From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write to new file inside Producer/Consumer

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

Download All
0 Kudos
Message 1 of 6
(2,510 Views)

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.

0 Kudos
Message 2 of 6
(2,494 Views)

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

0 Kudos
Message 3 of 6
(2,462 Views)

No problem. I saved it for 2011 below. 

 

Please take a look at the VI and see if that answers your questions. 

0 Kudos
Message 4 of 6
(2,444 Views)

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

 

Download All
0 Kudos
Message 5 of 6
(2,413 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 6
(2,376 Views)