Jump to content

Running Program Terminates if Condition State Changes?


cpoore

Recommended Posts

Posted

Hi,

 

I have an IOLinc tied to my garage door and have written a program to trigger the garage fluorescents on, wait a predefined time, then turn the fluorescents off - this occurs any time the IOLinc sensor is switched off (i.e. the garage door is opened).

 

If I combine all of this within a single program (detection, on, wait, off) and the garage door is opened and closed before the wait period ends, the garage fluroescents stay on indefinitely (i.e. the program never reaches the turn off line after the wait). However, if I break this apart into (2) separate programs and do the garage door sensor detection in one program and the timer (fluorescents on, wait, fluorescents off) in a separate program - then trigger the on/wait/off timer from the 1st detection program, things appear to operate correctly. The lights turn on and turn off even if the garage door is open and closed before the "wait" time frame.

 

So my question...if the condition of a program evaluates as true and the condition then evaluates as false while the "then" statement is still running (i.e. during a "wait" statement), is the program terminated before completion?

 

Any assistance in understanding this would be greatly appreciated!

Posted

Yes, the If statement is continuously analyzed. If the program changes the state of the device, then the If part is re-evaluated at that time.

Posted (edited)

Got it. Thanks for the quick reply!

 

I also found related info buried in the wiki pertaining to Statement Execution Order...

 

http://wiki.universal-devices.com/index.php?title=ISY-99i/ISY-26_INSTEON:Scope,_Precedence_and_Execution_Order#Statement_Execution_Order

 

"Statement Execution Order

Within the Then or Else clause of a program, statements are executed from top to bottom in the order in which they occur. When a statement calls another program, the called program begins executing, and the calling program immediately continues execution with the next statement in sequence--it does not wait for the called program to complete before continuing.

A series of statements within a Then clause (or within an Else clause), up to the next Wait or Repeat statement, are atomic. In other words, all such statements are executed before the conditions of the program are retested. The program's conditions are reevaluated each time a Wait or Repeat statement is encountered, and at the end of each iteration of a Repeat loop.

What this means is that if a program's Then clause changes a condition which causes the program's overall condition to become false (or if the program's Else clause changes a condition which causes the program's overall condition to become true), the current atomic statement group will complete, and at that point execution will transfer from the Then clause (or the Else clause) to the Else clause (or theThen clause).

Therefore, if a Then clause (or an Else clause) contains no Wait or Repeat statements, the entire clause is atomic, and will complete before the program's conditions are reevaluated."

Edited by cpoore
Posted

Therefore, if a Then clause (or an Else clause) contains no Wait or Repeat statements, the entire clause is atomic, and will complete before the program's conditions are reevaluated."[/size][/font][/color]

I've long suspected this, and make use of it in many places. Good to see its supposed to work this way!

Guest
This topic is now closed to further replies.

  • Recently Browsing

    • No registered users viewing this page.
  • Who's Online (See full list)

  • Forum Statistics

    • Total Topics
      37k
    • Total Posts
      371.5k
×
×
  • Create New...