Home AMX User Forum NetLinx Studio

How to execute / trigger commands in some interval.

Hi Guys,

Can you please suggest a way to execute / trigger commands in some interval, namely when a specified amount of time has elapsed?

I have tried below code, but it didn't work:

WHILE (TRUE)
{
SEND_STRING 0,"'Inside the while loop ...'"

WAIT 10 'FIRST WAIT'
{
SEND_STRING 0,"'After the first wait ...'"
}
}

The thing is that execution of the SEND_STRING 0,"'After the first wait ...'" isn't performed, and the only thing I get is a bunch of "Inside the while loop ..." string, when debugging.

I just want to repeatedly execute code enclosed in the outer WAIT scope. Can anyone please explain why this doesn't work and how else can I do that?

Thanks in advance,

David Gevorkyan

Comments

  • HedbergHedberg Posts: 671
    try:
    define_program
    
    wait 10
    {
      send_string 0,'Wait has expired'
    }
    

    and see what happens.

    My guess about the code that you wrote is that the first send_string occurs about 1000 times per second and you just don't notice the other string that pops up every second, but that's just my guess.

    I don't think that there's anything wrong with doing this sort of thing in define_program, but in general, it's probably better to use a time line -- particularly if you're trying to code that !#(%#%& test program. Of course, if you're trying to program an Axcent 2 that you bought off Ebay for $1.75, time lines are not your solution.
  • Actually the inner WAIT works correctly, the issue is to make it work repeatedly.

    Your guess isn't correct, since I have commented out the:
    SEND_STRING 0,"'Inside the while loop ...'"
    

    but still there is no sign of entering and executing code inside the WAIT.

    Can you please send me an example of time line? Can I specify an [highlight]Interval[/highlight] there and a [highlight]Function[/highlight] that should be executed as the specified amount of time elapses?
  • Spire_JeffSpire_Jeff Posts: 1,917
    In the keywords help section, look at TIMELINE. There are examples on how to implement it. Yes, you can specify intervals and use them to execute functions.

    Jeff
  • There are good descriptions of timelines in the Netlinx help file.

    They are very flexible and can easily be manipulated.
  • dchristodchristo Posts: 177
    davidgev wrote: »
    Hi Guys,

    WHILE (TRUE)
    {
    SEND_STRING 0,"'Inside the while loop ...'"

    WAIT 10 'FIRST WAIT'
    {
    SEND_STRING 0,"'After the first wait ...'"
    }
    }

    This code doesn't work because you created an endless loop with the while statement, so the processor never is able to check for expired waits. If you change your WHILE statement to an IF statement it should work as you intended, however, in this case a Timeline might be a better choice.

    --D
  • Guys, thanks a lot!

    I have used TIMELINE and it worked perfectly.
    Here is some code snippet:
        TimeArray[1] = 1000
        TimeArray[2] = 2000
        TimeArray[3] = 3000
        TimeArray[4] = 4000
        TimeArray[5] = 5000
        TIMELINE_CREATE(TL1, TimeArray, 5, TIMELINE_ABSOLUTE, TIMELINE_REPEAT)
    

    Sincerely,

    David Gevorkyan
  • AMXJeffAMXJeff Posts: 450
    davidgev wrote: »
    Hi Guys,

    Can you please suggest a way to execute / trigger commands in some interval, namely when a specified amount of time has elapsed?

    I have tried below code, but it didn't work:

    WHILE (TRUE)
    {
    SEND_STRING 0,"'Inside the while loop ...'"

    WAIT 10 'FIRST WAIT'
    {
    SEND_STRING 0,"'After the first wait ...'"
    }
    }

    The thing is that execution of the SEND_STRING 0,"'After the first wait ...'" isn't performed, and the only thing I get is a bunch of "Inside the while loop ..." string, when debugging.

    I just want to repeatedly execute code enclosed in the outer WAIT scope. Can anyone please explain why this doesn't work and how else can I do that?

    Thanks in advance,

    David Gevorkyan

    What your trying to do is best handled by creating a QUEUE. Search through the forum looking for the term "QUEUE". You will find a bunch of ideas how to do this correctly.

    // Here is a nice conversation on queueing...

    http://www.amxforums.com/showthread.php?t=5372&highlight=Queue
Sign In or Register to comment.