LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Help Optimizing Code: Reaching 100% buffer when saving data

Solved!
Go to solution

The following VI collects data from 3 sensors. Data from the 3 sensors goes into 3 separate "Write To Measurement" file within the While loop. This is causing the VI to reach 100% buffer and therefore crucial data is lost. If the "Write To Measurement" is removed, buffer stays around 10%. 

Also, I am using TDMS to save faster, but it's still not fast enough. What is a logical approach to saving data fast enough? Typically the files are of 1GB for 5 minute collection for all three sensors.

Below is an image of the location of the "Write To Measurement"

 

Write To Measurement Problem.png

0 Kudos
Message 1 of 12
(3,106 Views)
Solution
Accepted by Joaquinh

Maybe you want to append instead of creating a new file with every write operation if the file already exists (which it does). Look at your file IO express configurations.

 

Saving to file should be done in a parallel asynchronous loop. Use a queue based producer/consumer architecture.

 

(I also don't understand why you have an event structure, but that's a different discussion). Also your various "read/timeout cnts" belong in a feedback nodes or shift registers instead of ping-ponging via value property nodes. Where are their values initialized?

Message 2 of 12
(3,099 Views)

How about use Merge signals and use only one Write to measurement.vi?

 

0 Kudos
Message 3 of 12
(3,089 Views)

altenbach,
- I tried to append, but the value for the buffer was the same. It does help when starting the VI when the file already exists. I will look into the parallel asynchronous loop with a queue. Would it need three different queues? Or would one handle all three signals? The data size is 1x800 for each sensor.


- Event structure is more for the commercialization of the VI.  
- "read/timeout cnts" are initialized at the beginning when the sensors start monitoring.

Valentin87,
The merging was the first thing I did, but there was no difference in performance. Buffer was identical.

0 Kudos
Message 4 of 12
(3,059 Views)

It probably would also help to use low-level file IO. Open the files once before the loop, append inside the loop, and only close the files when done. Still, I would do a parallel loop for the file IO as already suggested.

 


Joaquinh wrote:

- "read/timeout cnts" are initialized at the beginning when the sensors start monitoring.


In any case, you should not use value property nodes here.

 

Also, how many times do you think you need to unbundle the same value? Wouldn't once be enough? (see picture)

 

3xtoomany.png

Message 5 of 12
(3,050 Views)

Another optimization tip:

 

Why do you convert to I32 to do a division by 1M? Why not just convert to a double so the buffer can be reused. Right now you are making an I32 buffer and a Double Buffer, just make it a double initially.

 

mcduff

0 Kudos
Message 6 of 12
(3,039 Views)

mcduff wrote:

Why do you convert to I32 to do a division by 1M?


The data is originally U32 and some values might represent negative I32 values. Need to be careful here...

0 Kudos
Message 7 of 12
(3,031 Views)

@Altenbach

Thanks did not see that.

0 Kudos
Message 8 of 12
(3,027 Views)

0 Kudos
Message 9 of 12
(2,993 Views)

Are you still seeing the error mentioned above? The queue should be able to handle the array you describe. 

 

If you have LabVIEW 2016 or above you can also use channel wires. 

 

Channel Wires
http://www.ni.com/white-paper/53423/en/

Message 10 of 12
(2,977 Views)