LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event structures??

Hello!

Now I would like to use an event structure to controll an event. We want to push a button and then an event is supposed to happen. I have read about this eventstructure but dont get it :-(. The question is how to do when we want to controll an event? We see the list in the left of the event structure and the label on the top but do not get how to use those... so the problem is how do we get the event structure to start from a button push? Hope you understand what we want... PS My english is not good maybe that is why I do not get how to do 😞 Best regards.
0 Kudos
Message 1 of 17
(4,204 Views)
Hi Ex-jobb

If you use the F1 help and search for "Event" you will get a list options concerning event structures.

Basically you Right Click on the frame of the Event Structure and select Add Event Case ... which will give you a list of controls that can generate events. Select a control from the Event Sources and then select an event from the Events list. The event case will be generated and will give you a terminal (NewVal) that corresponds to the latest value of the control. You can use this within the event case to control your code. I've attached a very simple example that simply triggers the Boolean case when the button is pressed and take the button value and sends it to the LED. Notice that you need a separate case for the Stop function.

Good Luck
Neil
0 Kudos
Message 2 of 17
(4,197 Views)
Hello!

Thank you for your answer. My problem is the following: I have a button "read list" and when one push that button I want the program to open my text-file and read it and write out some text and some more things on the front panel. I already have a few while-loops in this "section". I read that it is not so good to have while-loops inside the event structure. My problem is that I do not get how to "connect" the event to happen because of the button push. I could not figure it out with your example either :-(. The tip to read in the "help" section have I tried too...
Feel like I´ve forgotten my brain at home :-/. Must I have a while-loop around the event structure? Hmmm... thank you for your help anyway 🙂
0 Kudos
Message 3 of 17
(4,196 Views)
Hi

Yes you have to put the event-structure into a while loop. You also should place a control into its corresponding event-frame.

To react on the events, you can have another while loop with a case structure inside.

Have a look at the attachement. It's the producer-consumer design-pattern. You also can create this over the dialog which appears if you click "New..." in the menu.

In the event-structure, if a event occurs, a string is put into a queue. In the second while loop the string is dequeued and linked to a case-structure.

Instead of the strings, you also can create a custom control containing an enumeration (declared as strict type def). If you link this to a case-structure, the structure recognises the elements.

Hope this helps.

Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 4 of 17
(4,187 Views)
Hello!

No I do still not get out how this event structure works. I do not know how you connect the button that control if the event shall start? I have tried to right click and choose and then right click and choose which event to be coupled with for example the button push... but the problem is still there 😞 Thank you for your help anyway. Best regards
0 Kudos
Message 5 of 17
(4,173 Views)
Ok let's try it:

1. You place a control (e.g. a button) on the front panel.
2. right-click on the event-structure
3. select "Add Event Case..." -> a window opens
4. there you have an area "Event Sources" -> select the control you want to react
5. you also have an area "Event" -> select the type of event you want to react on (for a button usually "Value Change" is ok)
6. click "Ok"
7. now you can select the case of the ok button (similar to case-selection on a case-structure)
8. now place the terminal of the control inside this case
9. now it should work 😉

Hope this "step by step" description helps.

Thomas
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 6 of 17
(4,162 Views)
Ex-jobb

You don't need to connect the button terminal to anything.
When you press the button during run-time it triggers the code present in the Event Case defined for the button. The current boolean value of the button is passed to the Event Case using the NewVal terminal.
0 Kudos
Message 7 of 17
(3,894 Views)
Hi!

I think I understand what you're asking, so I hope this helps a bit...

First, you want to put the button you are reading inside of the event structure case that handles it. This will cause it to pop back up. At first this confused me, but you do NOT need to connect the button to anything - simply placing it there causes it to be read, which causes it to pop back up, given that you have the appropriate mechanical action (is it latch when pressed?)

Second, make sure to choose "Value changed" for the event type you choose, not button down or button up. I am not sure why this is the case, but it works best.

Lastly, you saw the producer/consumer example. You probably want to use a queue or an occurrence (queue preferred) and have the code that handles this button outside of your event structure.

Lastly, I believe you advice your were given was to have a while loop AROUND the event structure, not INSIDE of it. You are likely right if you read it not to have a while loop inside of an event structure. It probably is recommended because if you get locked up, you can't process any other front panel events. This would make sense from a programmatic point of view because the event structure, IMHO, is viewed like an interrupt service routine. Read the button, do the minimum to alert the outside world what to do (or do it here if very minimal - which in your case reading a file is not), then get out quick!

I hope this helps!

Jason
Message 8 of 17
(3,885 Views)
Hello again 🙂

Thank you for your help! Now there is a small question... when I drag out the event structure there is a "timeout"-event from the beginning. I have my event in there when I drag out the event structure. When I add a new event structure this program disappears and there is a label at the top with "event 1"... how can I control the event in the first "eventstructure" to say? hope you understand what I mean 😛 Thank you for your step by step-help 🙂 Best regards
0 Kudos
Message 9 of 17
(4,157 Views)
Sorry but I don't understand you. Could you be a little bit more precise?

By the way - the timeout event-case is always there.
Using LV8.0
--------------------------------------------------------------------
Don't be afraid to rate a good answer... 😉
--------------------------------------------------------------------
0 Kudos
Message 10 of 17
(4,147 Views)