LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

producer/consumer state machine

Hello,

 

I have a State Machine with an Idle state that has an Event Structure to handle user events in it. I would like to include in that state, and in parallel with the Event Structure, a VI that polls for data every 10 seconds. Is there a way to have the Event Structure respond automatically to User events without having to wait 10 seconds before polling new data? Is the Producer/Consumer the way to go and how am I going to program this?

 

Thank you,

 

Richard

0 Kudos
Message 1 of 4
(1,306 Views)

If you are polling for data (in the same state) in parrell to the event case then surely the event structure would execute at the same time you poll.. it would just not be able to jump to the next state in your state machine until the polling had completed.

 

I had a quick look at your code, not to be mean but it's not the easiest thing to read. Try to keep the block diagram to a single screen so you don't have to scroll if possible. If that isn't possible, have it only scroll in one direction. You can achieve this with the use of Sub VIs.

Also, be careful with using local variables to read and write. They are terrible for introducing race conditions. Instead trying using an FGV/Action Engine.

 

Olly

**********************************************************************************************
The day is quickly coming when every knee will bow down to a silicon fist, and you will all beg your binary gods for mercy.
0 Kudos
Message 2 of 4
(1,299 Views)

You can have a timeout case on your event structure which will effectively cause it to poll.

 

If you have a separate while loop, you could have it use a Value(signalling) property node to fire an event within the event structure.  Or you could actually dynamically register for user events and fire on them.

0 Kudos
Message 3 of 4
(1,286 Views)

@RavensFan wrote:

You can have a timeout case on your event structure which will effectively cause it to poll.

 

If you have a separate while loop, you could have it use a Value(signalling) property node to fire an event within the event structure.  Or you could actually dynamically register for user events and fire on them.


My concern with that is it would only poll on timeout event. If the user is actively interacting with the program, I don't see a 10 second timeout occoring that frequently.

 

I personally would go with a second loop and a message handler of some sort to take care of the polling.  Just have a "wait until next ms multiple" in the second loop for 10 sec, and every iteration just poll the data and send a message back to the first loop. You could use a queue with a state, or with the data. You could also open a data value reference and send that type as the queue message, simply saying "new data in this memory location."

0 Kudos
Message 4 of 4
(1,272 Views)