LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to search and parse a binary file?

I need to search binary files for specific data messages.  These messages begin with "11111111" then follow with some more 8 bit words, one of which defines the length of the following data bits.  I am experienced with LabView but not with using binary files.  There may be several of these complete "messages" within a single data file.  How would I create a simple reading VI for this?

 

Appreciate the help!

0 Kudos
Message 1 of 7
(5,555 Views)

This 11111111 is a sequence that looks like an integer number of bytes (1 to 8), depending on data format you have written them. 

 

Convert 11111111 to string (1 to 8 elements), read binary data from file into string, search this pattern in read data, format data after pattern as needed. If the file is too large, you can read portions of file.

 

If this file is a bit sequence and pattern has non-integer byte offset, it is more complicated. 

LabVIEW stores boolean arrays 1 byte per element so it does not make sence to work with true bit patterns. I would say - read data as u8, convert each one into 8 bits thenconvert bits into strings (1 string byte per original bit) and search string as previously.

0 Kudos
Message 2 of 7
(5,545 Views)

That sounds promising.  Could you send a picture of how I would create that in Labview?  Or the VI?

 

Thanks!

0 Kudos
Message 3 of 7
(5,535 Views)

What part is not clear?

Work with file:

Open file -> [Set File position  ->] Read from binary file -> Close file

 

Make pattern string from bit array:

Boolean array to number -> build array -> byte array to string

 

Work with string:

Search string, string subset (or match pattern)

0 Kudos
Message 4 of 7
(5,524 Views)

@Gumborg wrote:

I need to search binary files for specific data messages.  These messages begin with "11111111" then follow with some more 8 bit words, one of which defines the length of the following data bits.  I am experienced with LabView but not with using binary files.  There may be several of these complete "messages" within a single data file.  How would I create a simple reading VI for this?

 


You need to be significantly more clear.

 

"What is "11111111"?

Is it a sequence of 8 bytes, each containing a decimal U8 value of  49 (ASCII for "1") or is it a single byte corresponging to a value of 255?

 

Can you attach a simple file for testing?

0 Kudos
Message 5 of 7
(5,496 Views)

I don't have an example file with me from this pc.  The value of all ones is the bits (0 or 1) which are set to 8 "1"s in a row to signify new data follows.

 

0 Kudos
Message 6 of 7
(5,413 Views)
  • OK, unless the file is gigantic, read the entire contents into a raw string (e.g. don't convert EOL, of course!). Then you can use string functions to look for patterns.
  • You could even create a 1D array of strings each containing a dataset between delimiters by using "scan strings for tokens" in a loop and using 0xFF as the only delimiter.
  • Alternatively you could read it as a U8 array, then use search array to search for a value of 255. 

 

0 Kudos
Message 7 of 7
(5,407 Views)