LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read data from textfile via LabVIEW while writing to it

Hi everybody,

 

I study Technical Physics and I am currently working on my thesis. One of my subtasks is to perform some measurements using a spectrometer and process the results.

 

The acquired data from the spectrometer gets written to a textfile, which has the following structure:

 

[HW-Info]

...

 

[SW-Info]

...

 

[Data]

1   2   3   ...   ...   ...   1023   1024

1   2   3   ...   ...   ...   1023   1024

 

At the moment I am writing the data to the textfile and after finishing the measurement I use LabVIEW to read the data from this file. This is the structure of my VI:

 

1. Open textfile

2. Read first line and write it to string

3. Search string for "[Data]"

4. No match -> read next line from textfile and overwrite string

5. Search string again

6. Repeat 4. & 5.

6. Match -> now read textfile line by line and write each single line to array using "spreadsheet string to array"

7. Repeat "spreadsheet string to array" for each line, while current file position (in byte) < total file size (in byte)

 

This program works fine when executing it after the writing of the textfile finished.

 

The next task is to modify this program to perform simultaneous measurement and data processing. The LabVIEW-program should read data line by line from the textfile, while the C++-program should acquire spectra and write them to the textfile (one spectrum per line). Due to the reason that the reading of one spectrum is a lot faster than the writing of one spectrum (0.8 ms vs. 21.5 ms) there will inescapably be the point where the LabVIEW-VI catches up with the C++-program. As a consequence the while loop of my VI will exit because the "read file" function within the loop will cause a "EOF encountered"-error.

 

Therefore my question is: How can I manage to avoid the abort of the program? Could you give me a possible approach to wait for a new data line to be written when reaching the (temporary) end of the textfile instead of stopping the LabVIEW-program?

 

Thank you very much for your support!

 

Regards from Austria,

Philipp

0 Kudos
Message 1 of 5
(3,604 Views)

Don't allow that specific error to stop your program.  Clear that specific error.  If you get it, allow your code to wait a bit and check the file again to see if new data was added,  (file size, or try reading again and see if you get another error.)

 

Hopefully you've set things up so you aren't getting any file violation errors because your VI is trying to read it while the other program has it open and writing to it.

Message 2 of 5
(3,598 Views)

Thanks for your reply!

 

Unfortunately I am not at the university till Monday to test this approach, but I will keep you informed 😉

0 Kudos
Message 3 of 5
(3,592 Views)

I would also suggest you use the OpenG confuration file VIs, downloadable from VIPM. You can just set the section, and read in all the data in a variant form for processing.

0 Kudos
Message 4 of 5
(3,506 Views)

You could also take a look at this setup: https://decibel.ni.com/content/docs/DOC-41654

 

It uses the FileSystemWatcher class from Windows to alert you to an event within a watched folder. It will tell you when something within a certain directory has changed, alerting you to when you need to read in the new data. After that, you can just do as you normally do, and discard all but the last row of data in your read.

 

You'll need at least LabVIEW 2014 for this to work, unfortunately.

0 Kudos
Message 5 of 5
(3,489 Views)