For with Wait problem!
Hello,
I'm trying to send 163 send_string with a interval time of 0.3 to 0.5 seconds but I'm having problems with the WAIT statement.
As NetLinx Help says:
"(...)When a wait statement is executed, it is added to a list of currently active wait requests and the program continues running.(...)"
Here is my Code:
TIMELINE_EVENT[BIAMP_TL_POLL_TIME_ID]
{
SWITCH(TIMELINE.SEQUENCE)
{
CASE 1:
{
LOCAL_VAR INTEGER nCount
FOR(nCount = 101; nCount <= 163 ; nCount++)
{
WAIT 3
{
GetVolBiamp(ITOA(nCount),1,1)
}
}
}
}
}
So my problem is that when the FOR statement start it get right trough the WAIT statement because it takes less than 0.3 seconds to be executed and the only send_string it sends is the last one, the 164 one.
Is there anyway possible to do that without having to type the WAIT statement between a send_strings?
Example.:
TIMELINE_EVENT[BIAMP_TL_POLL_TIME_ID]
{
SWITCH(TIMELINE.SEQUENCE)
{
CASE 1:
{
WAIT 3
{
GetVolBiamp('101',1,1)
WAIT 3
{
GetVolBiamp('102',1,1)
//and repeating this structure until 163...
}
}
}
}
}
}
Thank you.
I'm trying to send 163 send_string with a interval time of 0.3 to 0.5 seconds but I'm having problems with the WAIT statement.
As NetLinx Help says:
"(...)When a wait statement is executed, it is added to a list of currently active wait requests and the program continues running.(...)"
Here is my Code:
TIMELINE_EVENT[BIAMP_TL_POLL_TIME_ID]
{
SWITCH(TIMELINE.SEQUENCE)
{
CASE 1:
{
LOCAL_VAR INTEGER nCount
FOR(nCount = 101; nCount <= 163 ; nCount++)
{
WAIT 3
{
GetVolBiamp(ITOA(nCount),1,1)
}
}
}
}
}
So my problem is that when the FOR statement start it get right trough the WAIT statement because it takes less than 0.3 seconds to be executed and the only send_string it sends is the last one, the 164 one.
Is there anyway possible to do that without having to type the WAIT statement between a send_strings?
Example.:
TIMELINE_EVENT[BIAMP_TL_POLL_TIME_ID]
{
SWITCH(TIMELINE.SEQUENCE)
{
CASE 1:
{
WAIT 3
{
GetVolBiamp('101',1,1)
WAIT 3
{
GetVolBiamp('102',1,1)
//and repeating this structure until 163...
}
}
}
}
}
}
Thank you.
0
Comments
You could also create a recursive function, a function that calls itself, after the wait expires to call your GetVolBiamp function, increment by 1 then call this recursvice functioin to run again if the end hasn't been reached. Be carefull though and make sure there's a definite way out of the loop!
Here's 2 TL examples that I would possibly do that may work for you. I would likely do the 2nd since that sets a busy flag when a string is sent so subsequent strings won't fall on deaf ears (a device not ready).
DEFINE_CONSTANT BIAMP_ZONES = 63 ; TIMELINE_EVENT[BIAMP_TL_POLL_TIME_ID]// if repeats at 300 - 500 milliseconds { SELECT { ACTIVE(TIMELINE.SEQUENCE <= BIAMP_ZONES): { GetVolBiamp(ITOA(TIMELINE.SEQUENCE + 100)),1,1) } ACTIVE(1): {//I think this will reset the sequence count, otherwise use a local var counter and reset. //TIMELINE_RESTART(BIAMP_TL_POLL_TIME_ID) ;// if polling is continous. alot of traffic! //or TIMELINE_KILL(BIAMP_TL_POLL_TIME_ID) ;//if called periodically or just at start up. } } } //or DEFINE_CONSTANT BIAMP_ZONES = 63 ; DEFINE_VARIABLE VOLATILE INTEGER nBIAMP_Busy ; //Set to 1 when string sent, to 0 when acknowledged or time out. TIMELINE_EVENT[BIAMP_TL_POLL_TIME_ID]// if repeats at 300 - 500 milliseconds { LOCAL_VAR INTEGER nCnt ; if(!nBIAMP_Busy) { nCnt++ ; SELECT { ACTIVE(nCnt <= BIAMP_ZONES): { GetVolBiamp(ITOA(nCnt + 100)),1,1) } ACTIVE(1): { nCnt = 0 ; //if polling is continous (alot of traffic!) comment out TL kill below //or TIMELINE_KILL(BIAMP_TL_POLL_TIME_ID) ;//if TL created periodically or just at start up. } } } }