Default vs. Configured Communication Settings

NI-VISA

Default vs. Configured Communication Settings

When you open a Serial port, the VISA specification defines the default communication settings to be 9600 baud, 8 data bits, 1 stop bit, no parity, and no flow control. If you have configured the settings to a different value in the NI-VISA configuration utility (MAX on Windows, visaconf on UNIX), then you must pass the value VI_LOAD_CONFIG (4) as the AccessMode parameter to viOpen(). This parameter will cause the configured settings to be used; otherwise, if the AccessMode is 0 or VI_NULL, the default settings will be used.

Most Serial devices allow you to set the communication settings parameters via either DIP switches or via front panel selectors. If you are not using the NI-VISA configuration as discussed above, be sure to use viSetAttribute() to make these attribute values consistent with your device settings:

  • VI_ATTR_ASRL_BAUD sets the baud rate. Defaults to 9600. The range depends on the serial port's capabilities and is platform dependent. For example, most but not all systems support 115200 baud.
  • VI_ATTR_ASRL_DATA_BITS sets the number of data bits. Defaults to 8. The range is from 5–8.
  • VI_ATTR_ASRL_PARITY sets the parity. Defaults to VI_ASRL_PAR_NONE (0). You can also choose odd, even, mark, or space.
  • VI_ATTR_ASRL_STOP_BITS sets the number of stop bits. Defaults to VI_ASRL_STOP_ONE (10). Other valid values are VI_ASRL_STOP_ONE5 (15) and VI_ASRL_STOP_TWO (20). Note that 1.5 stop bits is not supported on all systems and is also not supported in all combinations with other settings.
  • VI_ATTR_ASRL_FLOW_CNTRL sets the method for limiting overflow on transfers between the devices. Defaults to VI_ASRL_FLOW_NONE (no flow control). You can also choose between XON/XOFF software flow control, RTS/CTS hardware flow control, and on supported systems, DTR/DSR hardware flow control.

Other common (but not all) ASRL INSTR attributes are as follows:

  • VI_ATTR_ASRL_END_IN defines the method of terminating reads. Defaults to VI_ASRL_END_TERMCHAR. This means that the read operation will stop whenever the character specified by VI_ATTR_TERMCHAR is encountered, regardless of the state of VI_ATTR_TERMCHAR_EN. To perform binary transfers (and to prevent VISA from stopping reads on the termination character) set this attribute to VI_ASRL_END_NONE.
  • VI_ATTR_ASRL_END_OUT defines the method of terminating writes. Defaults to VI_ASRL_END_NONE. (This value means that the setting of VI_ATTR_SEND_EN is irrelevant.) To have VISA automatically append a termination character to each write operation, set this attribute to VI_ASRL_END_TERMCHAR. To have VISA automatically send a break condition after each write operation, set this attribute to VI_ASRL_END_BREAK.
  • If the serial port is RS-485, then you can query and manipulate the attribute VI_ATTR_ASRL_WIRE_MODE, which designates the RS-485 wiring mode. This attribute can have the values VI_ASRL_WIRE4 (0, uses 4-wire mode), VI_ASRL_WIRE2_DTR_ECHO (1, uses 2-wire DTR mode controlled with echo), VI_ASRL_WIRE2_DTR_CTRL (2, uses 2-wire DTR mode controlled without echo), and VI_ASRL_WIRE2_AUTO (3, uses 2-wire auto mode controlled with TXRDY). This attribute is not supported for RS-232 ports. It is valid only on the platforms on which National Instruments supports RS-485 products.

For lower-level functionality, you can also query the state of each modem line via viGetAttribute(). VISA will return whether the given line state is asserted (1), unasserted (0), or unknown (–1).