LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write measurement to file appends data instead of making new file

Solved!
Go to solution

Hey guys, so I need to save two different sets of data to two different files. One data set (DatasetA) is a few local variables that I'm continuously appending to the end of a file (no problems here). The other data set (DatasetB) is two arrays that I'm trying to always dump to a new file called 'base_name'+'iteration_number'.csv.

 

Here is where my problem lies. I need to be able to run the VI without logging any data during normal operation. The user must hit the start button to begin data logging (for a set amount of time) and once that time expires, dump the logged data to the files. If I stop and start the whole VI between each data log, then DatasetB is properly saved to a new file. If I hit the start test button multiple times without resetting the VI, then each logged DatasetB (DatasetB1, DatasetB2, etc) is appended to a single file. What I need is a new file each time I hit the start test button. I am currently using the 'Save To Series Of Files' option.

 

Any advice or help would be very much appreciated! Thanks in advance

0 Kudos
Message 1 of 7
(2,991 Views)

Why are you passing filename, it has already configured in the configuration dialog.

Remove the file path and try.

bp
0 Kudos
Message 2 of 7
(2,962 Views)
Solution
Accepted by topic author mbustin

Ok, I have some hints (based on what I see in "Mosquito.vi"):

  1. Learn how to program a state machine. Using a state machine, such features like re-startable file logging is just simple.
  2. Get rid of that silly conversion to dynamic data. Also, set that "Analog 1D Wfm DAQmx Read" to read 1D array and not Wfm data type (NChan NSamp). Since you only take the first element from that Waveform array, the recent operation does not make sense. I think what you want is the "1D DBL, 1Chan NSamp" instance of this DAQmx Read vi...
  3. Do not use those the "Write to Measurement File" Express VIs. Use low level File VIs for performance reasons (TMDS, binary or text), in this case you do not need dynamic data type!
  4. I am pretty sure that combination of DAQmx tasks and the Timed Loop is wrong. It is almost always wrong to use a Timed Loop for a non deterministic OS, like Windows.

I think people from the forum could give better advice what kind of design pattern could be used here, if you explain what is the goal of this VI. Plus some more info, do you need tight sync between those two DAQmx task data stream? Maybe you need to use some form of triggered acquisition...

 

edit: plus info for point 2.: so if you want to sample only a single channel, you also need to change the DAQmx init part...

Message 3 of 7
(2,937 Views)

Sorry I went MIA, I had a few other issues that needed to be addressed these last couple of days. This is all great advice, thank you! I implemented items 2 and 3 that you recommended and now it all works properly.

 

I don't need a sync between the two data streams. The digital data input rate is governed by the speed of a paddlewheel which will vary significantly in frequency. The analog data input is just a load cell that actually only needs a sampling rate of 200 Hz, but the NI9237 that I'm using has a minimum sampling rate of ~1.6K so we're just going with 2K Hz. We aren't doing any analysis of any curves, just averages over a set duration.

You're right, I have much to learn about Labview. Resources online for a beginner seemed to point me in every direction possible so I just started from the DAQ Assistant and then went from there. If you have a recommendation for a good document on how to approach Labview, I'd be interested in reading it.

0 Kudos
Message 4 of 7
(2,908 Views)

To build off of this,

 

When using the Open/Create/Replace File primitive, I can't seem to figure out how to identify whether or not a file is being created and then opened, or just opened. It would be nice to be able to do this so I can add a header line whenever a file is created, but not every time it is opened after its creation.

0 Kudos
Message 5 of 7
(2,900 Views)

Nevermind, I found the 'Check if File or Folder Exists' VI...

0 Kudos
Message 6 of 7
(2,898 Views)

If you are a beginner in LabVIEW, it is not a bad start. You should go on with the learning, and you will see you will improve fast.

First of all, here is a page from our fellow forum member, Hooovahh:

https://forums.ni.com/t5/Community-Documents/Unofficial-Forum-Rules-and-Guidelines/ta-p/3536495

Scroll down to the section "Looking For Free Training". Pay special attention to the last two links. Either if you are a student, or you own an active LV licence (SSP), you are eligible to access the LabVIEW Core 1, 2, 3 etc online video trainings. I really like the new versions of these "core" ones (v2015). There is even an online training "Data Acquisition Using NI-DAQmx and LabVIEW" under this site.

Plus, I guess you already know this page?: http://www.ni.com/product-documentation/5434/en/

 

OK, back to your actual application, I downloaded your original VIs, and checked them again:

  1. When you start learning via the above resources, you will see an important recommendation. Namely, you should use LV project to keep all your VIs and controls (Type definitions are very very important and useful things in LabVIEW, you will see later why) organized and together.
  2. Data acqusition: in your original Main VI (Mosquito) you Initialize your 2 DAQmx tasks at EVERY iteration. This is not optimal at all. The usual way to do DAQmx acquisition: you initialize your hardware resources (creating DAQmx tasks, timing, etc) ONCE BEFORE you enter the while loop, and inside the while loop you only do DAQ. I do not really understand here that you have 2 Cases inside this while loop: one with a Timed loop, and the other without, but there you also erase a DAQmx error by code: -200474. This does not fix the problem, it is just like a bandage.
  3. Can you explain further what is the goal of these two cases? Then maybe we can recommend better solution. Also, we should eliminate that Timed loop. You should use DAQmx Timing.vi for that Counter task, and not that Timed Loop.
  4. About that Strain analogue task at the bottom: you said you do not need tight sync between the Counter task and this. I feel it would be better to have a dedicated separate while loop for this Strain measurements, where you only acquire this data. You average it in a continuous manner, and you send this data in a lossy way (we do not need tight sync, only a kind of tag info: "latest measured value") to a Data logger loop to combine the value with the Counter task results into a file. You can transmit such data between loops for example using Notifier or Tag Channel...
  5. So you could have 3 parallel While loops: one for the Counter, one for the Strain, and one for the File logging. You would get the data from the Counter loop into the Logging loop via a Queue (or Stream Channel).

Anyway, before trying to further improve your code, some learning would help to make it a faster journey 🙂

 

0 Kudos
Message 7 of 7
(2,889 Views)