LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Using one button to start and stop

Hello 

 

I am not a seasoned LabVIEWer so please forgive me for any mistakes. 

 

I am trying to control data acquisition using one button to start and the same button to stop. 

 

I would like there to be a start button because I want the program to be running to allow other functions to work before the front panel items are stored and data is acquired. (ie. allowing the user to change front panel items whilst the program is technically running). 

 

I have attached a VI which successfully uses the start button to start the acquisition but requires a separate stop button to finish it. Any help in how to eliminate the stop button and any improvements on the current methods used would be much appreciated. 

 

Kind regards

0 Kudos
Message 1 of 7
(3,621 Views)

Generally, you should have a single loop to handle your GUI.  That is the loop which contains your Event Structure.  You can use Notifiers or Queues to send messages to your other loops to start acquisition, stop acquisition, close, etc.  Look into the Queued Message Handler for more details.


GCentral
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
0 Kudos
Message 2 of 7
(3,614 Views)

Unless i'm misinterpreting your advice, I prefer to use channel writers as they are easier to follow rather than queues. I'm already using channel writers to pass between the producer and consumer loop but I'm not quite sure how using using more queues/channel writers would solve my issue? Would you mind explaining further or providing an example please? Thanks

0 Kudos
Message 3 of 7
(3,603 Views)

You need to start over and implement a simple state machine with one single event structure. Your "Acquire" event structure is outside and can only execute once. This means that if somebody would press that button again later, your UI will lock up forever, because the event can no longer be serviced.

 

As a first step, get rid of all the hardware interactions and create an UI that simulates the hardware. Once that works as desired, add the IO.

0 Kudos
Message 4 of 7
(3,586 Views)

As I've not yet installed LabVIEW 2019 I cannot open your code. However, typically this would be done with an event structure for your button. You then send the appropriate message based on the state of the button.

0 Kudos
Message 5 of 7
(3,581 Views)

I use Channel Wires all the time.  However, you are using the wrong Channel Wire.  The Stream Channel Wire is, indeed, a "super Queue", suitable for point-to-point wiring.  But what you need is a Channel Wire that accepts Branching, like a Tag or a Messenger.  

 

Here's a picture of a Event-driven State Machine, with Tag Channels carrying State information from the middle (State Machine) loop to itself, and also from the top (Event) Loop to the State Machine.  In addition, there is a Producer/Consumer design between the Sampling Loop in the State Machine and the Display Loop below it.  I created this is 2016, when Channel Wires were first available, so you should be able to open it with whatever version of LabVIEW you are using.  Note that the Tag Channel allows the information to branch and merge, acting as a Feed-back loop and as an "Event-injection" pathway.

DEMO Complex DAQ.png

 

A related Design Pattern to the Event-driven State Machine is the Queued Message Handler (there's a QMH Project Template that ships with LabVIEW).  I frequently create a "Channel Message Handler" by replacing the Message Queue with a Messenger Channel.  There's a "natural mapping" between the QMH and the CMH -- both use a "Message Cluster" consisting of an Enum representing "What to do" and a Variant representing optional Data.  I generally create a "Send Message" VI that takes the Enum and an optional Argument and creates a Messenger Channel output, and a "Receive Message" VI (there's only one, at the input side of the Message Loop) that takes the Messenger and outputs the Enum and optional (Variant) Argument.

 

I've also attached this VI as a LabVIEW 2016 file.

 

As to creating a "One-Button Front Panel" (which was the reason for your Post) -- think about your User, who doesn't want to "guess" what button to push, nor guess what the "one button" does.  Have Your Cake and Eat It, Too -- create three buttons, with obvious names like "Play", "Pause", and "Stop".  If you want the User to push only one, then set the Visible property of the other Buttons to False.  Once you are done with a Button (such as after you push "Play"), in the "Play" State, set the "Play" Visible Property to False, and set the "Stop" and/or "Pause" Visibility to True.  Note you can also place the buttons "on top of" each other -- LabVIEW has convenienntly made it so you can't press an invisible Button.

 

Bob Schor

Message 6 of 7
(3,511 Views)

Thanks very much for the example, I will use this as a template to get started!

 

And good to know about the invisible button thanks!

0 Kudos
Message 7 of 7
(3,481 Views)