LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read binary file by chunks

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?

Download All
Message 1 of 5
(4,345 Views)

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.

Message 2 of 5
(4,326 Views)

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?)

Message 3 of 5
(4,325 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 4 of 5
(4,304 Views)

Thank you guys for your help.

0 Kudos
Message 5 of 5
(4,292 Views)