LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to initialize variable in while loop?

I have a program that records and displays data from several channels of a NI DAQ board. Also, it plays an AVI in Media Player included as an ActiveX object in the VI.

I would like to automatically start playing the AVI when the voltage on one of the channels on the DAQ board reaches a certain level.

I am thinking of using a global variable to change the Play State of Media Player from 0 to 1, in order to start playing.

The problem is this. The part of my program which monitors the channels on the DAQ board is enlosed in a WHILE loop. The program runs so long as the WHILE loop is active. The channel that I am monitoring for the signal to start Media Player starts off with a value of 0. At some point, the value being recor
ded changes to 1, after which it continues to switch between 0 and 1.

I want the global variable to be modified ONCE only, that it, it should start by reading the initial value on the channel (which is 0), continue to monitor to it until it changes to 1, and then cease to monitor it altogether, leaving it at 1 for the rest of the time the program is active.

Does anyone have any suggestions on how to do this?

Thanks.

Pankaj Saxena
0 Kudos
Message 1 of 3
(5,502 Views)
Hi,
you can use the next thing:
Let the boolean variable B corresponds to the state of your signal from DAQboard. If signal is greater then some level then B=1 else B=0. As I undersand now you simply pass this value B to your global variable G.
But actually to set G=1 once and keep its value during all the program you have to make the logical OR operation in such a manner:

G=B or G

In this case at the first moment G=0, B=0 and the Media Player is stoped. When B=1 G becomes equal to 1_or_0=1 and the player starts. Then G keeps its value independent of the value of B.

So just replace your current G=B with G=B_or_G

Good luck.

Oleg Chutko.
0 Kudos
Message 2 of 3
(5,502 Views)
JNR wrote in message news:<5065000000080000008D510000-1023576873000@exchange.ni.com>...
> I have a program that records and displays data from several channels
> of a NI DAQ board. Also, it plays an AVI in Media Player included as
> an ActiveX object in the VI.
>
> I would like to automatically start playing the AVI when the voltage
> on one of the channels on the DAQ board reaches a certain level.
>
> I am thinking of using a global variable to change the Play State of
> Media Player from 0 to 1, in order to start playing.
>
> The problem is this. The part of my program which monitors the
> channels on the DAQ board is enlosed in a WHILE loop. The program runs
> so long as the WHILE loop is active. The channel that I am monitoring
> for the signal to start Media Player starts off with a value of 0. At
> some point, the value being recorded changes to 1, after which it
> continues to switch between 0 and 1.
>
> I want the global variable to be modified ONCE only, that it, it
> should start by reading the initial value on the channel (which is 0),
> continue to monitor to it until it changes to 1, and then cease to
> monitor it altogether, leaving it at 1 for the rest of the time the
> program is active.
>
> Does anyone have any suggestions on how to do this?
>
> Thanks.
>
> Pankaj Saxena

Hi Pankaj,
sounds like you need to create a shift register on the edge of the
while loop, pre-initialised with a 0. You can then compare not only
your new value from the DAQ channel, but also the old value. Use an OR
gate between the old value (shift register) and the DAQ channel (don't
worry, it works with integers too - 0 = false, 1 = true), and then
pass the output of this to
your trigger variable, and your shift register on the output side of
the loop.
A better option would be to use a notify synchronisation though. You
could set the Media player section to wait on the notify, and then off
it goes when the DAQ channel goes to the set level. It doesn't matter
if the DAQ channel goes up again, because you're not watching for it
any more.

Hope that helps

Sash
0 Kudos
Message 3 of 3
(5,502 Views)