Home AMX User Forum NetLinx Studio

A few questions...

Hey,

So I would like to be able to check if a timeline has been paused or not. Timeline_active only tells me if it's been created or not right? Everytime I pause it, do I need to track that with a variable and check the variable or can I go something like "IF (TIMELINE_PAUSE(TL_QUEUE))".

Also can I get the time a timeline has been running from outside a timeline event? I have a timeline that just runs for 10 minutes and has only the one event, but before it's reached that event, can I find out how long it's been running for?

And the same with IP_CLIENT_OPEN, how do I check if it's open or closed? Again do I need to track it with variables on the online/offline events, and if so I have another question: If it is online, and then I pull the network plug I assume it triggers an ONERROR event, but will it also trigger an offline event aswell?

And is there any opensource piece of code around that is just opening and closing IP comms and trying to keep them open? I've built IP into a module based off a technote I read and downloaded, but it didn't have much in the way of reopening the connection on error, or stop trying to connect if it fails x number or times etc.

Cheers
Joshua

Comments

  • The IP part

    I don´t know much about timelines but here is a code I generally use for IP devices
    DATA_EVENT[0:dvDEVICE.PORT:0]
    {
       ONLINE:
       {
    	SEND_STRING 0,"'DEVICE ONLINE'"
    	bDEVICEONLINE = TRUE
       }
       OFFLINE:
       {
    	SEND_STRING 0,"'DEVICE NOT ONLINE'"
    	bDEVICEONLINE = FALSE
    	WAIT 100
    	IP_CLIENT_OPEN(dvDEVICE.PORT,cDEVICEADDRESS,lIPPORT,IP_TCP)
       }
       STRING:
       {
    
       }
       ONERROR: // IF ERROR THEN RECONNECT IF POSSIBLE
       {
    	SWITCH (DATA.NUMBER)
    	{
    	   CASE 9:
    	   CASE 17:
    	   {}
    	   DEFAULT:
    	   {
    		WAIT 100
    		IP_CLIENT_OPEN(dvDEVICE.PORT,cDEVICEADDRESS,lIPPORT,IP_TCP)
    	   }
    	}
       }
    }
    
    I suppose you could make a counter for the number of "trying to connect". I don´t see the point honestly. But then again I don´t turn IP connections on an off when sending commands. If the device is there, it should be connected and if it is offline, the Master should be trying to connect to it and if he can´t, then let someone know so it can be fixed. Thats how I do it.
    When you pull the cable, the online variable will equal false. It may take a few moments though.
  • Joe HebertJoe Hebert Posts: 2,159
    jcerecke wrote:
    can I get the time a timeline has been running from outside a timeline event?

    Yes you can with TIMELINE_GET()
    TIMELINE_GET
    This function returns the value of the specified timeline’s timer. The timer indicates the number of milliseconds that have passed since the timeline started. If the timeline is paused the timer is also paused and subsequent calls to TIMELINE_GET will return the same value.
  • It's not possible to find out directly if a timeline is paused or not. The TIMELINE_ACTIVE() just replies if the timeline exists or not. You may have to track the pause manually, e.g. by a variable.

    Regarding the IP_CLIENT_OPEN(), Thorleifur's code is pretty good, a little improvement may be to track also a third state "Trying to connect", so you can find out if there's a IP_CLIENT_OPEN() in progress or not, like
    ...
    IF(bDEVICEONLINE = FALSE) // no OPEN in progress
    {
    IP_CLIENT_OPEN(<all the required parameters>)
    bDEVICEONLINE = 2 // IP_CLIENT_OPEN in progress
    }
    ...
    DATA_EVENT[0:dvDEVICE.PORT:0]
    {
    ONLINE: 
    {
    bDEVICEONLINE = TRUE
    }
    OFFLINE: 
    {
    bDEVICEONLINE = FALSE
    }
    }
    
  • mushmush Posts: 287
    jcerecke wrote: »
    So I would like to be able to check if a timeline has been paused or not.

    Try this..
    DEFINE_VARIABLE
    volatile    long    lRunTime
    
    if(TIMELINE_ACTIVE(TL_QUEUE))                 // If the timeline is running
    {
     lRunTime = TIMELINE_GET(TL_QUEUE)             // Get the value of the timeline in milliseconds
     wait 1                                           // Wait for a bit
     {
      if(lRunTime = TIMELINE_GET(TL_QUEUE))        // compare times
      {
       send_string 0,'Timeline TL_QUEUE is paused'   // We are paused as both times are equal
      }
      else
      {
       send_string 0,'Timeline TL_QUEUE is !paused'  // We are not paused as times are different
      }
     }
    }
    

    Cheers
Sign In or Register to comment.