LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing Data Between Loops & Loop Timing

Hi,
 
Attached is my code in-progress for the project I am working on.  Here is a little background on what I am attempting to do.  The idea of the program is that data can be recorded every 5 seconds from 4 different sources.  3 of these sources are acquired using the data acquisition card.  The 4th device is a meter that outputs data in a comma delimited format.  This 4th device is accessed over the serial port, and the fastest the meter can output is every 5 seconds.
 
As a beginner still learning LabVIEW (hence very messy code), I am trying to figure out a way so that I can still update all of the instruments faster than the 5 seconds that I would be limited to if I placed the Serial Interface code in the DAQ While Loop.  Currently I am trying to have two while loops and passing the serial data into the other.  I don't think I can do this, but I figured for illustration purposes hopefully this would help.
 
The reason for this is so that as a user makes an adjustment they can see the movement on the DAQ devices more in real-time, otherwise there will be a lag.  Currently in the upper While Loop (DAQ While Loop), I have it set up the way I would like to save to a file as well if this helps at all.
 
Any help would be greatly appreciated, especially on just general code comments as well.   Please let me know if you have any questions.
 
Thanks
 
0 Kudos
Message 1 of 4
(7,162 Views)
It might be better if you could attach the actual program, too many things are not really clear by just looking at a picture of the code.
 
Some simple comments:
  1. You cannot run the two while loops in parallel the way you do it here, because there is a wire between them. This means the upper loop cannot start until the lower loop has finished. It's all in the dataflow. In order to run parallel loops, the loops canot have a wired data dependency. Have a look at e.g. queues, for example.
  2. You seem to have gauges and a seperate digital indicator for each. Delete the digital indicator, right-click on the gauge, and select "show digital display" 🙂
  3. Why do you use "display message to user" in the main loop. Doesn't that stall the entire code?
  4. Why do you need a local variable for "experiment duration"? Just place the real terminal (which is currently not wired) in its place.
  5. Using a dynamic data conversion bullet to turn a scalar into an array is unusual. Just use "build array".
  6. Your 5 sec timer" logic is flawed. I can easily imagine a scenario where logging is skipped. What if the time is read at the 4 second and 6 second stamp only due to loop delays?
Message 2 of 4
(7,154 Views)
Thanks for the comments thus far, it is really helpful to get insight from someone who knows LabVIEW far better than I.
 
I attached the code that corresponds to the block diagram picture, with a few modifications as per your suggestions.
 
1.  I realized when creating this program that the two while loops would not work, but I figured by doing this it would be slighlty easier to see what I was attempting.  As far as queues does anyone have any good examples of these, I have found a few but the comments in them are rather sparse and it is hard for me to grasp the concept a little.
2.  I did not realize there was a built-in digital display for the gauge, shouldn't have looked a little closer in the documentation I suppose. 
3.  The "display message to user" was placed there to see what the effects would be.  As I am still new to LabVIEW I was trying to discover the best way to prompt a user if their meter goes over a certain value.  This would serve as a warning for them to turn the meter down.  If anyone has any suggestions please let me know.
4.  Again this was placed there as a learning "experiment" to see what local variables could do.
5.  Just missed that.
6.  If you are referring to the upper loop 5 sec timer, I do believe this logic is correct.  If I time it with a stop watch it seems fairly close (barring starting exactly at the same time) to the 5 sec mark.  Maybe I'm wrong, again any suggestions for a better way would be great.
 
Again the idea of the program is to record data from 4 sources.  If I could figure out a way to update the 3 sources as fast as the DAQ Board acquires, that would be nice as it would be easier for the user to see real-time events.  The end result is to be able to record the 4 sources every 5 seconds (when specified) into a file to be opened in Excel.
 
Thanks for any help.
0 Kudos
Message 3 of 4
(7,149 Views)

I'm not at a LV pc so I can't comment specifically on code.  Here's some generic advice though:

I'd start up an independent loop that talks to the serial instrument and whenever it gets data back, it "publishes" it to some globally-accessible location.  A standard global variable is conceptually the simplest such place, but there are other options that are typically preferable such as "functional globals", notifiers, or queues.  Personally, I'd probably use a notifier here, but notifiers admittedly take a little getting used to.

Now there's another faster independent loop that's acquiring DAQ data.  Well, whenever new DAQ data is retrieved you would also query this "global" which holds the most-recently updated data from the serial instrument.  You'll probably spin through several DAQ loops which keep retrieving the same constant serial data, but at least you won't be sitting around waiting for new stuff.

-Kevin P.

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
0 Kudos
Message 4 of 4
(7,124 Views)