LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

State Machine Data Acquisition

Solved!
Go to solution

I am trying to write a vi to collect data and allow the user to input header information and setup any parameters. Following the example for a state machine, the data will be acquired and written to file in one state. The header information, data analysis parameters, and file name created in another. The user will enter the information and start the data acquire state when ready to take a measurement. I noticed that if the state is running and the user selects another state the user loses ability to click any other state or abort button. It seems that once the loop in state 1 loses the focus I can not get it back unless I stop the vi and start again. I can disable all other buttons or options while in state 1 however I wanted to see if another more appropriate solution exists. I attached a sample of what I am trying to do. I left out the data acquire component that would run inside the loop of state 1.

 

0 Kudos
Message 1 of 9
(4,710 Views)
Solution
Accepted by ChrisH76

When you are in State 1, you have to press the "Stop Data Acquire" button for the other buttons to do something. This you are in a loop that won't terminate until Stop Data Acquire is true. All other inputs would don't do much. If you press the Stop button while in this state, I think the front panel is locked because the event structure locks the panel (it is a checkbox option you will see if you edit the Stop: Value Change event). Otherwise, you are essentially always in the Wait for Data state where all the buttons should be more or less responsive.

 

I actually think disabling the other buttons is a decent solution. I often either combine all the references to the control in an array and enable and disable them. Or I put them in a cluster or tab and disable everything in the cluster or tab that will be disabled (then you just need to drag new things into the cluster to get them to disable at the right time). You can also use a tab to have one tab visible when in state 1 and another tab visible when in all the other states.

Message 2 of 9
(4,702 Views)

eems to me an example where a producer/consumer design would be best. I recommend that you look into that design pattern.

 

Quick example of how your example would work using channel wires (can be implemented using variables, queues, etc):

State Machine Test (2 loops)_BD.png

Marc Dubois
Download All
Message 3 of 9
(4,699 Views)

This must be a new element added to NI. Did this exist in earlier versions of LV or did this start with 2017?

0 Kudos
Message 4 of 9
(4,666 Views)

I'm referring to the channel wire!?

0 Kudos
Message 5 of 9
(4,664 Views)

Channel wire was added in 2016

Message 6 of 9
(4,658 Views)

Marc,

 

Thank you for the response. I did consider using producer/consumer however (at the time) my code was not processing much for the HMI screen so I opted for the state machine approach. Plus the approach seems more complicated with the messaging/notifications.  I will revisit it as I am considering on adding a step to display the error of the measurement for the operator. This will not be stored in the data file and warrant the producer/consumer pattern. I am not familiar with the channel wires. I am using LabVIEW 2015.

 

Thank you,

 

Chris

0 Kudos
Message 7 of 9
(4,642 Views)

Majoris,

 

Thank you for the response. I implemented the able/disable option and the code is working now with out hanging.

 

Thank you,

 

Chris

0 Kudos
Message 8 of 9
(4,640 Views)

@ChrisH76 wrote:

Majoris,

 

Thank you for the response. I implemented the able/disable option and the code is working now with out hanging.

 

Thank you,

 

Chris


The best way to say thanks is to mark solutions or give kudos 🙂

Message 9 of 9
(4,632 Views)