LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read from binary file into a cluster array

Hi everyone

I need help with reading the contents of a binary file into an array of clusters . Now this cluster has 5 members that have datatype u32 and a FIXED SIZE array of u8(SIZE of Array is 64).
There are so many thoughts on related queries, I thought if I can get specific I will get help on what is best for my case .
Also fixed size of the array is something about which I am concerned.
Thanking you all in anticipation.

Sumit
0 Kudos
Message 1 of 11
(5,464 Views)


@sumitrishi wrote:
Hi everyone

I need help with reading the contents of a binary file into an array of clusters . Now this cluster has 5 members that have datatype u32 and a FIXED SIZE array of u8(SIZE of Array is 64).
There are so many thoughts on related queries, I thought if I can get specific I will get help on what is best for my case .
Also fixed size of the array is something about which I am concerned.
Thanking you all in anticipation.

Sumit




Best would be to create a VI which reads one record a time. First use a Read File node with the "byte stream type" input wired with an U32 constant and the "count" input with a constant 5. Depending what application wrote these data files you may have to pass the resulting U32 array trough the "Swap Bytes" and "Swap Words" function. LabVIEW always assumes that data is written in Big Endian format. If the application which wrote the file is a DOS or Windows app it is likely that the data is saved in Little Endian format.

A second Read File function with "byte stream type" input wired with an U8 constant and the "count" input with a constant 64 will read the fixed array.

Now just combine those two resulting wires into a LabVIEW cluster in whatever way you wish and then call this function in a loop to read all your records.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 11
(5,432 Views)
Thanks Rolf!

I think that is what I have been thinking of doing but was hoping there was an easier way something like a type cast being able to accept this cluster of mine.
Because I had diluted my problem to make it more easier for all to understand .
I actually have 25 members in cluster first 23 are u16(17 in number) and u32(6 in number) jumbled
and then 24th member is an array of u8 of size 64.
and 25th is the u16 member.
I am taking care of the little<> big endian conversions.

Thanks
Sumit
0 Kudos
Message 3 of 11
(5,424 Views)
Hi Sumitrishi!

I'm attaching a VI (written in LV 7.1) that does what you are referring to! In this VI, I create some sample data (according to your specs), convert it to binary data, and reconverts it back to the original data type. The main functions used are Flatten to String & Unflatten to String.

Hope this helps!

Travis H.
National Instruments
Travis H.
LabVIEW R&D
National Instruments
Message 4 of 11
(5,421 Views)
Thanks Travis.


I am using LV 6.1 . Does this VI uses features from 7.1 which are new ? If it does not can you please convert it into 6.1 and share it with me .

Thanks again ,
Sumit
0 Kudos
Message 5 of 11
(5,415 Views)
Hi Sumitrishi!

No, this VI doesn't use anything native to LV 7.1. I've converted it to a LV 6.1 VI and attached it below.

Hope this helps!

Travis H.
National Instruments
Travis H.
LabVIEW R&D
National Instruments
0 Kudos
Message 6 of 11
(5,397 Views)
Thanks for the help but according to my problem the first flatten to string is getting binary string/value (which in turn is being read from a file ). In your case flatten to string is getting an array of clusters.
With my case the unflatten from string gives an error.

Sumit
0 Kudos
Message 7 of 11
(5,392 Views)
Here is the VI that shows what I meant by my previous posting.

Thanks
Sumit
0 Kudos
Message 8 of 11
(5,391 Views)
Check this out. Adapt to cluster type to whatever you need.

Rolf Kalbermatter
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 9 of 11
(5,383 Views)
Thanks Rolf will try this approach.

Sumit
0 Kudos
Message 10 of 11
(5,378 Views)