05-16-2017 08:39 AM
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:
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!
05-16-2017 08:45 AM
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.
05-16-2017 09:48 AM
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
05-16-2017 09:53 AM
@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