Home AMX User Forum NetLinx Studio

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.

Comments

  • viningvining Posts: 4,368
    Why not just queue all your cmds and use a timeline to pace the time between send_strings. If you don't want to create a queue that big you could create a timeline that adds the commands to a small queue or just sends the string directly at your desired delay.

    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!
  • viningvining Posts: 4,368
    I should really read before posting! I didn't even notice you were already using a TL since I saw the FOR loop and now that I see it the combination sort of confuses me a little.

    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.
    		    }
    	       }
    	  }
         }
    
Sign In or Register to comment.