cancel
Showing results for 
Search instead for 
Did you mean: 

How to do state machine using events .

SOLVED
Highlighted
SaranVenkateshS
Active Participant
Solved!

How to do state machine using events .

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.

 

 

 

 

22 REPLIES 22
JGar
Member

Re: How to do state machine using events .

Message contains an image

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

GerdW
Knight of NI

Re: How to do state machine using events .

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
Bob_Schor
Knight of NI

Re: How to do state machine using events .

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

Bob_Schor
Knight of NI

Re: How to do state machine using events .

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

crossrulz
Knight of NI

Re: How to do state machine using events .

Message contains a hyperlink

@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/



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
SaranVenkateshS
Active Participant

Re: How to do state machine using events .

Message contains an image

EVET.PNG

 

i am expectin like this 

SaranVenkateshS
Active Participant

Re: How to do state machine using events .

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

RavensFan
Knight of NI

Re: How to do state machine using events .

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.

SaranVenkateshS
Active Participant

Re: How to do state machine using events .

yes.. I am not expecting traditional state machine
..
I need a function which calls all the event function like sate machine