From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reading bytes from a binary file directly, what format specifier

Solved!
Go to solution

The function "Read from Binary File"   has a datatype specifier.

 

I want to read the file into a byte array.  What should I put in the data type string.

I could not find a format specifier for byte.  

 

The help says

""

data type sets the type of data the function uses to read from the binary file. The function interprets the data starting at the current file position to be count instances of data type. If the type is an array, string, or cluster containing an array or string, the function assumes that each instance of that data type contains size information. If an instance does not include size information, the function misinterprets the data. If LabVIEW determines that the data does not match the type, it sets data to the default for the specified type and returns an error.""

 

Thanks

0 Kudos
Message 1 of 8
(4,098 Views)
Solution
Accepted by topic author snarkysparky

Hi sparky,

 

when you want to read U8 values you need to define the datatype as U8:

check.png

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 8
(4,091 Views)

Read it as U8.

Read Binary.png

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 3 of 8
(4,087 Views)

Binary data, by its very nature, does not have a "format". (A format defines the translation between binary data and an approximation using printable characters and decimal delimiters and such.)

 

By default, binary data is read as string and that's why the default type is a string. Byte arrays and strings are basically the same and what you chose depends on what you need to do with it later. It is also trivial to convert between the two. Type can be anything and the value wired does not matter. It could be a complicated cluster if the binary file happens to contain an array of such clusters.

 

Also note that in Yamaeda's code, the "close file" is only needed if you wire a file reference instead of a path to the input or if you wire something to the ref out. If not, "close" happens automatically and there is no need to wire it.

 

0 Kudos
Message 4 of 8
(4,063 Views)

Is datatype a string specifying the data type.   Looks that way to me but your

example is colored for integer I think.

 

How do I make it U8  datatype.

 

Thanks

0 Kudos
Message 5 of 8
(4,059 Views)

I inserted a numeric constant and cast it to U8 and then put that into the datatype terminal.

 

Is that OK 

 

Thanks

0 Kudos
Message 6 of 8
(4,058 Views)

@snarkysparky wrote:

I inserted a numeric constant and cast it to U8 and then put that into the datatype terminal.

 


The "value" is completely irrelevant. All that matters is the datatype. A U8 diagram constant is perfectly sufficient as already shown by others above (telling the function that the binary data should be interpreted as a U8 array). If you add convoluted code to generate a U8, that's up to you but just clutters the diagram and confuses other programmers. Keep it simple! Just right-click your numeric constant and set the representation to U8. No need for any casting.

0 Kudos
Message 7 of 8
(4,052 Views)

Now see that's why I should have had the class.  I had never looked at the "representation" submenu for an numeric constant.

 

Thanks

 

All the replies were the solution but I think I will check the first one.

0 Kudos
Message 8 of 8
(4,040 Views)