Setting the RS-485 Transceiver Control Mode in Windows

NI Serial Hardware and Software

Setting the RS-485 Transceiver Control Mode in Windows

Setting the Default Mode of Operation

To set the default mode of operation:

  • Use the Advanced tab in Measurement & Automation Explorer (MAX).

Modifying the RS-485 Transceiver Mode Programmatically

To modify the RS-485 transceiver mode programmatically:

  • Change the NI-VISA wire mode attribute.
  • The NI-Serial software uses programmatic control codes and the DeviceIoControl Windows function for programming the RS-485 transceiver control mode.

    Setting the RS-485 Transceiver Control Mode on PCI, PXI, USB, ExpressCard, and PCMCIA Hardware

    To set and retrieve the RS-485 transceiver control mode using the DeviceIoControl Windows function on PCI, PXI, USB, ExpressCard, and PCMCIA RS-485 hardware, complete the following steps:


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



    3. To set the RS-485 transceiver control mode, use NISERIAL_SET_RS485_MODE and DeviceIoControl. For example, to set to two-wire Auto Control mode, use the following code:

      TRANSCEIVER_MODE l_TransceiverMode = RS485_MODE_2W_AUTO;
      DWORD            l_ByteCount;
      
      DeviceIoControl (
         PortHandle,
         NISERIAL_SET_RS485_MODE,
         (LPVOID) &l_TransceiverMode,
         sizeof (l_TransceiverMode),
         (LPVOID) NULL,
         0,
         (LPDWORD) &l_ByteCount,
         NULL
         );
      
    4. To retrieve the current RS-485 transceiver control mode, you can use NISERIAL_GET_RS485_MODE and DeviceIoControl with the following code:

      TRANSCEIVER_MODE l_TransceiverMode;
      DWORD            l_ByteCount;
      
      DeviceIoControl (
         PortHandle,
         NISERIAL_GET_RS485_MODE,
         (LPVOID) NULL,
         0,
         (LPVOID) &l_TransceiverMode,
         sizeof (l_TransceiverMode),
         (LPDWORD) &l_ByteCount,
         NULL
         );

    Setting the RS-485 Transceiver Control Mode on ENET Hardware

    To set and retrieve the RS-485 transceiver control mode using the DeviceIoControl Windows function on ENET RS-485 hardware, complete the following steps:


    1. Add the following lines to your source code:
      #include <winioctl.h>
      #define SERIAL_TM_4WIRE	0x80
      #define SERIAL_TM_2W_ECHO	0x81
      #define SERIAL_TM_2W_DTR	0x81
      #define SERIAL_TM_2W_AUTO	0x83
      #define IOCTL_SERIAL_SET_TRANSCEIVER_MODE
         CTL_CODE(FILE_DEVICE_SERIAL_PORT,37,METHOD_BUFFERED,FILE_ANY_ACCESS)
       
    2. To set the RS-485 transceiver control mode, use IOCTL_SERIAL_SET_TRANSCEIVER_MODE and DeviceIoControl. For example, to set to two-wire Auto Control mode, use the following code:
      ULONG bytecount;
      TRANSCEIVER_MODE transceiver_mode = SERIAL_TM_2W_AUTO;
      DeviceIoControl(
         comhandle,
         IOCTL_SERIAL_SET_TRANSCEIVER_MODE,
         (PVOID) &transceiver_mode,
         sizeof(transceiver_mode),
         (PVOID) NULL, 0,
         &bytecount,
         NULL
      );