LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write multiple inputs with KHz sampling rate to a file outside the loop?

Solved!
Go to solution

Hi,

 

I am measuring multiple channel voltage inputs using DAQ assistant (1 sample on demand) and it is placed inside a timed loop of 1 KHz rate. 

 

This timed loop is placed inside another while loop.

 

Issue is with writing the data to a file, Although I can see 100 samples in 100 ms in the graphs wired to the the channel outputs but the write measurement output file either stores only 19 to 20 samples per second (when it writes inside the timed while loop) or does not store at all (if placed outside the inner timed  loop).

 

I have tried to implement producer consumer structure but in the consumer loop I cannot write the queued data to a file saying datatype mismatch. I have placed the start queue element and consumer loop outside both the loops and the enqueue element inside the timed loop with DAQ output fed in to the enqueue element.

 

Can you please help me solving this writing to file problem?

 

 

0 Kudos
Message 1 of 9
(4,182 Views)

There are a lot of issues. First, before addressing functionality, why have you made the diagram so large? Even on a 21" monitor I have to scroll in both directions to see the diagram, which is considered bad style, particularly as it is mostly empty.

 

Why do you have the timed loop within another loop, which is set (by wiring a boolean constant to the loop's stop node) to run once? The bottom most loop will not execute until the top, outer most loop stops, because, LabVIEW being a dataflow language, it won't have the queue reference or error cluster created in the outer loop until the outer loop stops. In the timed loop the "enqueue rate" has no meaning, the loop executes at whatever the timing is set at. In the bottom loop, if it could execute, it doesn't need the "Dequeue speed" as that loop will only execute when there is data present on the queue, the time out for the dequeue is at -1, which means never time out. Too many other issues to deal with at this time.

 

What are you trying to achieve with the feedback nodes at the left side of the timed loop? Create your queue using a constant of the type of data it is to carry, pass the resulting queue reference to where it is needed. Data inside a loop will not exit the loop by wires until the loop is stopped. Your data type input to the "obtain queue" won't get the data type from within the loop until the loop is stopped.

 

Neatness does count, it is very hard to follow someone's code when wires are led from outputs on the right back to inputs on the left. Also, unnecessary bends do not help as well.

Putnam
Certified LabVIEW Developer

Senior Test Engineer North Shore Technology, Inc.
Currently using LV 2012-LabVIEW 2018, RT8.5


LabVIEW Champion



0 Kudos
Message 2 of 9
(4,163 Views)

I am sorry about the mess, actually I have not written this, it was written before and I also don't understand the function of the outer loop. I did not change it because it is programmed to move the piston to and fro between a maximum and minimum point which is critical. Also I didn't create the feedback nodes on the left, when I tried to wire to the queue element it was automatically formed.

 

I will try clean the vi as much as possible and will post it soon. Meanwhile what I wanted to know is the seeing the structure of the VI, a loop, inside that a timed loop, inside that a DAQ measurement taking place, multiple channel inputs---  in this situation how can I write the input data to a file at 1KhZ ? (Ignore whatever queueing I have done, it is probably wrong). Is the solution using queue element? If so where to place the queue elements.

 

I will post a cleaner VI soon.

 

Thank you

0 Kudos
Message 3 of 9
(4,153 Views)

This is a cleaner VI, not smaller though,  tried to place queue elements outside the loop, define data type, all the wires are connected, still there are errors. Please suggest what is wrong in the queueing structure?

0 Kudos
Message 4 of 9
(4,143 Views)

This one is much cleaner.

 

And what errors are you getting now?

0 Kudos
Message 5 of 9
(4,133 Views)

There was a wire broken in the previous VI, I have corrected it in the attached VI. Now the VI runs there is no error but the purpose is not served. So I wanted to write the measurement file at the same rate at which I sampled the analog input  which is 1Khz. But even after doing queue element in the present VI the output of the dequeue element only writes 21 samples per second to the output data file? Why is it not able to write to file at 1 Khz.

0 Kudos
Message 6 of 9
(4,129 Views)

Please help anybody...

0 Kudos
Message 7 of 9
(4,102 Views)
Solution
Accepted by topic author Sayantan

I haven't looked at the code so writing from the top of the head, but file access is slow, and if you open and close the file it's quite slow. What you usually do it write to file at a slower pace, e.g. once per sec and write all 1k samples at once. Try that, and also keep file ref open during the test.

 

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 8 of 9
(4,089 Views)

Actually I did kind of a similar thing by myself today morning, but thank you for your idea.

0 Kudos
Message 9 of 9
(4,064 Views)