Keysight VISA.NET Help
Reading IEEE 488.2 Binary Blocks

Reading IEEE 488.2 Binary Blocks

Scanf data to be parsed as an IEEE 488.2 arbitrary block has a format specifier in the following form:

%b%[*][ArraySize][h|l|ll|z|Z]b

Note that the arbitrary block format is such that the parser can distinguish between definite length and indefinite length blocks, so only one format type (%b) is needed for both.

Modifier

Interpretation

Default Functionality

The argument is interpreted as an IEEE 488.2 arbitrary block containing an array of integers or floating point numbers.

flags

*

Controls parsing, as follows:

'*' indicates that the data is to be parsed and skipped - there is no corresponding output argument in the Scanf call.

width

For types e, E and f, the actual number of digits after the decimal point.

For types g and G, the actual number of significant digits.

A hash character (#) may be present in lieu of an integer width modifier, in which case an extra Int32 argument supplies the value.

,[arraySize]

Format an array of integers converted to strings.  If arraySize is specified, it is the maximum number of elements to include in the formatted array.

A hash character (#) may be present in lieu of an integer arraySize modifier, in which case an extra Int32 argument supplies the value.

Length modifiers

H,l,ll,z,Z

Indicates the length of the elements in the binary data portion of the block:

  • No modifier indicates 8-bit integers.
  • 'h' indicates 16-bit integers.
  • 'l' (lowercase 'L') indicates 32-bit integers.
  • 'll' (lowercase 'LL') indicates 64-bit integers.
  • 'z' indicates 32-bit reals in IEEE 754 format.

Note that 'Z', which indicates 64-bit reals in IEEE 754 format, is not supported for IEEE 488.2 blocks at this time. 

All integers are parsed as IEEE blocks in big-endian format.

For Scanf, output array sizes are calculated from the size of the data. For ScanfArray, which is unsafe, the calling program must allocate an array that is guaranteed to be large enough to hold the parsed array.

Size modifiers are required when formatting IEEE blocks. The default is 8-bit integers.

Size modifiers are required when formatting IEEE 488.2 arbitrary blocks and raw binary arrays.  In these cases, the type of the array argument to Scanf that corresponds to the format specifier must match the size modifier.  For example, if the format specifier is "%ly", the corresponding argument must be an array of 32-bit integers.

IEEE 488.2 Binary Block Parsing Code Snippets

Remember that Scanf is reading bytes from the formatted read buffer. The format of IEEE 488.2 arbitrary blocks is documented in the IEEE 488.2 specification, sections 8.7.9 and 8.7.10.  Refer to this documentation for a precise description of what Formatted I/O is reading from the read buffer when parsing IEEE arbitrary blocks.

Note that an IEEE 488.2 indefinite-length arbitrary block includes a terminating newline and end, which causes the buffer to be read from the device to the end of the block and flushed as soon as the block has been successfully read from the Formatted I/O read buffer.

Assume that the io variable is a valid reference to IMessageBasedFormattedIO.

Block of Integers
Copy Code

// The read buffer contains an IEEE definite-length block with 5 16-bit

// integers { 1, 2, 3, 4, 5 }

 

// The block is consumed, and out1 returns { 1, 2, 3, 4, 5 }

Int16[] out1;

io.Scanf("%hb%*T", out out1);

 

Block of Reals
Copy Code

// The read buffer contains an IEEE definite-length block with 5 32-bit

//  floating-point numbers { 1.1, 2.2, 3.3, 4.4, 5.5 }

 

// The block is consumed, and out1 returns { 1.1, 2.2, 3.3, 4.4, 5.5 }

Double[] out1;

io.Scanf("%zb%*T", out out1);

 

Flags
Copy Code

// The read buffer contains an IEEE indefinite-length block with 5 16-bit

//  integers with values { 1, 2, 3, 4, 5 }

 

// The block is consumed, and nothing is returned.

//   A trailing %*T is not needed because indefinite blocks include newline and END.

Double[] out1;

io.Scanf("%*zb", out out1);

Array Size
Copy Code

// The read buffer contains an IEEE indefinite-length block with 5 16-bit

//  integers with values { 1, 2, 3, 4, 5 }

 

// The block is consumed, and out1 returns { 1.0, 2.0, 3.0, 4.0 }

Int16[] out1;

io.Scanf("%*4hb", out out1);

 

// The block is consumed, and out1 returns { 1.0, 2.0, 3.0 }

io.Scanf("%*#hb", new Int32[] { 3 }, out out1);

ScanfArray
Copy Code

// The read buffer contains an IEEE indefinite-length block with 5 16-bit

//   integers with values { 1, 2, 3, 4, 5 }

 

// Returns { 1, 2, 3, 4, 5 } and consumes the buffer.  Memory must be allocated

//   by the calling program.

Int32[10] out1;

io.ScanfArray("%lb", out1);

 

 

 

 


© Keysight Technologies 2015-2025