LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

read the same text file in real time

Hello,

 

I need to read the same text file for real time control.

 

First, I save the data to a text file through image processing in c++.

At the same time, I am trying to read the file in LabView and get the value.

I used while-loop for reading the text file, but it only runs once and it ends.

How can I keep reading the same file?

 

(Only one value is continuously updated in the text file. By erasing and saving new)

 

0 Kudos
Message 1 of 4
(870 Views)

It sounds like you are writing to a single file, over and over again in C++, and expecting that LabVIEW will be able to open the file once (which is all that your program shows) and, by repeated readings (which should "advance it through the file") be able to detect that the file was closed and re-written!  That's not going to work.

 

Using a file to pass data between programs is very slow and inefficient.  How will the Writer know when the Reader has read?  How will the Reader know when the Writer has "new data"?

 

If you must do it this way (perhaps because you don't know about passing data through Network protocols such as TCP/IP), here's one (slow, but safer) way to do it --

  1. The Writer (C++) makes sure there is no pre-existing Data File (I'll call it "My Data.dat") present.  If this is the first time it runs, it deletes any such file it finds.
  2. The Writer writes data to My Data.dat and closes the File.
  3. The Reader (LabVIEW, which should be started after the Writer) looks for a file called "My Data.dat", waiting for it to appear.
  4. When the Reader sees the file, it opens it, reads the data, then closes and deletes the File.
  5. The Writer checks (in a loop) to see if My Data.dat has been deleted (which means that the Reader has read it).  If so, it goes back to Step 2.
  6. To end this process, the Writer writes a "Sentinel Record", putting a special message in My Data.dat that says "This is the last one I'm going to send you, so don't look for any more from me".

Bob Schor

0 Kudos
Message 2 of 4
(849 Views)

Can't I repeat "opening the file" by using while loop?

C++ keeps saving files with the same name.

I want Labview to open the file again and again regardless of the save speed of c++.

0 Kudos
Message 3 of 4
(840 Views)

@wlwl wrote:

Can't I repeat "opening the file" by using while loop?

C++ keeps saving files with the same name.

I want Labview to open the file again and again regardless of the save speed of c++.


Sure, you can do that, but then the Open, Read, and Close all need to be in the While Loop.  You also need to think what might happen to the C++ program if it tries to write to the file while LabVIEW has it open, which is why I suggested some form of "communication" between the two routines to prevent this.

 

Bob Schor

0 Kudos
Message 4 of 4
(782 Views)