Mark Zacharoni Hamilton Posted May 16, 2013 Report Share Posted May 16, 2013 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 Quote Link to comment
Mark Zacharoni Hamilton Posted May 16, 2013 Author Report Share Posted May 16, 2013 Fixed the issue wired RefNum to shift register Quote Link to comment
Aristos Queue Posted May 16, 2013 Report Share Posted May 16, 2013 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. Quote Link to comment
Rolf Kalbermatter Posted May 17, 2013 Report Share Posted May 17, 2013 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. Quote Link to comment
hooovahh Posted May 21, 2013 Report Share Posted May 21, 2013 I know the original issue has been solved but an alternative to polling for changes is using the System.IO.FileSystemWatcher class. http://forums.ni.com/t5/LabVIEW/execute-vi-when-a-certain-file-is-in-a-certain-directory/m-p/397763?view=by_date_ascending#M198073 This VI can be modified to have file changes on a single file. 1 Quote Link to comment
Labview Master Posted May 22, 2013 Report Share Posted May 22, 2013 you'd better write a external dll to do this Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.