LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to have a channel writer mark a message as the last to be received?

Solved!
Go to solution

Hello,

 

I have a state machine that uses channel wires to move between states. I'm not using a shift register because I also have a event structure outside of the state machine so that I can stop the state machine with the front panel at any point. The problem that I am running into is that the stop button gets pressed, the stop state is sent through the channel wire, and the reader receives it and goes to the stop state, but the previous state had sent the next state over the channel wire, so it leaves the stop state and the state machine continues running.

 

I'm thinking I could do some sort of logic inside the while loop that would stop sending cases to the case structure after the stop state is received, but I feel like there is a more simpler way to handle this. I've tried the Write with Abort, but I haven't been able to get that to work. I've included an example of what I am working on.

 

thansk,

0 Kudos
Message 1 of 8
(1,159 Views)
Solution
Accepted by T_Black

I've been using the Channel Message Handler model (I think I might have "invented" the name in 2016) for 6-7 years.  The way I handle ending loops in the CMH model is to stop the While Loop in the appropriate State (and Event Handler "case").

 

In the code you showed, you wired a "False" constant to the two While Loop Stop controls.  Either the Stop or the Fail state (or both?) should do two things:  wire a True constant to the Message Handler's Stop Control, but also you need an Input to the Event Loop (either a Tag Channel or an Event Messenger) that will stop the Event Handler Loop (by, again, wiring a True to the Stop Control).  I would not use a Message Write with Abort in the Event Loop.

 

Bob Schor

Message 2 of 8
(1,138 Views)

That did the trick. I really appreciate it. The stop state is used to shutdown the testing equipment and the VI itself. Is there any reason that I would need to stop the while loop that contains the event structure?

0 Kudos
Message 3 of 8
(1,094 Views)

If you do not shut down a running While loop, it will ________ running.  (fill in the blank, yourself).  Is this the behavior you want?

 

Bob Schor

0 Kudos
Message 4 of 8
(1,070 Views)

I'm pointing out that the stop state closes the VI. I think in any other situation it would make sense to shut down the event structure while loop.

0 Kudos
Message 5 of 8
(1,041 Views)

@T_Black wrote:

I'm pointing out that the stop state closes the VI. I think in any other situation it would make sense to shut down the event structure while loop.


I do not know why you are arguing with me.  The code you posted had two While Loops, one for the Event Structure, and one for the Message Handler.  Both had a "False" constant wired to the loop Stop Control.  I pointed out that a Stop State in a well-designed Channel Message Handler would take steps to stop (by wiring a True to .  the Stop control) every running While Loop.  

 

In the only code I've seen from you, all the Stop does is shut down the Messenger Channel, so no more communication is possible.  The While Loops are still (both) running.  The running VI will still be "running", but not doing anything (or, at least, that's very much what I expect to happen -- please let me know if aborting a Messenger Channel also kills the LabVIEW program in which it is running).

 

Bob Schor

0 Kudos
Message 6 of 8
(1,029 Views)

I wasn't trying to argue. I was trying to learn if there was another reason that I wasn't considering. I appreciate the help.

0 Kudos
Message 7 of 8
(1,028 Views)

Don't apologize -- you actually make a valid point (that I failed to realize).  You can use "Abort" to unconditionally "kill" a Messenger Channel (sort of a "Panic Stop") which might be important in some situations.  However, you still need to stop those While Loops.  However, if you use a "Write with Abort" Messenger Channel Wire, you need to read it with a "Read with Abort" Reader, and use the Abort output (in addition to wiring a "True" in the "Exit" state of your State Machine) to stop the Reader's While Loop.

 

To date (meaning since 2015, before their release in 2016), I've not used any of the "Abort" variants of Channel Wires.

 

Bob Schor 

0 Kudos
Message 8 of 8
(974 Views)