From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can a binary file be read incrementally?

I have a situation where I would like to do repeated incremental reads (i.e., N bytes at a time) from a binary file. My understanding of the Read Binary File VI is that you open the file, read N bytes from the file, and close the file - i.e., do a SINGLE read. I don't want to read the WHOLE file into memory at one gulp; I want to keep repeating the N-byte read operation in an indefinite loop, until I say to stop. On each read I will be updating a graph with the last data read.
 
(OK, some more detail: I am monitoring 32 digital lines using some external equipment that writes the file. Each time one of the digital lines changes value, 10 bytes are written: a 48-bit timestamp and 32 bits for the current digital values. The file is a continuous little-endian raw concatenation of these 10-byte records, with no header or record markers. In LV 8.21 (under WinXP) I want to generate a scrollable display of the 32 digital traces, by reading a block of data as needed whenever I want to advance the display.)
 
What is the suggested way to handle this kind of binary reading? (I am willing to write C code if necessary.) Any useful responses will be appreciated.
 
dhfx
 
 
 
0 Kudos
Message 1 of 14
(3,284 Views)
If you don't close the file, then you can continue to read the file.  Depending on your LV version the process changes slightly, but basically, use the Open FIle, then Read or Read from Binary File to get the data you want.  If you leave the file open, then you can do another read, and LV will keep track of your position in the file.  Now of course, this assumes that both programs can coexist with the file being open by someone else.
Message 2 of 14
(3,262 Views)

This may be lower level than you were looking for.  As already mentioned, the big problem may be having two applications accessing the file simultaneously.

Jim

 

Jim

LV 2020
Message 3 of 14
(3,257 Views)
Thanks for the responses so far. I realize that I could also use positioning to move forward or backward in the file, as well as reading consecutive data on successive reads.
 
Can anyone point me to some good examples for doing what I'm talking about?
 
- dhfx
 
0 Kudos
Message 4 of 14
(3,204 Views)
Just use "set file position" first to start reading at a specific location.
0 Kudos
Message 5 of 14
(3,192 Views)

I have the same problem, has this been solved?

I've tried a combination of Open File, Set File Position and Read from Binary File, but there are permission and other issues.

0 Kudos
Message 6 of 14
(2,238 Views)

You just revived an ancient thread!

 

What are the permission issues? Is the file already open elsewhere?  Can you elaborate on "other issues"?

 

We need significantly more detail. Show us some code!

0 Kudos
Message 7 of 14
(2,229 Views)

I've attached a stripped-down program. I managed to fix the file permission, but it still doesn't do what I want it to, which is to show me different frames in a raw video. It's not letting me attach a data file unfortunately, but when I run it I get different values for the two refnums, so I think it's setting the file position in the first frame of the stacked sequence and then opening a new file in the second one in every iteration of the while loop.

Download All
0 Kudos
Message 8 of 14
(2,200 Views)

ayscr,

 

You're opening the file and setting the position in the first frame, but you're not using that refnum for the read. Get rid of the stacked sequence and use the refnum from the file you just opened to feed to Read from Binary File. Also, use shift registers or a feedback node to hold your refnum until the next iteration instead of using a local variable. Open and close the file outside the loop. I've attached an update of your stripped down program as an example.

Message 9 of 14
(2,180 Views)

Hi johntrich,

 

Would you mind posting pictures of your code? I have an older version of Labview (2011) and can't open this.

 

P.S.: It sounds like your version of Labview allows you to feed a refnum into the Read From Binary File function, which mine doesn't - I think this might be the problem for me, but I can't update it.

0 Kudos
Message 10 of 14
(2,168 Views)