LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Basic application to record data

I've built this application to acquire data from a couple DAQmx tasks. I want to record the temperature, pressure and liquid levels into a file. I also want to be able to turn a set of thermocouples on/off at the user's preference. I've successfully been able to record the data from the task that I want to, but that's about it. I know my code is janky, and I'm probably doing everything wrong. This is my first attempt at LabVIEW, and I'm trying to learn. Please take a look at my .vi and help me make it better.

 

Help I'm looking for:

  • I know the crazy while loop structure I have now is not the preferable way to do things. How can I clean this up?
  • How can I make a better timestamp for the spreadsheet file I'm writing to (I just want it to count elapsed seconds from the start, which it currently does, but maybe write the current date and time as a header)?
  • How can I activate/deactivate the thermocouples at the flip of a switch and possibly write that information to the same file as the other spreadsheet?
  • Why do the inner while loops continue to execute when I stop the outermost while loop?

Note: The function box for that converts a voltage to temperature, pressure and liquid level does not contain the actual functions I will use, those are just standins until I can actually test the program witht the real hardware.

0 Kudos
Message 1 of 3
(2,460 Views)

The while loops themselves are not so crazy.  Parallel loops are often used to run several tasks simultaneously and at different rates.  The outer loop is not necessary.  There are better ways to set the overal timing.

 

Two of your loops are infinite loops.  The only way to stop them is with the Abort button on the toolbar.  This is a bad way to stop a program. Someone on the Fourm suggested that using the Abort button to stop a VI is like using a tree to stop a car: It works but there are often undesirable consequences.  A notifier is a good way to use one button to stop multiple loops.

 

Use of local variables to move data around in a program is poor practice.  It can lead to race conditions and slower performance.  It is also more difficult to maintain.  The best way is always a wire.  However, you cannot wire data from one loop to another which runs in parallel.  You can use queues, Action Engines, and LV classes (LVOOP).  Search the help or the Forums for lots of information about these topics.

 

The formula nodes can be replaced by simple LV primitives (subtract, multiply, and divide).  All of those can be used directly on arrays.  No need to convert to clusters and unbundle.  To break out the data for display, either use an array indicator or Index Array.

 

Write to Spreadsheet File.vi opens, writes, and closes the file every time it is called. Doing this once a second for 8 data points seems excessive.  Accumulate data perhaps for a minute and then write?

 

Look at the Producer/Consumer design pattern and examples.

 

Documentation about what each loop does and why is a good idea.

 

Lynn

Message 2 of 3
(2,450 Views)

You can replace your top while loop with a sub-VI and place it in your bottom loop.  This will allow for better timing between your measurement and data logging (It will log directly after taking the measurement). 

As Lynne has stated, get rid of the outer while loop.  It's pointless.

I'm not sure why you are writing to the local variables in the bottom loop.  There's no need to do that.  Reading the variables in the top loop will read the current state.  What you are doing is like writing to a variable, twice in a row.  It doesn't make sense.

This is my personal preference, but I don't like to view control/indicators as icons.  It just takes up too much room.  You can decrease the size of your loops by deselecting "view as icon."  That's just me.

These changes will make your bd more manageable and more viewable (smaller).

You can take most of your code and condense it down into sub-VIs and still maintain the structure of the code. 

As I said, you can get it down to two loops, but why does the data acquisition have to happen in parallel.  Can you do it with one loop?  The simplest structure would be better than over-complicating it.

-----------------------------------------------------------------------------------------
Reese, (former CLAD, future CLD)

Some people call me the Space Cowboy!
Some call me the gangster of love.
Some people call me MoReese!
...I'm right here baby, right here, right here, right here at home
Message 3 of 3
(2,436 Views)