LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine within a Queued Message Handler

Dear Dora,

 

     Your observation is totally "on the mark" -- my suggestion really is more complicated than it needs to be.  But, fortunately, there is a simpler way -- simply embed your "State Machines" right in the Message Handler explicitly.  Here's what I mean (along with an example).  Suppose you have two sequences, Seq 1 and Seq 2, that you want to run, and each has three Steps (such as Seq 1 Step 1, Seq 1 Step 2, Seq 1 Step 3, Seq 2 Step 1, etc.).  I'm going to create a Button, Sequence 1, that, when pushed, executes Sequence 1.

State Machine Demo.png

This shows how you would start Sequence 1 when the Sequence 1 button is pressed -- you'd issue the Seq 1 Message, which the Message Handler would see, do so initialization (not shown), then issue the Seq 1 Step 1 Message to do the first Step of the processing.  This would be followed by the Seq 1 Step 2 message, and so on.

 

Since you are using one of the LabVIEW-supplied Templates, you understand that the Message (which I show as a Type Definition feeding the Cluster bundle and as the input to the Create Queue) includes a Variant, which I'm not using in these simple steps.

 

Since there are two parallel loops, the question arises how to end them together.  My technique is to have the Message Handler end first, and subsequently "cause" the other loops to end.  To end the Message Handler, there is a Stop button, trapped by the Event Handler loop, that generates a Stop Message, which wires a True to the Stop Indicator of the While loop.  When this loop exits, it releases the Message Queue.  Meanwhile, the Event Loop, every 200 msec, executes a TimeOut which has a Query Queue function that basically does nothing, but generates an Error if the Queue has been released, and the Error stops the Event loop.

 

So this should accomplish your goal of having a State Machine within a Queued Message Handler -- just make each of the States of each of your "State Machines" unique messages (Seq 1 Step 1, which differs from Seq 2 Step 1).

 

BS

0 Kudos
Message 11 of 11
(1,196 Views)