LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing and Understanding the Producer/Consumer Template

Solved!
Go to solution

Thanks for updating us on the status of where you currently stand with this project. Just so everyone is on the same page, could you provide us with which error you're getting? Also, have you tried running a simple write to text file example to see if you can get a simple File I/O example working?

Mike B.
Technical Support Engineer
National Instruments
0 Kudos
Message 11 of 25
(2,214 Views)

Hi Mike, 

 

I believe LabVIEW is initializing the Write to Spreadsheet function every time the loop runs and writes over previously saved data. Therefore, I only get one line of data.I am not 100% certain if this is the issue but it is my best guess. I tried using the Set File Position from the Advanced File Functions palette and setting it to "end," but it did not work because the the Write to Text File function is required. I could not get the Write to Text File function to work with non-string data. 

 

The second issue I am having is LabVIEW does not stop running my VI when I press the stop button. 

 

Attached is the my current VI. 

 

Thanks for the help!3.PNG

0 Kudos
Message 12 of 25
(2,202 Views)

It is always a good idea to read the Help and know all of the inputs on the LabVIEW functions you use.  Yes, you are, indeed, creating a new Spreadsheet (of the same name) each time through the loop because the "Append to File" input is left at its default "F" setting.  An uninitialized Shift Register that is set inside the loop to "T" should fix this for you.

 

It's less clear why the program doesn't exit.  You seem to be using a Sentinel correctly to stop the Consumer when the Producer exits.  Can you test which loop(s) do or do not exit?  One way would be to put a probe on each exit Error line and see which one(s) don't have a value.

 

Bob Schor

Message 13 of 25
(2,192 Views)

Bob, 

 

You were right about the “Append to File” being set to False as the default. It is kind of embarrassing I missed that considered I solved this problem with the other “Write to Spreadsheet File” functions in my VI. I am not sure what you meant by the shift register comment though.

 

I figured out why the VI is not exiting when I press the Stop Button. I am reading data at 1000 samples/sec but I am not writing data at 1000 samples/sec. It is similar to your sink and drain analogy you wrote earlier. I am filling up the sink super-fast and the drain cannot keep up. I am confident this is the case, because I ran the VI for 30s and pressed the Stop Button. It took the VI another 4 minutes to finish writing all the data generated in that 30s. After the 4 minutes the VI stopped running. When I opened my text file 30s of data was written to the text file.

 

I think LabVIEW is opening and closing the text file every time it runs, slowing down the VI. I am not sure how to keep a text file open or if this is even the problem. This is just my first guess.

 

Do you have any ideas?

 

THANKS!

 

EDIT: Data could also be stuck in the Queue slowing it down. 

0 Kudos
Message 14 of 25
(2,177 Views)

Is there a reason you're using the deprecated File I/O VIs? These read and write equivalents are not deprecated.  Also, you can review the LabVIEW File I/O examples in the NI Example Finder for how to properly create/open/close file references.

Mike B.
Technical Support Engineer
National Instruments
0 Kudos
Message 15 of 25
(2,162 Views)

@Mike.B wrote:

Is there a reason you're using the deprecated File I/O VIs? These read and write equivalents are not deprecated.  Also, you can review the LabVIEW File I/O examples in the NI Example Finder for how to properly create/open/close file references.


They are not deprecated for him.  He is using LV14.  The newer versions didn't exist yet.

0 Kudos
Message 16 of 25
(2,160 Views)

Remove your calls to the 'write to spreadsheet file.vi' and use the lower level file IO functions - you can use that VI as an example of what to do. Call the open file before your loop, call the write to file in the loop, and close when the loop is done. 

0 Kudos
Message 17 of 25
(2,157 Views)

Here's another Demo that generates 3 2D arrays of simulated sinusoids and writes them as two columns to a CSV (Comma-separated Values) file, which Excel can open (as can Notepad, for that matter).  It uses Consumer/Producer with Sentinels (which I think you know about).  To understand how the file gets written, look carefully at the Help for the Write Spreadsheet (misnomer!) function.

DEMO Write Delimited Spreadsheet.png

Bob Schor

 

P.S. -- I tried to do this in LabVIEW 2014 ...

0 Kudos
Message 18 of 25
(2,148 Views)

Paul, 

 

When you say "use the lower level file IO functions" are you referring to the "Write to Text File" VI? I tried using that VI, but I could not get it to write to a text file, because my data is not a string. I tried converting to a string before writing, but it did not work properly. 

0 Kudos
Message 19 of 25
(2,147 Views)

Yes, you will need to convert your data to a string - open up the VI you are currently using to see how you can do this. What do you mean when you say it didnt work properly? The format wasnt what you want? Didnt write anything? Did you get an error? 

 

Again, you can pretty much just copy the code from inside that write to spreadsheet vi - difference is you will open and close the file outside the loop, the rest of the operations will occur inside the loop. 

0 Kudos
Message 20 of 25
(2,142 Views)