LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Two while loops

I need to update time while doing other things. Since LV doesn't have
timers, I am using a separate while loop to update the time every 100msec.
My main loop is a separate while loop which used Event structures. My
problem is that I while I am reading bytes using the UDPRead in one of my
subVIs (called from main loop), I don't see the time update.

Basically when I apply power to my device, it takes upto 10seconds to boot
up. When it powers up, it sends pkts. on a knows UDP port. So in my main
loop, I apply power & wait in a loop calling UDPRead with timeout of say
1second. If timeout and 10seconds not up, I call UDPRead again and so on.
When I am doing this, I see time update so second while loop is running
fine. But when I get to read actual pkt, my ti
me update stops for more than
4 seconds. I have played with the UDPRead timeout, changing it from 100msec.
to 10sec.

Is there a way in LV for me to make a part of my application run under a
separate thread. Or even in case of 2 separate while loops, how do I know
that LV is running these under 2 separate threads. I think since I am
updating front panel in my second while loop, it is running in same thread
as my GUI thread.

I think it will be nice for LV to provide timer controls where I can
enable/disable them and set the timeouts.

vishi
0 Kudos
Message 1 of 3
(2,787 Views)
You can multithread your program by creating a separate VI for each section of code you want to multi-thread. Then go to VI Properties:Execution and select a priority and a thread. Be careful when selecting time critical as a priority because it can lock your PC if your VI does not have sufficient waiting.

LabVIEW has two time(r) values, a ms timer value and a get date/time. The first returns a continually incrementing ms time value (which will roll over after 2^32 ms) and second is the standard Universal time value - you will get a more accurate "time" value by using this in your timeout vi, e.g. init a shift register with their current value when you start and subtract this value from subsequent reads of these VIs. This should give you a slightly more accura
te elapsed time (though you would still see the "lock up" you described.) until you multi-thread.
0 Kudos
Message 2 of 3
(2,787 Views)
As a first experiment, I would place the UDPRead part of the code into it's own subVI and assign it a different thread. See if this cures it.
0 Kudos
Message 3 of 3
(2,787 Views)