10-28-2014 11:26 AM - edited 10-28-2014 11:34 AM
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.
Solved! Go to Solution.
10-28-2014 11:40 AM
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
10-28-2014 12:01 PM
Additionally, look into State Machines. I find they are extremely useful in situations like this.
10-28-2014 12:09 PM
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.
10-28-2014 12:24 PM
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.
10-28-2014 12:28 PM - edited 10-28-2014 12:29 PM
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.
10-28-2014 12:30 PM
@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.
10-28-2014 12:39 PM
oh..i see.
let me try that.
10-28-2014 01:04 PM
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!