05-03-2016 10:08 AM
I wonder if i read the binary file in a while loop by chunks of 20 bytes - the file increments its position or always reads from the start?
05-03-2016 10:43 AM
The way you've set up the code in the image, it will always restart at the beginning, because you are re-opening the file each iteration of the while loop (and closing it again after the read, although that happens implicitly). You should open the file once, outside the while loop, and keep the file reference in a shift register. Close the file after the while loop ends. Inside the loop, read from the file. That way, the position mark will increment on each read.
05-03-2016 10:43 AM
When you use only read function, it opens file, reads from start, closes file.
If you manually Open file and connect file refnum to read, next read will continue from the last position (until you use file close). You can also manually offset current position with Advanced file functions -> Set position.
When you start working with advanced file funcitons, it is better to normally stop vi, not abort it in case of errors. LabVIEW will try to release file lock when closed, but do you need extra source of possible errors?
So, while debugging read fixed number of times (for loop, not while loop), add OR with error to abort while loop, do not use strict comparison (what if your file size is not a multiple of 20 bytes?)
05-03-2016 11:39 AM - edited 05-03-2016 11:40 AM
To give a little more details, you should have a setup like this: Open the file before the loop, close the loop after the loop, and read as much as you want inside of the loop. In this way, the file pointer will always be the next set that you need to read.
05-03-2016 12:16 PM
Thank you guys for your help.