LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State machine

Solved!
Go to solution

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!

0 Kudos
Message 1 of 20
(4,787 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 2 of 20
(4,780 Views)

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.

0 Kudos
Message 3 of 20
(4,770 Views)

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. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 4 of 20
(4,707 Views)

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.

0 Kudos
Message 5 of 20
(4,646 Views)
You will find some good info on state machines here:

http://www.notatamelion.com/2015/02/23/building-a-proper-labview-state-machine-design-pattern-pt-1/

And the post following.

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 6 of 20
(4,603 Views)

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!

0 Kudos
Message 7 of 20
(4,555 Views)

ProducerConsumer_Modify.jpg

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.

Certified LabVIEW Architect
Certified TestStand Architect
0 Kudos
Message 8 of 20
(4,517 Views)

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!

 

0 Kudos
Message 9 of 20
(4,486 Views)
Solution
Accepted by cl0ck

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 10 of 20
(4,477 Views)