Integers

NI-VISA

Integers

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 and l) and the array modifier (,).

Short Integer—"%hd"

Use this modifier for short (16 bit) integers. These are typically used for holding test results and status codes.

Examples

This example shows how to scan a self test result (a 16 bit integer) returned from an instrument into a short integer.

/* Self Test */
ViInt16 testResult;
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 */
ViInt16 esr;
viQueryf (io, "*ESR?\n", "%hd", &esr);
/* read status into short integer */

Long Integer—"%ld", "%d"

Use this modifier for long (32 bit) integers. These are typically used for data value transfers and error code queries.

Examples

This example shows how to scan an error code (a 32 bit integer) returned from an instrument into a 32 bit integer.

/* Error query */
ViInt32 errCode;
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);