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: 

how to handle event structure with two loops

Solved!
Go to solution

i have a question regarding user event structure using 2 buttons?

 

button 1: START LOGGING DATA

button 2: STOP LOGGING DATA

 

how would i control my 

event structure cases so that it will work? because right now as the loop is logging data.. i cant stop the loop, when i clicked on either button.

 

Untitled.png

 

 

Untitled1.png

 

Untitled2.png

 

0 Kudos
Message 1 of 9
(3,030 Views)

It is difficult to tell exactly what you are doing from images of parts of the block diagram.  The parts not shown may be as important as the parts you show.   Please post your VI.

 

In general no time-consuming code, such as indefinite loops or user dialogs, should be inside an event structure. Look at the Producer/Consumer Design Patterns which come with all recent versions of LV. Basically you have one loop with the event structure. Inside the vent cases are the button terminals and Enqueue. In the other loop the commands are Dequeued and the data acqusition and logging takes place there.  That way the event structure can always respond rapidly to new events.

 

Lynn

Message 2 of 9
(3,021 Views)

Additionally, look into State Machines.  I find they are extremely useful in situations like this.


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
Message 3 of 9
(3,009 Views)

i am currently using my code as a state machine. 

thats the example i was looking it. 

except that its an indefintely loop unless the operator stop the data logging. 

 

but i'll look into producer/consumer loop as well. 

 

 

0 Kudos
Message 4 of 9
(3,003 Views)

You need to move all of your code that is inside of your Event Structure into other states of your state machine.  You are allowed to make more states.  Just be sure to save that Enum to something in your project instead of still pointing to the example's enum.


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
Message 5 of 9
(2,989 Views)

the problem with moving it out is that I dont have control of when the DATA LOGGING STARTS?

i want the data to start and stop with the click of the button..

it gives time for me to do my testing. 

 

yeah.. i am saving trouble saving vis and .ctc for something. 

it is always pointed to where i got the examples or other vis i looked at.

i'll play with that some more later, but i do want to get my state machine to work as the start of me clicking on the button and stopping the data loggin. 

 

0 Kudos
Message 6 of 9
(2,983 Views)
Solution
Accepted by topic author super_saiyans

@super_saiyans wrote:

the problem with moving it out is that I dont have control of when the DATA LOGGING STARTS?


Sure you do.  When you get your button press event, you tell your state machine to go into the logging state.  You should also make sure you go back to visit the Wait For Event state to check for the stop button's event.


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
Message 7 of 9
(2,977 Views)

oh..i see.

let me try that. 

 

0 Kudos
Message 8 of 9
(2,969 Views)

ok. 

i did exactly what you said "When you get your button press event, you tell your state machine to go into the logging state.  You should also make sure you go back to visit the Wait For Event state to check for the stop button's event." and i was sucessful at that.

THANK YOU BOTH FOR THE ADVICEs!

0 Kudos
Message 9 of 9
(2,958 Views)