03-12-2013 12:46 PM - edited 03-12-2013 12:54 PM
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?
Solved! Go to Solution.
03-12-2013 01:38 PM
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.
03-12-2013 01:59 PM
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
03-12-2013 03:19 PM
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?
03-12-2013 03:58 PM
This one is much cleaner.
And what errors are you getting now?
03-12-2013 04:26 PM
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.
03-12-2013 08:11 PM
Please help anybody...
03-13-2013 05:33 AM
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
03-13-2013 11:27 PM
Actually I did kind of a similar thing by myself today morning, but thank you for your idea.