LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Save data to one file instead of multiple

Solved!
Go to solution

Before I can give more hints/help, I need to understand your requirements better. As I see in your VI, you set your sampling rate for all channels as 1000 Hz, sampling mode continuous and you did not specify the "samples per channel" at the DAQmx Timing function. Inside the while loop, you use a -1 for the "number of samples per channel" input, so you try to read all available samples.

 

So, as I understand, you want to read and save 1000 samples per channel per every second into files? If this is so, you could just use the DAQmx Configure Logging VI ( http://zone.ni.com/reference/en-XX/help/370469AD-01/lvdaqmx/mxlogging/ ). Note that, you should place this VI before the While loop, and the logging will start when the while loop starts with the DAQmx Read (use the "Log and Read" input for the Config Logging VI). If this is ok for you, this would be the simplest method, as suggested in a previous post.

 

If you want the user decide when the logging starts and the logging rate, you should use a producer/consumer pattern, but keep using TDMS file functions, since TDMS is a very useful way to store multiple channel data...

0 Kudos
Message 11 of 27
(1,119 Views)

Hi Blokk

 

The most important thing is that the user i able to toggle logging on / off. The reason why the sampling rate was set to 1000 was to get a smooth looking chart and the sample should be 1 (not -1) at the specified interval by the user (So one sample every x seconds) or else too much data will be saved. 

 

Greetings

DP

0 Kudos
Message 12 of 27
(1,109 Views)

@DP123 wrote:

Hi Blokk

 

The most important thing is that the user i able to toggle logging on / off. The reason why the sampling rate was set to 1000 was to get a smooth looking chart and the sample should be 1 (not -1) at the specified interval by the user (So one sample every x seconds) or else too much data will be saved. 

 

Greetings

DP


Since you deal with pressure and temperature, I do not think you really need 1000 Hz sampling rate. I would imagine a rate of 10 Hz would be sufficient, and you could average these 10 samples per channel in the Consumer loop before writing to file. I have modified your VI to work in this way. By the way, I think you mixed up some things in your original VI, one example: on the Front Panel you show "Start logging 2" Boolean control under the "Temperature 2" Waveform chart. But you connect the data "Temperature 1" to the File Express VI. Also the same mistake for the "Temperature 1".

What about the Carbonmonoxide signal? Just in case I also included it in the file logging.

Another change is that, the user can change the logging intervals on the fly via the "Log rates" array control.

I have created a LV project, having the main VI and the typdef cluster for data transfer. There is planty of room to improve this VI (like better error handling), please check it if works as required. Note that, I have deleted the serial port code portion, you can add it back to the main VI.

 

Logging af data ved speciferet tidsinterval3_v2_BD.png

0 Kudos
Message 13 of 27
(1,099 Views)

Here is the front panel, and I attached the project in a zip:

 

Logging af data ved speciferet tidsinterval3_v2_FPfcsdds.png

Message 14 of 27
(1,098 Views)

There is a race condition in my code: there is a chance that the VI releases the Queue before Dequeuing the Stop command in the Consumer loop. So modify the VI that the Queue is only released when the Consumer loop stopped:

 

Logging af data ved speciferet tidsinterval3_v2_BDdsdddddddd.png

0 Kudos
Message 15 of 27
(1,094 Views)

Extra info: if you install the TDMS plugin, you can directly open TDMS files into Excel:

http://www.ni.com/example/27944/en/

0 Kudos
Message 16 of 27
(1,091 Views)

Hey Blokk

 

That really looks impressive. I would not have been able to make that myself but I will try to figure out how it works. I am really grateful you are taking your time to help me out! 

 

Yes, you a correct. I mixed the button for the temperaure 1 and 2, but the rest should be fine.

 

When I run the VI it seems like it is not reading the data received from the DAQ properly. I get no values at all from my temperature sensors. I will be able to test the other sensor a little bit later but I guess the outcome probably will be the same. Any idea what might be wrong?

 

 

Greetings 

DP

0 Kudos
Message 17 of 27
(1,087 Views)

@DP123 wrote:

Hey Blokk

 

That really looks impressive. I would not have been able to make that myself but I will try to figure out how it works. I am really grateful you are taking your time to help me out! 

 

When I run the VI it seems like it is not reading the data received from the DAQ properly. I get no values at all from my temperature sensors. I will be able to test the other sensor a little bit later but I guess the outcome probably will be the same. Any idea what might be wrong?

 

 

Greetings 

DP


Did you set a TDMS File path before running the VI? What happens when you stop the VI via the "stop DAQ" button, any error msg? Put an indicator in the Producer loop, and connect the 2D data into it coming from the DAQmx Read. Do you see new values changing at every 1 second? If so, the problem is in the Consumer loop. Also, right click on the output of the iteration terminal (in the FOR loop inside the Case structure in the Consumer loop), and create an indicator: you should see a value of 3 when you run the VI...

Please give feedback what you see after your checked the above things.

0 Kudos
Message 18 of 27
(1,070 Views)

Another thing you need to change! The problem is that, you did not specify file path to record data for the Consumer loop. Do the following:

  1. Go to the Front panel
  2. Right click on the "file path" control
  3. Select "Browse options..."
  4. Selection mode should be: "Files", and "New", not "Existing"!

Now you can specify a path and a file name for the TDMS file BEFORE running the VI, like "Data_1.tdms".

What happens when you try this?

 

fsfgsdfsdfs.png

0 Kudos
Message 19 of 27
(1,066 Views)

You were completely right!

 

I forgot to set the filepath and that was the problem. Everything works like it should :D. I just tested the pressure sensor and it is working like a charm! I really need to understand how this exactly works and hope that you maybe have the time to give me some understanding. I will work with it over the next couple of days and then return with some questions. It just looks wonderful.

 

I have one more little request. I know that you mentioned that I should just put the serial port code back into the main VI but if I want to be able to save the data in the same file just like with the other sensors. Could you maybe help me with that aswell?

 

I did not see your last post before I posted but I found out that I had to change the mode so it creates a new one instead of looking for an existing. 

 

 

Greetings

DP

 

 

0 Kudos
Message 20 of 27
(1,059 Views)