ModuleEnabled Function

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by Josh, Mar 6, 2006.

  1. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    Description

    This returns a boolean value with the enable state (true/false) of the selected Module.

    Question

    I have noticed that if the "ModuleEnabled" function is called while the module in question is busy with a Delay function, false is returned. Is this a bug?:confused:
     
    Josh, Mar 6, 2006
    #1
  2. Josh

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    As we know the delay function places the module it is written in on hold, halting processing of operations within that module for the duration of the delay - then it sort of makes sense that ModuleEnabled should be false during this time ??

    Does the state change when delay period ends ?
     
    Last edited by a moderator: Mar 6, 2006
    Phil.H, Mar 6, 2006
    #2
  3. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    Yes it does.

    It would be nice if the function return true on all conditions when enabled.
     
    Josh, Mar 6, 2006
    #3
  4. Josh

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    This can be changed if it is deemed worthwhile. Does anyone else think this is worth changing ?

    The PAC firmware will need to change too.
     
    Darren, Mar 6, 2006
    #4
  5. Josh

    ashleigh Moderator

    Joined:
    Aug 4, 2004
    Messages:
    2,397
    Likes Received:
    26
    Location:
    Adelaide, South Australia
    A personal view is that it should be left alone.

    If you change it, any code that relies on the current behaviour would break, which is known in the trade as "a bad thing".
     
    ashleigh, Mar 7, 2006
    #5
  6. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    How would you check if a module is enabled or disabled?

    There might be no harm in disabling a disabled module, but I would prefare to test the condition before hand and not waste resources and processing power.

    In that case, I think the function name should be changed to something like ModuleRunning and not ModuleEnabled.

    That is just my view.
     
    Josh, Mar 7, 2006
    #6
  7. Josh

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    What about for a module that you want to check status on, have all code that enables the module also set a flag (Global Variable - Boolean). Have all code that can disable the module also reset the flag. ?

    2. Can you restrict using delay in modules you wish to test the state of and use other timing functions.

    "ModuleRunning" ?? even if this chage included modules that were enabled and timing out a delay period still would not help you determine what code was being processed at any one time.

    Seeing as we have been given IfConditionStaysTrue / StayTrueTimer (well almost) I tend to use this and steer clear of delay 99.9% of the time. For automation purposes delay can cause problems just like "if" and C-Bus actions often don't mix real well.

    The chap who wrote the logic engine got some real good tips regarding everyday use, as a result he included some real handy "non standard" programming options.

    Use a flag or StayTrueTimer, drop a line if you would like further info :)
     
    Last edited by a moderator: Mar 7, 2006
    Phil.H, Mar 7, 2006
    #7
  8. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    I am currently using flags, but while I was going through the documentation and saw ModuleEnabled, I thought this would be a better way of checking and it would reduce my code.

    This particular module does my "Someone is at home" simulation, which starts after sunset and when the alarm is ON. I am using muliple Randoms and delays (which might not be the best way of doing this).

    I am not after what code is processed, but checking if the module is enabled.
     
    Last edited by a moderator: Mar 7, 2006
    Josh, Mar 7, 2006
    #8
  9. Josh

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Wow! I can't imagine why you would want to use delay for this type of 'typical function'... {"Someone is at home" simulation}

    Have a look at the example code in the zip in this thread. (Think it is the 5.1 file) have the file on my work PC.
    http://www.cbusforums.com/forums/showthread.php?t=1845

    Hope this helps :)
     
    Phil.H, Mar 7, 2006
    #9
  10. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
     
    Last edited by a moderator: Mar 7, 2006
    Josh, Mar 7, 2006
    #10
  11. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    Maybe not, I think I might getaway with just a few...:rolleyes:
     
    Josh, Mar 7, 2006
    #11
  12. Josh

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Not sure why you need to declare variables to simulate GA's at all ????

    Sometimes constants are used to make GA values constant for example code where you don't want to worry about a specific C-Bus data base (tag file).

    I only use delay when I want to stop a module processing code for a second or so, other than that trust me - "delay gets in the way" If someone comes back into the house in the middle of a delayed process next thing you have to start disabling modules then enable later then probably need to check the state of modules, isn't that were we started ? Enabling and disabling modules all over the place can get difficult to manage and always had that spaghetti (goto) feel to me...
     
    Last edited by a moderator: Mar 7, 2006
    Phil.H, Mar 7, 2006
    #12
  13. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    Looking at the sample code you had variables RandomTime1, RandomTime1a and so on. That is what I was referring to....
     
    Josh, Mar 8, 2006
    #13
  14. Josh

    Phil.H

    Joined:
    Jul 29, 2004
    Messages:
    466
    Likes Received:
    0
    Location:
    Sydney
    Did the sample code help ???
     
    Phil.H, Mar 8, 2006
    #14
  15. Josh

    Josh

    Joined:
    Aug 25, 2004
    Messages:
    241
    Likes Received:
    0
    Location:
    Pretoria, South Africa
    It did , thanks.
     
    Josh, Mar 9, 2006
    #15
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.