02-09-2010 07:09 AM
GPC wrote:... the reading sets the cursor to the beginning of the file and then it reads it all ...
There you would have a race condition. If the write process just happens between setting the file position and reading the file you'll have the new data at the beginning.
Opening and closing the file might cause other problems if you do this at 2 places. Will you open it with r/w access in both places? Then you will get an error the second time you try to do so. This would need to be handled (try again after some time).
You could try opening 2 file refs (one r/w and one r only) for the 2 loops. I don't know exactly how this will work, but the read loop might not see all data unless you flush the file after writing.
02-09-2010 07:45 AM
02-09-2010 08:26 AM
02-09-2010 09:55 AM
If you open the file 2 times only 1 instance can have r/w access. The other just has read access, so you can't mess up.
Stopping the program before closing the file is bad programming, but shouldn't lead to data loss, since the data is either in the buffer to be written to file or already written to file.
The idea was something like this:
- in your loop that writes data, open the file once and keep it open, write to file continuously (probably using Flush File to force the OS to write the data), close the file when the loop terminates
- in your master loop only open the file when you need to read the data. Open the file in read-only mode, read the data, close the file.
You could also create a SubVI with different methods (action engine) which takes care of all the file access. One method would be to open the file. One method to write data to the file, one to read the file contents, one to close the file. Like this you have one central place handling all the file access.
02-10-2010 05:52 AM
02-10-2010 06:15 AM
TerraNova wrote:Hang on, Hang on...
Look at this picture, please.
You only have the correct value of size(s) in the very first iteration.
Regards.
Yes, because you don't rewind the file position. If you keep the file open you need to set the file position to the start in order the read the whole file. Else you just read what has been added since the last read operation.
02-10-2010 06:25 AM
So how, dan_u, You suppose to make it, again?
Please, picture or vi, please.
Regards.
02-10-2010 07:08 AM
In your read loop, just insert the Set File Position primitive to set the file cursor to the start of the file before reading the contents.
02-10-2010 07:14 AM
02-10-2010 07:19 AM
Well, for me it works. The 2 refs don't interfere with each other. LV 8.5.