Setting the RS-232 Transceiver Mode with DeviceIoControl

NI Serial Hardware and Software

Setting the RS-232 Transceiver Mode with DeviceIoControl

There are two ways to set and retrieve the RS-232 transceiver state:

  • Set and read the NI-VISA wire mode attribute.
  • The NI-Serial software uses programmatic control codes and the DeviceIoControl Windows function to retrieve the RS-232 transceiver state.

To set and retrieve the RS-232 transceiver state using the DeviceIoControl Windows function, 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 TRANSCEIVER_MODE attribute can have the following values:
    • RS232_MODE_DTE
    • RS232_MODE_DCE
    • RS232_MODE_AUTO



  3. To set the RS-232 transceiver, use NISERIAL_SET_RS232_MODE and DeviceIoControl. For example, to set to Force DCE mode, use the following code:
    TRANSCEIVER_MODE l_TransceiverMode = RS232_MODE_DCE;
    DWORD            l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_SET_RS232_MODE,
       (LPVOID) &l_TransceiverMode,
       sizeof (l_TransceiverMode),
       (LPVOID) NULL,
       0,
       (LPDWORD) &l_ByteCount,
       NULL
       );
  4. To retrieve the current RS-232 transceiver mode, you can use NISERIAL_GET_RS232_MODE and DeviceIoControl with the following code:
    TRANSCEIVER_MODE l_TransceiverMode;
    DWORD            l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_GET_RS232_MODE,
       (LPVOID) NULL,
       0,
       (LPVOID) &l_TransceiverMode,
       sizeof (l_TransceiverMode),
       (LPDWORD) &l_ByteCount,
       NULL
       );