Logic work's in fine PICED but not in PAC little advice if possible

Discussion in 'General Discussion' started by mark_curd, Sep 25, 2009.

  1. mark_curd

    mark_curd

    Joined:
    Mar 28, 2009
    Messages:
    20
    Likes Received:
    0
    Location:
    Maidstone, UK
    Hey Guy's

    Hoping that someone might be able to point me in the right direction as to why I can't get my logic to work once it's transferred to my PAC unit but it works fine in PICED.

    I am wanting to setup a boolean identifier called "WorkingDays" to keep things more simply when writing a long bit of code.

    At the moment I am keeping the code to a minimum just for test purpose as this is my first approach at using an identifier.

    So in the logic menu I am setting up a Global Variable as follows:

    WorkingDays : boolean; { boolean variable is either "True" or "False" only }

    My Logic Module is as follows:

    { Test WorkingDay boolean variable. This Logic code will set the "Main Light" to 25% in the master bedroom for 15min at 6:00am on work days only }

    WorkingDays := ((DayOfWeek >= "Monday") and (DayOfWeek <= "Friday"))

    once ((time = "06:00:00") and
    (WorkingDays = True )) then

    begin
    SetLightingLevel ("Main Light", 20%, "8s");
    Delay ("00:15:00")
    SetLightingLevel ("Main Light", 0%, "8s");
    end;

    Any pointers would be much appreciated

    Thanks
     
    mark_curd, Sep 25, 2009
    #1
  2. mark_curd

    mark_curd

    Joined:
    Mar 28, 2009
    Messages:
    20
    Likes Received:
    0
    Location:
    Maidstone, UK
    Ok now I feel a right numpty :eek:

    Turns out when I was transferring the project to my PAC unit it was not syncing the date and the pac unit thought it was Sunday hence the "WorkingDays" was never "True"

    My fault as I was recently testing another code and changed the date. Think I will offset the code to test them from now on. :rolleyes:

    Anyway here is my final code clean up. Thanks to tho's that viewed, maybe this will help someone out at somepoint.



    So in the logic menu I am setting up a Global Variable as follows:

    WorkingDays : boolean; { boolean variable is either "True" or "False" ("On" or "Off") Only }

    My Logic Module is as follows:

    { Test WorkingDay boolean variable. This Logic code will set the "Main Light" to 25% in the master bedroom for 15min at 6:00am on work days only }

    WorkingDays := (DayOfWeek >= "Monday") and (DayOfWeek <= "Friday")

    once ((time = "06:00:00") and (WorkingDays = True )) then

    begin
    SetLightingLevel ("Main Light", 20%, "8s");
    Delay ("00:15:00")
    SetLightingLevel ("Main Light", 0%, "8s");​
    end;
     
    mark_curd, Sep 25, 2009
    #2
  3. mark_curd

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    Logic Expressions can be Simplified to make them evaluate more quickly. This can make the code easier to read too.
    Your condition with the "and' means time and bool WorkingDays needs to be evaluated each loop. You are being kinder to the processor with a nested condition like
    once (time = "06:00:00") then
    if (WorkingDays = true) then
    begin

    The other thing that is often misunderstood is the "delay" in code - especially ones for several minutes.
    For your code above once it gets to -Delay ("00:15:00") everything in this module will stop being processed for 15 minutes most of the time you don't want this. Instead use the Pulse C-Bus Level to pulse the light on for 15 minutes - (right mouse click is your friend here - how clever must the chap be who designed this logic engine :) ). Be aware that turning on/off the same GA from elsewhere in the network during this pulse period will stop the pulse timer running in the logic. If this is undesirable then start an internal timer in your logic then turn the light off when the timer gets to 15 minutes - don't forget to also reset your timer when you are finished with it.
     
    Last edited by a moderator: Sep 26, 2009
    Lucky555, Sep 26, 2009
    #3
  4. mark_curd

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    You were obviously paying attention during logic training ;)

    I always feel compassion for the processor and try to write code to make things efficient. It comes from years of work on very low end microcontrollers. I am still in the habit of trying to save a loop here or there for my quad core desktop computer, although I suspect that it doesn't appreciate my effort...
     
    Darren, Sep 26, 2009
    #4
  5. mark_curd

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    Of course most compilers these days wouldn't bother evaluating the second part of an 'and' if the first was false. Perhaps a future enhancement to the logic engine :)
     
    Ashley, Sep 26, 2009
    #5
  6. mark_curd

    mark_curd

    Joined:
    Mar 28, 2009
    Messages:
    20
    Likes Received:
    0
    Location:
    Maidstone, UK
    Thanks for that, always looking for pointers and better ways to approach these things. I will be changing the way I have written it as I can see how you mean about using "then" "if" as the processor will only be checking the first statement (time = "06:00:00") and not both.

    I have not done any in-house C-bus training at present as at the moment this is only a small setup in my own home. But am working my way through the training manuals etc.

    Thanks
     
    mark_curd, Sep 26, 2009
    #6
  7. mark_curd

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,391
    Likes Received:
    24
    Location:
    Adelaide, South Australia
    Depends.

    In "C", short-circuit evaluation is defined as part of how the language operates and thus what you say is correct.

    Conversely, in pascal, short-circuit evaluation is explicitly not performed (if you want it, use cascaded IF statements), and so won't and should not be performed.
     
    ashleigh, Sep 26, 2009
    #7
  8. mark_curd

    Lucky555

    Joined:
    Aug 13, 2007
    Messages:
    229
    Likes Received:
    0
    Yeh... What he said :p
     
    Lucky555, Sep 27, 2009
    #8
  9. mark_curd

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    I guess it depends of what version of Pascal you are talking about. Delphi will certainly only evaluate as much of the expression as required.
     
    Ashley, Sep 27, 2009
    #9
  10. mark_curd

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    This has been in our system (#7050) for years. One day we will get to it...
     
    Darren, Sep 28, 2009
    #10
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.