LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

[LV] "Read from Binary File" truncates

hello!

While programming my application in LV, I've run into an unexpected behavior of the "Read from Binary File" block: if I try to read a file as array of U32 (I need to handle it as array of U32 to send it through a DMA FIFO) and the file is not perfectly aligned on 4 bytes (32 bits) the last bytes are truncated. I was expecting to have one more element padded with 0s instead.

See the code snippet:

ReadBinaryFile.png

 

Is there a way to NOT leave behind that very last chunk? I'd like not to read the whole file as U8s and then join them into U32s because I need to handle large files.

 

TY!

0 Kudos
Message 1 of 4
(2,647 Views)

From the LabVIEW help "Read from Binary File", parameter "data type":

If the type is an array, string, or cluster containing an array or string, the function assumes that each instance of that data type contains size information. If an instance does not include size information, the function misinterprets the data.

Please verify that you are NOT running into this issue.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 2 of 4
(2,641 Views)

If your file size is not 0 mod 4, then it is "mal-formed" and you'll get an error.  So you could do the following:  use Get File Size, do an Integer Divide by 4, and tell the Read Binary to read that many U32's from the file.  You can even test that the Remainder is 0 (file OK) or not (mal-formed file).

 

Bob Schor

0 Kudos
Message 3 of 4
(2,607 Views)

@Bob_Schor wrote:

If your file size is not 0 mod 4, then it is "mal-formed" and you'll get an error.  So you could do the following:  use Get File Size, do an Integer Divide by 4, and tell the Read Binary to read that many U32's from the file.  You can even test that the Remainder is 0 (file OK) or not (mal-formed file).

 

Bob Schor


I think that will give the same results as mapping the file as an I32. If they want the fragments, map the file as U8 and then regroup the data and handle the odds and ends at the trailing end as needed to pack it into a I32.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 4 of 4
(2,605 Views)