LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

UI control of State Machine

I'm working with a traditional state machine that stores the current state in an OO cluster and reads it in the next iteration (no shift registers). 
 
I have another VI that handles the User Interface, it's a loop with an event structure. 

I need to transition the state machine according to the events of the UI.

In the past, I have simply wrote a new state to class variable when the desired event occurs.  This "works", but has proven unreliable because at times I find that the state machine will rewrite the variable after the User Interface VI tries to change it.
 
I've tried boolean flags indicating certain UI events, but it seems to be slower.  I've also tried writing event refnums to variables, this is about the same speed and probably a gratuitous waste of memory.

How do you do it?

0 Kudos
Message 1 of 5
(3,113 Views)

I am not sure of the relationship between your class and your state machine, but have you considered a queue driven state machine? This is very versatile because can feed the queue based on user events or programmatic actions.

Allen

0 Kudos
Message 2 of 5
(3,086 Views)
A good solution is to make the whole thing event driven. Put your state machine in the Timeout event and have the usual events for managing the rest of the interface. As long as nobody pushes a button, the state machine merrily chugs along, doing its thing; but is a GUI event occurs, the event is handled and then state machine continues - or not depending on what the action was that the operator took.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 3 of 5
(3,077 Views)
Or the other way aroundSmiley Very Happy, put the event structure inside one state 'idle' or something. In that way you can control your State Machine from the Events that happened in the Event Structure.

Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 4 of 5
(3,052 Views)

Mike wrote;
 
A good solution is to make the whole thing event driven. Put your state machine in the Timeout event and have the usual events for managing the rest of the interface. As long as nobody pushes a button, the state machine merrily chugs along, doing its thing; but is a GUI event occurs, the event is handled and then state machine continues - or not depending on what the action was that the operator took.

 
The State Diagram Editors "use as sub-VI" mode is included to fill this use case nicely unless the UI actions must "lock" the UI until it the events execute and the state machine can not tolerate this.
 
In that case I tend to put all of the UI stuff in the event structure and run the state machine in parallel interconnected via command a response queues.
 
Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 5 of 5
(3,032 Views)