To send binary or hex data, you have to first convert the data to string format, so that it can be passed to VISA, TCP or UDP Write function. Likewise, the string value provided by VISA, TCP or UDP Read can be converted into the desired output format. While those communication functions in require a string value to be used as the data input and output, the character values in a string are not restricted to standard ASCII characters. Each character is an unsigned 8-bit integer (U8), with possible values ranging from 0 to 255.
There are several methods that can be used to transmit binary values, depending on the format of your source data. Below we present some examples using NI-VISA Functions, but the very same concept can also be applied to TCP and UDP:
Transmit constant hexadecimal values, and display received data in HEX format.
The simplest way to transmit a constant hexadecimal (hex) value is to use a string constant, with the constant configured for Hex Display (configurable by right-clicking on the constant and selecting Display Format...). This will allow you to type the hex values of non-ASCII characters in a string control or constant, which can then be passed directly to the VISA Write function. When reading data with VISA Read, the string can be wired directly to a string indicator in hex display mode in order to display the hex values to the front panel.
Transmit & Receive constant Hex values:
Transmit U8 integers (single value or array).
In order to transmit a single byte of data (U8 integer), the Build Array function should be used to form an array with a single element. The Byte Array to String operator can then be used to create a string which is compatible with VISA Write. The same procedure can be used to transmit an array of bytes, with the exception that Build Array is not needed.
Transmit & Receive a single U8 integer:
Transmit & Receive an array of U8 integers:
Transmit a non-U8 value or an array of values.
When the binary data to be transferred is larger than a single byte, it is necessary to first typecast the value or array to a U8 Array, then convert this array to a string which is acceptable to VISA Write. The same operations are performed in reverse order to convert the string acquired from VISA Read into a binary data type. This may be used with single data elements, or with arrays of elements.
Transmit & Receive a multi-byte value:
Note: When working with binary data types larger than one byte (I16, U32, DBL, etc...), the endianness (byte order) of the remote device can become an issue. LabVIEW is natively Big Endian, so communication with Little Endian devices will require changes to the byte ordering of data elements.