LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Event Driven VI

I have some experience using CEC testpoint, Visual basic, and some
Agilent VEE. With these programs I can create event driven actions.
For example, when I press a button I send data out of the serial port.

I am new at Labview and am trying to figure out how I can accomplish
the following?:

Set up a Ring control that has 3 different values and based upon the
value selected, choose 1 of 3 strings to send out the serial port. I
want to be able to select a value and have Labview send it out only
once. I want the action to only occur when the user changes the value
of the ring control.

Any help would be great
0 Kudos
Message 1 of 4
(3,179 Views)
You will need a while loop. You will continuously poll (check the value of) your ring. If it changes value, you will send a command to the serial port. You will need to wire the ring to a shift register and compare the rings value to its value in the previous loop cycle.

See the attached file for an example

-Jim
0 Kudos
Message 2 of 4
(3,179 Views)
Chris,
Jim K's answers are always right-on, but, since I have an older version of LV and can't see his VI, I thought I'd go ahead and give you another - just to look at.
There are many ways to do what you want; personally, I'd choose a list box over a ring because you can see all the options easier in a list box.
Good Luck, Doug
0 Kudos
Message 3 of 4
(3,179 Views)
chris lindsey wrote:

> I have some experience using CEC testpoint, Visual basic, and some
> Agilent VEE. With these programs I can create event driven actions.
> For example, when I press a button I send data out of the serial port.
>
> I am new at Labview and am trying to figure out how I can accomplish
> the following?:
>
> Set up a Ring control that has 3 different values and based upon the
> value selected, choose 1 of 3 strings to send out the serial port. I
> want to be able to select a value and have Labview send it out only
> once. I want the action to only occur when the user changes the value
> of the ring control.
>
> Any help would be great

I've not used ring controls much. The way I do event detection is to
use a while loop. In the loop compare the value of a control with the
value from the previous loop. You can easily get the previous value by
feeding the control into a shift register created on the loop (Right Click
on the border of the loop > create shift register. Feed your control into
the right hand terminal and the previous loops value becomes available on
the left hand terminal. You might need to feed a constant into the left
hand terminal from outside the loop which is the same as the default value
of the control to stop the event being triggered on the first loop
(initialize the shift register) but try it without first as I'm not sure
on this.
When you have detected a change (use not equal comparison) you can use
some case structures to identify the value and set a string to output to
the port.
I usually put a wait command in the loop (maybe 250ms min.) which stops
the loop executing like mad and sucking all your CPU power.
I have also seen some mention detecting the mouse events via the
windows API using a library downloaded from ni.com; I think you could then
trigger an Occurrence to examine control values, but I'm not sure if this
could be used to catch a ring control, in any case you would still have to
compare with a previous value to check for a change and this is only a way
of avoiding continuous polling of the control.
If using a boolean switch control to trigger an event then again I
have the control in a while loop but set the mechanical action to latch on
press (to give a single pulse when clicked) then trigger the event via a
case structure on the boolean value; this way the event only occurs once
per loop.
I'm sure there are other ways of achieving what you want, maybe better
ones; but that's Labview!

Hope this helps in some way,
Dave.
0 Kudos
Message 4 of 4
(3,179 Views)