06-25-2014 12:59 PM
Hi everyone. I have a question for all you LabVIEW gurus out there. I need to poll a device repeatedly and if I lose communication with it I need to shut things down. How do I poll this device constantly and run my other code at the same time?
Thanks!
06-25-2014 01:20 PM
Hi hobby1,
just with one while loop with the read function on the inside is going to be reading constantly every loop and if you wire the error to the conditional terminal of the while loop is going to stop the loop if there is any error. Click here to obtain a little more information about while loops.
Hope this can help you.
06-25-2014 01:23 PM
You just need to put it in another loop. You also need to setup some communications between the loops. User Events, Queues, Notifiers...these are really good for sending commands and status to different loops.
06-25-2014 01:25 PM
@Luis32 wrote:
Hi @hobby1,
just with one while loop with the read function on the inside is going to be reading constantly every loop and if you wire the error to the conditional terminal of the while loop is going to stop the loop if there is any error. Click here to obtain a little more information about while loops.
Hope this can help you.
The problem with using a single loop is you are limited to your loop rate. If I just put in an Event Structure, you are not polling anymore because the event structure is sitting there holding up your loop waiting for the user to hit a button. If you need to poll at a consitant rate, it has to be in its own loop.
06-25-2014 01:33 PM
Hi crossrulz,
yes, you are right but for what I saw, he asked for a continuos polling, never mentioning any event or something. You are correct on your answer and trying to be a little more helpfull I think that he can use a producer-consumer design, that is something that I think can apply for what he needs. On this link he can find a little more information about this design pattern.
I'm sorry if I misunderstood the question and I hope that this can clear some things.
Regards
06-25-2014 01:51 PM
And if he may need some events maybe the state machine structure is the best choice, but obviously having the reading loop running parallel. As you know, this design patterns are intended to run simultaneously with the polling loop for his case. There are many choices to create, but for a description like the one he gave, I tried to keep the answer simple.
I wish my answers don't complicate things more
06-25-2014 07:58 PM
Crossrulz, can you provide example code in where two processes are running in parallel? Thanks so much for everyone's help.
06-25-2014 08:43 PM
06-25-2014 08:59 PM
06-26-2014 08:24 AM
@hobby1 wrote:
Crossrulz, can you provide example code in where two processes are running in parallel? Thanks so much for everyone's help.
Almost all of my applications have multiple loops. But for the sake of examples, follow the link already given for the Producer/Consumer. You might also want to do a search for Queued Message Handler (QMH).