Logic not working.

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by bushy, May 22, 2008.

  1. bushy

    bushy

    Joined:
    May 17, 2008
    Messages:
    9
    Likes Received:
    0
    Can anybody tell me why the logic below wouldn't work.

    { This module controls the coach captain heat. Once the temp senor a set temp and winter start button or coach captains A/C on is activated then set high heat on }

    once (GetLightingState("Winter") = ON)or
    (GetLightingState("Coach captains A/C") = ON)and
    (GetUnitParameter("Local",36,ptTemperature)<16) then
    begin
    SetLightingState("Coach captain high heat", ON);
    SetLightingState("Coach captain low heat", ON);
    SetLightingState("Coach captain fan",ON);
    end;
    { This module controls the coach captain heat. Once the temp senor =
    set temp and winter start button and coach captains A/C on is activated then set low heat on }

    once (GetLightingState("Winter") = ON)or
    (GetLightingState("Coach captains A/C") = ON)and
    (GetUnitParameter("Local",36,ptTemperature)>=16) then
    begin
    SetLightingState("Coach captain high heat", OFF);
    SetLightingState("Coach captain low heat", ON);
    SetLightingState("Coach captain fan",ON);
    end;
    { This module controls the coach captain heat. Once the temp senor =
    set temp and winter start button and coach captains A/C on is activated then set all heat off }

    once (GetLightingState("Winter") = ON)or
    (GetLightingState("Coach captains A/C") = ON)and
    (GetUnitParameter("Local",36,ptTemperature)>22) then
    begin
    SetLightingState("Coach captain high heat", OFF);
    SetLightingState("Coach captain low heat", OFF);
    SetLightingState("Coach captain fan",OFF);
    end;
    { This module controls the coach captain heat. Once winter start button and coach captains A/C is off then set
    all heat off }


    once (GetLightingState("Winter") = OFF) and
    (GetLightingState("Coach captains A/C") = OFF) then
    begin
    SetLightingState("Coach captain high heat", OFF);
    SetLightingState("Coach captain low heat", OFF);
    SetLightingState("Coach captain fan", OFF);
    end;
     
    bushy, May 22, 2008
    #1
  2. bushy

    mattyb

    Joined:
    Jul 29, 2005
    Messages:
    78
    Likes Received:
    0
    Location:
    Sydney, Australia
    You could probably use some extra brackets in the AND/OR statements, as I'm not sure of the precedence the compiler uses. eg.

    Is it:
    Code:
    (A or B) and C
    or
    Code:
    A or (B and C)
    ...and that will at least make the intent of those logic statements a bit clearer.

    I guess it may also not work if the temp sensor is not working properly - you can use the GetUnitParamStatus(Network, UnitAddress, ParameterType) to make sure you're getting a valid reading back.

    OR its something more obvious that I can't see!

    Anyway, hope that's some help.

    Cheers

    Matt
     
    mattyb, May 23, 2008
    #2
  3. bushy

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,397
    Likes Received:
    26
    Location:
    Adelaide, South Australia
    ALWAYS ALWAYS ALWAYS use brackets around logical statements.

    life is sweeter and easier if you are in control (using brackets) instead of relying on the compiler interpreting things in the right way. You have to think less about whats going on !!
     
    ashleigh, May 23, 2008
    #3
  4. bushy

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    275
    Likes Received:
    98
    Location:
    Sydney, NSW, Australia
    code not working

    Would it be better to do it like this ?


    If (GetLightingState("Winter") = ON) or (GetLightingState("Coach captains A/C") = ON) Then
    begin

    Once (GetUnitParameter("Local",36,ptTemperature) < 16) then
    begin
    SetLightingState("Coach captain high heat", ON);
    SetLightingState("Coach captain low heat", ON);
    SetLightingState("Coach captain fan",ON);
    end;

    { This module controls the coach captain heat. Once the temp senor =
    set temp and winter start button and coach captains A/C on is activated then set low heat on }

    Once (GetUnitParameter("Local",36,ptTemperature) >= 16) And (GetUnitParameter("Local",36,ptTemperature) <= 22) then
    begin
    SetLightingState("Coach captain high heat", OFF);
    SetLightingState("Coach captain low heat", ON);
    SetLightingState("Coach captain fan",ON);
    end;

    { This module controls the coach captain heat. Once the temp senor =
    set temp and winter start button and coach captains A/C on is activated then set all heat off }

    once (GetUnitParameter("Local",36,ptTemperature) > 22) then
    begin
    SetLightingState("Coach captain high heat", OFF);
    SetLightingState("Coach captain low heat", OFF);
    SetLightingState("Coach captain fan",OFF);
    end;

    { This module controls the coach captain heat. Once winter start button and coach captains A/C is off then set
    all heat off }

    End;

    once (GetLightingState("Winter") = OFF) and (GetLightingState("Coach captains A/C") = OFF) then
    begin
    SetLightingState("Coach captain high heat", OFF);
    SetLightingState("Coach captain low heat", OFF);
    SetLightingState("Coach captain fan", OFF);
    end;
     
    lcrowhurst, May 23, 2008
    #4
  5. bushy

    bushy

    Joined:
    May 17, 2008
    Messages:
    9
    Likes Received:
    0
    Thanks.

    Thanks Matt,
    I have soughted the problem with your input. Still cant see why it didn't work with Get unit parameter. The brackets around the or statements I totally forgot about.
    Thanks again.
     
    bushy, May 23, 2008
    #5
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.