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.
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.
03-13-2019 10:27 AM
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 |
Solved! Go to Solution.
03-13-2019 10:44 AM
03-13-2019 10:49 AM
Read it as U8.
/Y
03-13-2019 11:34 AM
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.
03-13-2019 11:54 AM
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
03-13-2019 11:57 AM
I inserted a numeric constant and cast it to U8 and then put that into the datatype terminal.
Is that OK
Thanks
03-13-2019 12:13 PM
@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.
03-13-2019 12:34 PM
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.