12-17-2015 09:52 AM
Hello,
I am wirting a code for an experimental setup using the State Machine project template.
In the "idle" state, I would like to display a sort of device front-panel: I want to continously read data and update several indicators, as long as no button is pressed (triggering the event structure in the "idle" state).
However, as I want to set the buttons (boolean controls) to "Latch when pressed", I cannot get any values from them. I do not want to switch them to "switch when pressed, as this is both a bad UI (in my opinion) and caused some trouble (after returning to the idle state, can't press any other button).
I would greatly appreciate any guidance on how this can be done. Attached is an image of what I'd like to do, to further demonstate my intention.
Thanks!
Solved! Go to Solution.
12-17-2015 09:55 AM
You should NOT have a loop INSIDE of a state machine. Instead, use the timeout cabability of the Event Strucutre and have it say to go the the Idle state again if the timeout occurs. Though, I would probably put your update panel code inside of another state. Then you bounce between your Idle and Update Panel states.
12-17-2015 09:57 AM
Put the continuous updates in the timeout case of your event structure, wire a number (not -1) to the hourglass in the top-left of the event structure.
12-17-2015 05:06 PM
I would put your "Get Data" and "Update Panel" in its own parallel loop (outside of your main loop). That way your data always updates, no matter what your UI is doing. If you need to use the data for something (I'm sure you will), use a queue or user event to transfer the data over to your state machine loop.
12-18-2015 10:13 AM
Your code also lacks "Order of Operations." What I mean is, your Event Structure is capable of happening before your Case structure because there is no wire forcing order. Just because it is "furthest right" on your block diagram doesn't mean it'll happen second. This can lead to possible race conditions. Make sure you are aware of this when programming that your code doesn't know who happens first. Also, Different variations of State Machines exist. You can have a separate Case and Event Struct in the same loop and the Event structure just interrupts the state machine. Or, you can have your event structure within an "idle" case (many prefer this route). This helps in the Race Condition issue.
12-18-2015 08:02 PM
12-20-2015 10:25 AM
Thank you and everyone else for your assitance. I am very fond of this idea (having one loop continously reading and updating, and a second "state machine" loop that will handle the experiment, reading the data from the first loop as necessary).
However I am having difficulties implementing this.
What I need is for both loops to be able to send and receive data to each other (for example, start\stop continous acquisition, continous acqusition stopped, data acquired...).
I've tried implementing this using both User Events and Notifiers, but it seems like after a single state, the continous loop is holding.
Any help, including pointing me to some obvious example that I've missed, would be greatly appreciated!
12-21-2015 03:00 AM
Hi clOck,
I have seen your Code,Try to modify your code like this.In your event case try to figure out when to send start and Stop.You can also use another Queue fromUpper loop
to send data to the lower Loop.Hope this helps.
12-21-2015 07:21 AM
Thanks ohiofudu,
However as I am initializing in the first loop, I need to start with data acquisition off, and be able to turn it on\off (in the second loop) from the first.
I've tried wiring the "Wait on Notification" to a case structure, and putting the data acquisition in the "true" case, however for continous reading I must continously send notifications, which I cannot do in my actual program.
I believe an AE controlling the case structure in the "continously read and update" loop may be the best option. Will try and report!
12-21-2015 07:34 AM
cl0ck wrote:
However as I am initializing in the first loop, I need to start with data acquisition off, and be able to turn it on\off (in the second loop) from the first.
I've tried wiring the "Wait on Notification" to a case structure, and putting the data acquisition in the "true" case, however for continous reading I must continously send notifications, which I cannot do in my actual program.
Have your notification send a TRUE for start acquiring data and a FALSE for when to stop. When you get the TRUE, you can set the timeout of your Wait On Notification to whatever rate you want to do your acquisition and set it to -1 (wait forever) when you are commanded to stop. You can just store this timeout in a shift register. So you would then acquire data if you got a TRUE notification OR you have a timeout.