Polling devices efficiently?
vegastech
Posts: 369
I didn't see this anywhere, so here's my question:
What is the best way to enable polling on serial/IP devices in order to track their status? Specifically, I really only care about Power Off/On, and Input Selection. I have created 2 variables, nTVPWR and nTVINPUT, which work fine when pressing buttons on a touchpanel, but I want the program to go out and check every 30 secs to determine if the TV is still on, and if so, what input it is using. I thought this programming should go in DEFINE_PROGRAM, but should I put it in DEFINE_START instead?
I was thinking of a simple if statement that would send a serial string to the TV and then parse it for my variable's number.
I can't seem to find a polling command in the Netlinx programming guide to start with.
What is the best way to enable polling on serial/IP devices in order to track their status? Specifically, I really only care about Power Off/On, and Input Selection. I have created 2 variables, nTVPWR and nTVINPUT, which work fine when pressing buttons on a touchpanel, but I want the program to go out and check every 30 secs to determine if the TV is still on, and if so, what input it is using. I thought this programming should go in DEFINE_PROGRAM, but should I put it in DEFINE_START instead?
I was thinking of a simple if statement that would send a serial string to the TV and then parse it for my variable's number.
I can't seem to find a polling command in the Netlinx programming guide to start with.
0
Comments
The issue with this is that do this no matter what the status of the port.
Another way is to use a WHILE loop. This can be tied to a variable that tracks the status of the port in case its down.
The way I do it is use a TIMELINE. a timeline gives you many levels of control over how things fire and allows you to modify stuff dynamically.
Now when some one is "on page" I'll start polling (if needed) and feedback. Even in these cases I tend to do feedback as event driven but in define_program (behind a wait) or timeline will work for either purpose.
Can you send a string to the TV to request the current input? If so then a timeline would be the best way to do this, and you can determine when the best time to do this is (it may not be necesary every 30 seconds in reality). This may negate the need for a power sensor anyway because the device might only respond if its on.
Bottom line is, I don't think there is one answer. The main guiding principle is, however, don't poll any more than you absolutely have to. It not only bogs your program down, but can often bog the device itself down to the point it's so busy answering your polls that it isn't doing it's job. I've had cases where I had to sacrifice having current data just to make sure I didn't lose control (most recently, with a Jandy pool controller ... anything quicker than a 3 second interval on polling, and the thing didn't have time to do it's job).
This is how I usually handle it. My queue's run in DEFINE_PROGRAM, here is an example:
For this particular device I do not need to poll because it has unsolicited feedback, but if I needed to poll I would do so by putting the polling command in the ELSE bracket. It will only poll when there is no communications happening.