LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to do state machine using events .

Solved!
Go to solution

Hi all.

 

i like to create a state machine using events methos .

 

 

i have 4 functions 1,2,3,4. (event based functios) (seperate sub vis)

 

1.i will trigger the 1 function.

 

then end of the first function should trigger the next function.

..

 

like state machine .

 

 

how to create this method in labview .. i tried value signaling its still not working . what i want.

 

 

 

 

0 Kudos
Message 1 of 16
(10,256 Views)

Wouldn't it make sense to have the entire state machine within one event case?  When you trigger the event case the state machine then executes like a normal state machine.  Something like this:

 

Event.png

0 Kudos
Message 2 of 16
(10,235 Views)

Hi JGar,

 

Wouldn't it make sense to have the entire state machine within one event case?

No, it doesn't make sense to put the statemachine into the event case!

- THINK DATAFLOW: your statemachine will block the event structure!

- Your UI becomes either unusable or you may click on buttons but those events will not get processed!

 

Use a queued state machine approach with two parallel running loops!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 16
(10,214 Views)

You can create one or more User Events that act like a "software interrupt".  If you open LabVIEW Help, go to Contents, Event-driven Programming, Concepts, How-To, look at Creating User Events.

 

What I've done is to make the State, which I configure as an Enum, a User Event.  When I want to signal a State Change, I wire the new State into Generate User Event, and the Event Structure "fires", returning the particular value that I wire to the usual Event Case Statement.

 

Bob Schor

0 Kudos
Message 4 of 16
(10,206 Views)

One caveat (occasioned by GerdW's reply) is that if you have a single Event loop handling both Front Panel Events and User Events (your State Machine), you need to recognize that while processing any single Event (Front Panel or User), the system is "blocked" and cannot respond to another.  If all of your States and Event processing is quick and nothing is time-critical, this single-loop architecture can be efficient (and is certainly "neat").  Otherwise, take advantage of LabVIEW's ability to handle parallel processing in parallel loops.

 

BS

0 Kudos
Message 5 of 16
(10,199 Views)

@JGar wrote:

Wouldn't it make sense to have the entire state machine within one event case?  When you trigger the event case the state machine then executes like a normal state machine.


DO NOT DO THAT!!!!!!  Long parts of code do NOT belong inside of an event case.

 

The Event Structure should be in its own state and the state machine should to to that state every once in awhile to check for user events.

 

Alternatively, you could put just the state case structure inside of the Timeout event case.  Something like this: http://www.notatamelion.com/2015/03/02/building-a-proper-labview-state-machine-design-pattern-pt-2/


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 6 of 16
(10,193 Views)

EVET.PNG

 

i am expectin like this 

0 Kudos
Message 7 of 16
(10,145 Views)

But here the event alwasy calling (I confirmed with other threads , value signaling behaives same )

0 Kudos
Message 8 of 16
(10,143 Views)

I'm not sure what you are trying to show with those images.

 

I don't see any state machine in your architecture.

 

Your combination of loops and event structures look like they would basically function just glancing at them.  But it all seems rather contrived, and there it isn't clear what problem you are trying to solve by creating a VI that looks like that.

0 Kudos
Message 9 of 16
(10,133 Views)
yes.. I am not expecting traditional state machine
..
I need a function which calls all the event function like sate machine
0 Kudos
Message 10 of 16
(10,122 Views)