LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading a binary file with a certain format

I have 1553 data file which is a miltary standard format. It read out time,message counter id,1553 command word and 32 data words. I just tried to read the first word in a read file specifying the first word as a double. The real number should be 142.3341. I am not getting anything like this. Any help would be much appreciated. The total byte count is 80. The following is the format. 1 double, 1 unsigned long, 34 unsigned shorts.
Thanks.
0 Kudos
Message 1 of 6
(3,983 Views)
Check the READ BINARY FILE.vi in the examples.

I think you need to define a cluster, consisting of 1 double, 1 U32, and 34 U16s. You'll have to add those independently - you can't use an array.

Make sure the cluster order is the same as the file order.

Open the file, read the file, and close the file.

Wire that cluster into the READ FILE function as the BYTE STREAM TYPE.

If you leave the COUNT input unwired, what you'll get out is one of those clusters.

(If you wire it, even to 1, you'll get an array of those clusters.)
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 2 of 6
(3,961 Views)
I tried your suggestion and got the same results. Then I had a cohort of mine reverse the byte order of the binary file. In other words the format is Little Endian instead of Big Endian. How do I reverse the order of a binary file in labView so that it can read a Little Endian format.
0 Kudos
Message 3 of 6
(3,939 Views)
Reversing the byte order is easy for an I32,U32,I16, or U16. Use the ADVANCED - DATA MANIPULATION - SPLIT NUMBER to split an I32 or U32 into two 16-bit numbers, and use it again on each to split those into 8-bit numbers. Use JOIN NUMBERS from the same palette to make two 8-bit numbers into a 16-bit, or two 16-bits into a 32-bit.

HOWEVER, having a DBL in there really gums up the works - there are no functions to swap 8-byte DBLs end for end.

For that, here's what I would do:

1...Read the first 8 bytes as a cluster of 8 separate I8s.
2...Unbundle the bytes and rebundle them in the correct order.
3...Typecast that 8-byte cluster into a DBL

You could, in fact, read the whole file as an 80-byte cluster. Unbundle the whole thing into 80 separate bytes. Re-bundle 8 into a cluster (reversing the order), and typecast into a DBL. Rebundle the next four into an U32 (reversing the order). Rebundle the next two into a U16(reversing the order). Etc. Etc.

I'm not sure which method looks cleaner.
Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


LinkedIn

Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 6
(3,930 Views)
Thanks for your suggestion. I implemented your first suggestin using the type cast. I put it in an array and reversed the array. I do feel however that the majority of the binary files that come from windows and linux are little endian and this should prompt the labView development team to have more vis that use big endian format.
0 Kudos
Message 5 of 6
(3,929 Views)
LabVIEW uses Big Endian, because that is what the MacOS uses, and LabVIEW was created first for the Macintosh.

Please also check this example that shows the convertion process:

Writing Binary Files with LabVIEW That Can Be Read by Other Applications
- Philip Courtois, Thinkbot Solutions

Thinkbot Solutions
0 Kudos
Message 6 of 6
(3,915 Views)