From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Stop button not working with channels.

Solved!
Go to solution

Hello,

 

I am trying to do something like what's shown in the attached snippet, but the stop button doesn't work. It does when I use property nodes for the data channel, but for code readability I'd much rather use the channel.

 

The 50ms wait is, sadly, required, since I think that's where the problems lie (it certainly works without it). Any ideas?

0 Kudos
Message 1 of 5
(2,373 Views)

Do not use the standard setting "infinite time-out" on the "stream" channel reader, otherwise the stream reader waits infinitely for data that never gets generated by your writer loop. Check for yourself by switching to "highlighting" mode after pressing the stop-button.

 

Alternative: Use a writer stream with abort, then the reader gets destroyed too:

 

grafik.png

Regards, Jens

Kudos are welcome...
0 Kudos
Message 2 of 5
(2,362 Views)

The Tag setup will effectively signal all of the loops to stop running, but you still have an active Stream Channel.  Fix this by wiring the output of the Tag Channel (that becomes True to stop) to the "Last Element?" input of the Stream to also stop the Stream Channel (that's why it is there!).

 

Bob Schor

Message 3 of 5
(2,338 Views)
Solution
Accepted by topic author JCooper509

And a third easy solution, haven't thought about that, so I made a quick screenshot:

 

grafik.png

 

Regards, Jens

Kudos are welcome...
Message 4 of 5
(2,324 Views)

Not only is Jens' solution "easy", it is "better" than my original (correct) Solution.  Here's why (and a final example to illustrate the point):

  • You have two loops in a Producer/Consumer Design Pattern.  The correct way to stop such a pair is for the Producer to get a signal ("Time to Stop"), to stop, and then to tell the Consumer to stop.  This way, you can't have "orphan data" in the Producer-to-Consumer pipeline.
  • Until Channel Wires were invented, this was neither obvious nor emphasized (I only started yelling about it a few years ago, myself).  But Channel Wires, particularly the Stream Channel (used for P/C Streams, after all) include both "Last Element?" and (if you only want to stop both loops but not send data), "Valid Data?".
  • If all you want to do is have a Stop that fires once and then stops, an easy way to do with, without a loop, is to put it in an Event Structure.
  • The Tag stops only the Producer.  The Producer then stops the Consumer.Tag Stop Producer-ConsumerTag Stop Producer-Consumer

    Bob Schor

0 Kudos
Message 5 of 5
(2,316 Views)