07-26-2013 03:10 PM - edited 07-26-2013 03:15 PM
I am having trouble when writing data to a file. About 10 seconds into the saving process, I get the error 200279. I have done some research on the topic, but am unable to corect my code. I believe I do not want to increase the buffer size, but would rather, I assume, read the data more frequently. The way I save my file is, before running the VI, I assign a location and name of the file (e.g. data.csv). The date and time is appended to the end of the actual file when the I begin to save the data (e.g. data_07-26-13_122615.csv). If the file does not exist, it creates a new file, then appends data to that file after every loop iteration. The reason I did it this way was so I do not have to worry about running out of memory, but apparently my code is flawed.
I will include a copy of the flawed section of my code. Any help would be greatly appreciated.
Thanks.
Solved! Go to Solution.
07-26-2013
03:22 PM
- last edited on
05-05-2025
09:20 AM
by
Content Cleaner
Your problem is that writing to disk is slow. It is slow enough that it is causing your DAQ buffer to overflow and cause the error and loss of data. What you need to do is implement a Producer/Consumer. This will put the daq and the logging to disk in seperate loops. This will allow the DAQ to run at the speed it needs to keep up with incoming samples and the writing to disk can run at whatever rate it can. You send the DAQ data to the logging loop using a queue.
You might also want to think about changing how you write to the file. That VI is constantly opening and closing the file, which is a very slow process if you are doing it inside of a loop.
07-28-2013 10:54 PM
To expand on what has already been said, everything in your code is being done in the most inefficient way possible. For example, in addition to the file write already mentioned, you are using express VIs which are equally inefficient. You are also generating a new path with every iteration of the loop, even when the value isn't being used. Also lose the local variables. Learning about event-driven programming will also help a lot.
You are also using a boolean value where you should have an enum with two values (pause and continue).
Mike...
07-29-2013
12:01 AM
- last edited on
05-05-2025
09:21 AM
by
Content Cleaner
@mikeporter wrote:
You are also using a boolean value where you should have an enum with two values (pause and continue).
Hello Mike,
This particular point isn't clear... If we consider to use an enum (U8 type) or a boolean, LabVIEW stores Boolean data as 8-bit values and I'm not sure about enum (U8), certainly it should be more than 8-bit (to store the string labels)..
What you say??
07-29-2013 06:03 AM - edited 07-29-2013 06:07 AM
I guess I could have been clearer that the last point wasn't about code efficiency but rather readability and maintainability.
Booleans are correctly used to represent values that are inherently binary; things that can answer questions like yes/no, on/off, true/false. The control in question has two values (or at least is does for now) but there is no inherent logical mapping between true/false and pause/continue. Consequently you have to remember what the mapping is - or if you are inheriting the code - hope whoever wrote it, documented it somewhere.
In addition, what happens if in the future this value changes to pause/continue/stop or pause/continue/stop/pause-on-error. Now you have to change this VI and everything that calls it, because you have to change the datatype of the input.
Mike...
07-29-2013 09:44 AM - edited 07-29-2013 09:51 AM
Thanks everyone for your input and help. This is the first labview program I have written, so I am a complete amateur. And I am finding it somewhat difficult to write labview code that behaves appropriately.
I have been attempting to write what crossrulz suggested by implementing a producer/consumer, though am having trouble. I guess I am just somewhat ignorant on the capabilities of the many functions provided. Can anyone explain how I would go about setting up two differing loops for the logging and the DAQ? How would I setup a queue which will integrate the two? When dequeueing data, does the differing timing rates of data being produced and data being logged affect the queue? Should I store the data in the queue until the queue reaches a certain predetermined size, then log and pop off all elements in the queue, then repeat?
I apologize for all the questions, but I am not too familiar with coding with block diagrams.
Thanks again for all the help.