08-29-2013 04:27 PM
Hi
I'm trying to write a new file every time a boolean true occurs, but I don't know how to do it.
I found the example from Cont Acq Producer Consumer to File.vi, and I cant figure how to change the file path and refnum inside the consumer loop.
Just for reference: I'm trying to write data from a USB-6361 in a new file every time a PPS from a GPS device If someone has a better idea than mine please tell me.
Thanks in advance
08-29-2013 06:47 PM
In your example, you are opening a file ONCE when you application starts with the "Open/Create/Replace File" VI. What you are passing into your producer loop is a reference to this one file.
If you are trying to write to a NEW file each time, you will have to open a reference to a new file every time. You will also need to make sure you close the reference to this file when you are finished writing to it.
The Filename.vi you provided is a step in the correct direction. By using a time stamp, you will create a unique file name for each new file which will prevent you from overwriting any old file. However, your Filename.vi will only create a new filename every second. If you try to create two or more files within one second, you will overwrite the file. You should keep this in mind in relation to how often you anticipate creating files. If you want, you can modify your filename.vi to include miliseconds in the file name.
I have modified your consumer loop to create a new file each time you want to write new data.
08-30-2013 11:37 AM
Thank you so much. Could you please save for Labview 2011?
Actually I'm trying to write one file per second. The file must change every time a Digital signal from a GPS PPS(pulse per second) occur in a digital port.
So I must keep the file open and write to it until the next pulse occurs, close, open a new one, and pass the refnum to the consumer loop again.
I'm noob in Labview, and just figure how to keep another loop running in parallel sending the new filename to the consumer loop. But I don't know how to open and close a file passing and getting back the refnum, evaluating if the time ran (or a PPS ocurs) or not.
Thank you again
08-30-2013 05:37 PM
No problem. I saved it for 2011 below.
Please take a look at the VI and see if that answers your questions.
09-02-2013 06:56 AM
Thank you, but it doesn't answer my question.
In my new test I made a parallel while loop which opens a new file and pass the refnum to the consumer loop. The error is when a new file been closed, and the consumer don't have a file to write.
How do I syncronize both loops to avoid this?
Thanks in advance
09-02-2013 05:03 PM
You have one bad race condition in there. What you need to do is let 1 loop handle the file (the consumer loop in this case). That loop alone should open, close, and write the files.