Accessing Attributes

NI-VISA

Accessing Attributes

VISA uses two operations for obtaining and setting parameters—viGetAttribute() and viSetAttribute(). Attributes not only describe the state of the device, but also the method of communication with the device.

For example, you could use the following code to obtain the logical address of a VXI address:

status = viGetAttribute(instr, VI_ATTR_VXI_LA, &Laddr);

and the variable Laddr would contain the device's address. If you want to set an attribute, such as the baud rate of an ASRL session, you could use:

status = viSetAttribute(instr, VI_ATTR_ASRL_BAUD, 9600);

Notice that some attributes are read-only, such as logical address, while others are read/write attributes, such as the baud rate. Also, some attributes apply only to certain types of sessions; VI_ATTR_VXI_LA would not exist for an ASRL session. If you attempted to use it, the status parameter would return with the code VI_ERROR_NSUP_ATTR. Finally, the data types of some attribute values are different from each other. Using the above examples, the logical address is a 16-bit value, whereas the baud rate is a 32-bit value. It is particularly important to use variables of the correct data type in viGetAttribute().

Refer to Attributes for a list of all available attributes you can use for each supported interface.