07-23-2019 03:20 PM
So I am trying to read a .dat file and output an array of 4byte (32-bit) integers.
My current attempt is to use the Read from binary file. From here I use a StringSubset.vi to remove the first 834 bits as this is non-important information. From here I want to assemble the following string of binary into 4-byte integer values. I am unclear with what sub vi to use after removing the non-important information to convert packets of 4 bytes to numbers.
Any help would be super appreciated.
Solved! Go to Solution.
07-23-2019 03:30 PM
If you have an array of U8, you can type cast into an array of U32. This will naturally use 4 elements of the input array to create 1 element in the output array, with the most significant byte being the one with the lowest array index.
07-23-2019 03:34 PM - edited 07-23-2019 03:34 PM
*.dat is a generic extension and does not tell us anything about the data structure.
Do you have a typical datafile with known data? Please attach it.
After trimming 834 bytes, you might try to "unflatten from string" with a 1D I32 or U32 array as type.
Do you know the byte order? Try big endian and little endian to see which produces a more reasonable output.
07-24-2019 02:17 AM
07-24-2019 02:29 AM - edited 07-24-2019 03:14 AM
The original VI generates a string, so unflatten as suggested seems like a better choice. Easy to change byte order for testing. 😄
07-24-2019 02:38 AM - edited 07-24-2019 02:40 AM
07-24-2019 02:51 AM - edited 07-24-2019 02:52 AM
It might be easier to split the read in several operations. Either first read a chunk of 834 bytes and process it as header or throw it away or just set the File Offset to 834 bytes from the start. Then read the remaining data with Binary Read and the correct data type.
07-24-2019 07:12 AM - edited 07-24-2019 07:13 AM
My initial thoughts match what rolfk stated. Just have the Read Binary File do all of the conversion for you. Just wire an I32 constant to the data type input (on the top of the Read Binary File). You can also supply the byte order just in case the file is using little endian (big endian is the default).
07-24-2019 08:02 AM
Thanks so much alten, that worked out nicely. I can't believe how much trouble I was having with something so simple lol. Have a great day
07-24-2019 08:29 AM
@Jewsus wrote:
Thanks so much alten, that worked out nicely. I can't believe how much trouble I was having with something so simple lol. Have a great day
Who is alten (altenbach I presume)? You selected crossrulz' solution.