LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Binary File to Array

I need to choose a file with a file chooser and then convert it to an array.  The file is a binary file and I just want every byte out of it as an element in a very large byte array.  Im not quite sure how to go about this, can someone who has done this or knows how guide me in the right direction?
 
When I run the enclosed vi it acts as if the file is not 512 bytes big and says that an EOF has been reached.  Im sure Im just doing it plain wrong tho ;).
 
The zip contains two of the files I wish to read in as well as my poor attempt to read the file into a byte array. The vi has two main problems:
1) It doesn't work
2) It doesn't take into account variably sized files
 
Thanks

Cason Clagg
SwRI
LabView 7.1, Windows XP
0 Kudos
Message 1 of 6
(3,233 Views)
(1) You wire a byte stream type of I32, meaning you read 4x as many bytes as intended.
 
--> solution: right click in the type constant and select Representation:U8.
 
(2) You can get the actual file size e.g. with the eof function.
 
See attached modification (LabVIEW7.1).
 
... and don't forget to close the file when done 😉

Message Edited by altenbach on 07-21-2005 06:16 PM

Message 2 of 6
(3,227 Views)

I must have been tired yesterday, the byte stream type should have been obvious to me.

However I don't think I would have figured out how to determine the size of the file.

Thanks Alten.


Cason Clagg
SwRI
LabView 7.1, Windows XP
0 Kudos
Message 3 of 6
(3,204 Views)
Out of curiosity, what happens if I dont wire the error in/ error outs together? Does it just let the next block know whether or not it needs to try to execute depending on whether or not the previous block passed/failed?

Cason Clagg
SwRI
LabView 7.1, Windows XP
0 Kudos
Message 4 of 6
(3,193 Views)
It does that (what you mentioned) as well as determines order of execution.  Error in/out are generally good to wire as they help the flow of execution.

Essentially, it provides an easy way for you to provide an execution order, in addition to error checking (which I sometimes see as secondary to the order in some of the shipping VIs)
0 Kudos
Message 5 of 6
(3,190 Views)
Here, the order of execution is also enforced by the file refnum, so the error cluster is not needed for that. In general it is always recommended to wire the error clusters. It only takes a few seconds. 😉
 
0 Kudos
Message 6 of 6
(3,186 Views)