Jump to content

Polling text file for changes


Recommended Posts

I have a program that constantly has a text file open and will write to the text file every 2 seconds or so, maybe longer.

I need my labview program to constantly get updates from this file maybe every 400mS, I only want to get the last 2 lines of the file, I am working on some code that semi-works. The problem is sometimes the code will not detect any new data in the file. Also, I am wondering if the other program has the text file open all the time, can Labview open the text-file and read it? As long as I am not writing to the textfile from labview?

Not sure how labview ownership of the file works.

 

The updated information wrote in the file is "Keyboard got triggered key was: ##"

## is some number, and the line ends with a LF character

 

ConstantDataFIle.vi

Link to comment

To the best of my knowledge, LV ownership rules follow the operating system in all instances. You'd have to check your OS vendor for the rules on reading when another process is writing.

 

The "not seeing an update" is likely due to the other process not flushing its write buffer... just because you write to a file does not mean the file on disk actually gets updated. Most OSes will batch up writes to a file, especially if it sees them happening frequently to the same file, and only commit them when some in-memory buffer fills up or if the process explicitly calls some sort of flush command. LabVIEW includes the Flush File function in the palettes for forcing this.

Link to comment
I have a program that constantly has a text file open and will write to the text file every 2 seconds or so, maybe longer.

I need my labview program to constantly get updates from this file maybe every 400mS, I only want to get the last 2 lines of the file, I am working on some code that semi-works. The problem is sometimes the code will not detect any new data in the file. Also, I am wondering if the other program has the text file open all the time, can Labview open the text-file and read it? As long as I am not writing to the textfile from labview?

Not sure how labview ownership of the file works.

 

The updated information wrote in the file is "Keyboard got triggered key was: ##"

## is some number, and the line ends with a LF character

 

Most file systems including the usual ones under Windows know two sets of basic access rights for files. One is the access right which determines if the application has read, write or both access and are usually defined when opening the file. The other are deny rights which specify what the application wants to allow other applications to do with the file while it has it open. When your application is trying to open a file the OS is verifying if the requested access rights will conflict with any defined deny rights by other applications which have the same file opened at the moment. If there is no conflict the open operation is granted, otherwise you get an access denied error.

 

So the first important part is what deny rights the other application defines for the file when it opens it. Since it is writing to the file, it by default denies any other write rights to the file by other applications, but it can also choose to specifically require to deny any and all rights for other applications. There is nothing LabVIEW (or any other application) could do about it, if the other application decides to request exclusive access when opening the file. But if it doesn't request denial of read rights to other applications, then you can open that file with read rights (but usually not for write access) while it is open in a different process/application.

 

The access rights to request are defined in LabVIEW when opening the file with Open/Create/Replace File. This will have implicit deny write access for other applications when the write access right is requested (and may make the Open fail if write access is requested and another application has the file already open for write or explicitedly denied write access for the file). The Advanced File->Deny Access function can be used to change the default deny access rights for a file after opening it. Here you can deny both read and/or write access for other processes independent of the chosen access right when opening the file refnum.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.