LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Queued State Machine

Solved!
Go to solution

Hello

 

I am using a Queued State Machine that is controlled by an Event Structure. In this example, the State Machine has 3 cases: Idle, State 1 and State 2.

 

I need to trigger State 2 execution, from inside State 1.

 

Queued State Machine.jpg

 

Thanks

 

Dan07

 

 

Message 1 of 24
(7,660 Views)

Define State 2 as a User Event.  Use the Generate User Event VI to trigger the event from within State 1.

 

user events.png

0 Kudos
Message 2 of 24
(7,648 Views)

But in my real VI this will happen several times because my State Machine has a lot of cases (not only 3, as the example) and I would have to define almost all the States as User Events. I would like to keep using the Queue function that I used within the Event Structure, but within the State 1 to trigger State 2.

 

Thanks

0 Kudos
Message 3 of 24
(7,644 Views)

maybe you can use a property node (value/signaling)

 

0 Kudos
Message 4 of 24
(7,630 Views)

You should have a look at this Dr. Damien's Developement post. It shows two ways of creating a queued state machine with Event handler.

Basically you will nedd to do the following:

a) check for the queue timout, if so go to the idle state

b) place the event structure inside the Idle state

 

Then you can enqueue State 2 inside the State 1.

 

Felix

0 Kudos
Message 5 of 24
(7,630 Views)
I am trying to keep the Event Structure outside my State Machine, to keep the "Producer" out of the "Consumer". The queue works great, but I don't know how to manage them to trigger State 2 from State 1.
Message Edited by dan07 on 04-04-2010 07:38 AM
0 Kudos
Message 6 of 24
(7,626 Views)

Then you need to have two parallel while loops, one for the Event handling and one for the state machine. But in this case, triggering state 2 out of state 1 isn't good. You should instead always send 2 commands to the consumer 'State 1', 'State 2'.

 

Felix

0 Kudos
Message 7 of 24
(7,615 Views)

you can put an enqueue element function inside the case structure and let the state machine feed new states into the queue. the problem is that your while loop will wait for an event before it starts another execution.

 

your architecture will work better as two separate loops: one for the event structure, and one for the case structure (producer consumer). 

 

 

-Barrett
CLD
0 Kudos
Message 8 of 24
(7,591 Views)

Hello guys

 

Now I have two while loops running (Producer and Consumer). Is there anything else that I can improve in my code?

 

Thanks

 

Screen.jpg

Message Edited by dan07 on 04-04-2010 04:39 PM
Message 9 of 24
(7,561 Views)

looks good!

 

-why trigger events on mouseup?  What I think is most common is to use value change, which handles the different ways the control can be changed (ie keyboard), and also if you absolutely have to, you can use a value(signaling) property to trigger that case.

 

-handle the panel close? event to perform the same function as your stop button. 

-Barrett
CLD
0 Kudos
Message 10 of 24
(7,542 Views)