LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event-driven programming...can anyone help with this code

I am trying to learn event-driven programming, which is new to me. Can anyone help with this code. Brief description of the code: Reading data (frequency values) from a file and input into an array. Retrieve one value at a time from the array and update function generator with new frequency. Everytime the frequency value changes I would like to generate an event and indicate the same by using a round boolean (flashing) LED on the front panel. Tried implementing this but for some reason my while loops are not incrementing and event(s) not being generated. Would appreciate if someone can help me out with this.
0 Kudos
Message 1 of 21
(4,930 Views)
If I understand correctly you want to have that event case fire everytime the Frequency indicator updates.  In your event structure you are using the value cahnged event which only fires when the value is changed on the UI.  So indicators don't really fire this event.  You would only get it when the user changes the value, not when your code changes the value.
 
To get around that you can use the Value(Signalling) property.  It sets the value of the control or idictoar and causes the value changed event to fire as well.  So replace where you wire to the frequency terminal to that property node and you should get what you want.
 
As a side note I really see no need for the event code in your VI, but I will assume there is more to it then I am seeing.
 
Have a great day
0 Kudos
Message 2 of 21
(4,927 Views)

Evan,

I did use the Value (Signalling) property, but it doesn't seem to help as the while loop is not incrementing for some reason. Without using the event structure the VI works perfectly fine. I just started reading up on event-driven programming, so I am using my previous code to come with some simple examples to see how exactly it works. Can you throw some pointers as to what the reasons could be for the above problem. Thanks!

0 Kudos
Message 3 of 21
(4,916 Views)
You're using the event structure completely wrong.   
 
The event structure waits for an event to occur, and then perform the corresponding action.   That means, that your loop waits for an event.   However, no event occurs, so your loop doesn't increment.    The reason why no event occurs, is that the property node that fires the event, sits inside the event it should trigger... 
 
First, you should place the 'Value signaling' property node *outside* the event.   Place it for example in your 'set frequency & amplitude' part.    Now, at least you fire an event, to which the event structure can react.
 
Second,  get the event structure outside the loop that handles your data.   There's no reason for it to sit in that loop.   Place the event structure in it's own loop, outside your data handling loop. 
 
Now the things works as follows:  Your data handling loop fires an event every time it updates the 'value signaling' property node.  The event handler sits in it's own loop, and will react whenever it sees an event.
 
I've applied these two changes to your vi.    Didn't take care of the broken 'stop' boolean wires yet....
0 Kudos
Message 4 of 21
(4,900 Views)

Anthony,

Tried out ur suggestions...the loops are incrementing but for some reason the events are not fired in the event structure. What might be the problem according to you?

0 Kudos
Message 5 of 21
(4,892 Views)
Oops...   I should have checked better... Smiley Surprised
 
While you said that you used the signaling property node, you actually didn't.
 
You can have two value assignments in the property node:   "value"  and "value (signaling)"       Both update the control/indicator, but only the second one also fires an event.  So, you want to use the second one. 
 
The frequency property node on the diagram is using "value", and not "value (signaling)".   Correct that, and then it should work.
0 Kudos
Message 6 of 21
(4,877 Views)

Anthony,

I actually got it to work. Have another question...in the event structure, I would like to use a boolean indicator (round LED on the front panel) which flashes (True) each time a value changes and needs to be reset to false between changes. How does one write a True value to a boolean indicator in the event structure to accomplish this task?

0 Kudos
Message 7 of 21
(4,876 Views)

I would simply wire 'true' to the boolean,  wait a few hundred milliseconds, and wire 'false' to it.   Either using locals, or property nodes for writing to the boolean.

If you don't wait too long, then there's no harm putting that completely within one event. 

If you want the LED to stay on for seconds, then it might be wise to have the blinking handled asynchronously in a seperate loop, otherwise your front panel is not responding during the time that the LED is on.     Such a seperate loop can be very simple.  For example a loop waiting on a queue element, or waiting on a notifier.   

0 Kudos
Message 8 of 21
(4,858 Views)
Anthony,
I implemented the same idea as mentioned in your email yesterday and it works fine. Just set a boolean indicator to true for a few msecs and then set it to false in flat sequence structure enclosed within an event structure.
 
Another quesion I have is this on event-driven programming: this is an actual application in LabVIEW I am working on currently. I have 2 cases within a case structure. Case 0 takes care of setting the frequency of the function generator, which is code we have been discussuing so far. Case 1 is the code for controlling the PCI digitizer card for data acquisition. Each time the frequency is changed/updated in the function generator (Case 0), I will need to generate an event to trigger the digitizer card in Case 1 to acquire data and write to file. I have everything in place, except for the part where the appropriate event needs to be generated to trigger the digitizer card. I am really not sure how this can be done. For your reference, I have attached the following:
 
1. The actual LabVIEW application - Single probe dual coil DAQ
2. Zipped file of all the AlazarTech VIs
3. To unzip the above files, you will need to download 7-zip software by clicking on the link below. I am not sure if winzip also works, as the files were zipped using 7-zip.
 
 
Will look forward to your reply. Thanks!
 
 
 
Download All
0 Kudos
Message 9 of 21
(4,848 Views)

Hadn't had the time yet to look at your code.   But some thoughts before the weekend:

I wouldn't use a Labview event structure for triggering the DAQ card.  Keep the event structure for handling GUI events.   Do the data handling in a seperate loop, that you control with a queue.   It's similar to an event structure, except that you define the events yourselve as queue elements.

Take a look at the Producer/Consumer design patterns.   The producer is the GUI, and  is using the event structure.  The consumer is the loop reading the queue.   Put your DAQ code in the consumer loop.  Firing an event to trigger the DAQ card is then simply a matter of putting an element on the queue.

The queue can contain anything.   Could be text, in which case you could send commands and data (flattenend to a string) over the queue.   Queue could also be a enumerate, if you only send commands, and want a case structure in the loop.  Or you could even use an cluster as the queue element, which command and data parts...

0 Kudos
Message 10 of 21
(4,835 Views)