Setting the USB-485 Programmatically Controlled Bias Resistor Mode

NI Serial Hardware and Software

Setting the USB-485 Programmatically Controlled Bias Resistor Mode

The USB-485 hardware can programmatically control the onboard (nonsocketed) bias resistors. By default, these resistors are enabled during normal device operation and disabled during USB suspend. There are two ways to control these resistors:

  • Use the Advanced tab in MAX. If the Enable Dynamic Bias Resistors box is checked, the resistors are enabled automatically whenever a serial port is open during normal operation. If the box is not checked, the resistors are disabled.
  • Your software can enable or disable the bias resistors programmatically by making DeviceIoControl calls to the serial driver.

Setting the RS-485 Programmatically Controlled Bias Resistors with DeviceIoControl

The NI-Serial software uses programmatic control codes and the DeviceIoControl Windows function for programming the RS-485 bias resistor mode. To set and retrieve the RS-485 bias resistor mode, complete the following steps:

  1. Add the following lines to your source code:
    #include <winioctl.h>
    #include <NiSerial.h>
    Note  The header file NiSerial.h is included on your NI-Serial software CD. You also can find it in the NI-Serial folder where you installed your National Instruments software (typically, C:\Program Files\National Instruments\NI-Serial).
  2. The SERIAL_RS485_BIAS attribute can have the following values:
    • RS485_BIAS_OFF
    • RS485_BIAS_ON



  3. To set the RS-485 bias resistor mode, use NISERIAL_SET_RS485_BIAS and DeviceIoControl. For example, to enable programmatically controlled RS-485 bias resistors, use the following code:
    SERIAL_RS485_BIAS l_SerialRs485Bias = RS485_BIAS_ON;
    DWORD             l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_SET_RS485_BIAS,
       (LPVOID) &l_SerialRs485Bias,
       sizeof (l_SerialRs485Bias),
       (LPVOID) NULL,
       0,
       (LPDWORD) &l_ByteCount,
       NULL
       );
  4. To retrieve the current RS-485 bias resistor mode, you can use NISERIAL_GET_RS485_BIAS and DeviceIoControl with the following code:
    SERIAL_RS485_BIAS l_SerialRs485Bias;
    DWORD             l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_GET_RS485_BIAS,
       (LPVOID) NULL,
       0,
       (LPVOID) &l_SerialRs485Bias,
       sizeof (l_SerialRs485Bias),
       (LPDWORD) &l_ByteCount,
       NULL
       );