Integer formatting is often found in driver development. Besides transferring the numeric values that the instrument reads, it may also represent the status codes (Boolean values) or error codes returned by the instrument. When writing integer values to or reading them from the instrument, you can use %d format code with length modifiers (h, l, and ll) and the array modifier (,).
Use this modifier for short (16 bit) integers. These are typically used for holding test results and status codes.
This example shows how to scan a self test result (a 16 bit integer) returned from an instrument into a short integer.
/* Self Test */
viPrintf (io, "*TST?\n");
viScanf (io, "%hd", testResult);
/* read test result into short integer */
This example shows how to query the instrument to determine whether it has encountered an error. The error status is returned as a short integer (16 bits).
/* Check Error Status */
viQueryf (io, "*ESR?\n", "%hd", &esr);
/* read status into short integer */
Use this modifier for long (32 bit) integers. These are typically used for data value transfers and error code queries.
This example shows how to scan an error code (a 32 bit integer) returned from an instrument into a 32 bit integer.
/* Error query */
viPrintf (io, ":STAT:ERR?\n");
viScanf (io, "%d", &errCode);
/* read error code into integer */
This example shows how to format the sample count (a 32 bit integer) into the command string sent to an instrument.
/* Send Sample Count */
ViInt32 value = 5000;
viPrintf (io, ":SAMP:COUN %d;", value);