09-18-2016 05:34 PM
Hi,
I am using the Évent based Producer consumer Architecture to read data from a UWB module serially with VISA functions.The device is configured in Initial state and goes to a Wait state awaiting User action. I am able to acquire the data in the Acquire state of the state machine but if I press other buttons like Pause, which should go to wait state again, or save or stop, the control goes momentarily to those states and returns to Acquire state. I dont understand how this is happening. I am attaching the VI. Hekp me out here
Thanks
Goku
09-18-2016 07:07 PM
It is because the Acquire state is enqueueing an Acquire state. So even if you throw in the Pause, there is an Acquire waiting in the queue.
What I like to do in these situations is to use the timeout of the queue. You can store the timeout rate in a shift register, initialized to -1. So when the timeout is set to -1, the Dequeue will wait forever for a message to come in. Then you get an Acquire message. So set the timeout to be something like 25ms (your current loop rate). Then when you have a timeout, you read your data. When you get the Pause message, set the timeout back to -1. You will no longer be getting the data and will wait for a message to come in.
Another note: I HATE HATE HATE (could probably use a few more there) the idea of destroying the consumer's queue to make it stop. You send a message to tell it to stop. In that Stop case, you can destroy the queue and actually just stop the loop. The reason I despise the "cause a queue error" is because sometimes that is more that needs done (data to be processed, shutdown states need ran, etc). But when you destroy the queue, you have destroyed any messages and data that were on the queue and your consumer cannot do a proper shutdown.