What is the data format used by readbinblock and writebinblock functions in Instrument Control Toolbox?

31 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 29 Nov 2021
Edited: MathWorks Support Team on 29 Nov 2021
The data format used by readbinblock and writebinblock functions is IEEE 488.2 definite length arbitrary block response (or program) data.
Note that that the indefinite length arbitrary block response (or program) data is not directly supported, but it can be "manually" decoded/encoded using read or write functions.
Reference:
It is a format used by traditional Test & Measurement instruments for sending arrays of numeric data when the data size is known. For example, this can be an array of numeric values that represents a waveform acquired by an oscilloscope, or a waveform to be output by a function generator.
The data format is described below.
Note that even though the format description is for 8-bit data bytes, it can be used to receive/send arrays of numeric values of other data types (or "precision"); for example int16, single, or double, as these data types can be represented as multiple bytes (2, 4, or 8) for each value. The readbinblock and writebinblock functions automatically convert the numeric values (double, etc.) to/from 8-bit byte data as needed.
#N<D><8-bit data bytes>
  • # is a single "sharp" character, byte decimal value 35
  • N is single non-zero digit, ASCII encoded byte (1-9), decimal value 49-57; represents the number of digits in the data size D
  • <D> are multiple digits (up to 9), ASCII encoded numeric values (0-9), decimal value 48-57; represents the number of bytes in the data block that follows.
  • <8-bit data bytes> multiple 8-bit byte values, decimal value 0-255, in numeric representation (not ASCII encoded)
Example:
Suppose you are receiving an array of 10 byte values [1 2 3 4 5 6 7 8 9 10] sent by an instrument using the IEEE 488.2 definite length arbitrary block response data format.
You can read the data using the readbinblock function:
>> data = readbinblock(t, 'uint8')
data =
1 2 3 4 5 6 7 8 9 10
Or, you could read the same data and decode it "manually" using the read function.
In this case the header is 4 bytes (ASCII #210), and the data is 10 bytes.
>> data = read(t, 14, 'uint8')
data =
1×14 uint8 row vector
35 50 49 48 1 2 3 4 5 6 7 8 9 10
>> char(data(1:4))
ans =
'#210'
>> data(5:end)
ans =
1×10 uint8 row vector
1 2 3 4 5 6 7 8 9 10
This approach can be used for troubleshooting or for reading/writing indefinite length arbitrary block response (or program) data.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!