Setting Ring Indicate and DCD with DeviceIoControl

NI Serial Hardware and Software

Setting Ring Indicate (RI) and Data Carrier Detect (DCD) with DeviceIoControl

There are two ways to set and retrieve these RS-232 signals:

  • Set and read the NI-VISA Line RI State and Line DCD State attributes.
  • The NI-Serial software uses programmatic control codes and the DeviceIoControl Windows function to retrieve these RS-232 signals.

To retrieve these RS-232 signals 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 SERIAL_RI_OUT attribute can have the following values:
    • SERIAL_RI_ON
    • SERIAL_RI_OFF



  3. To set the RS-232 signal RI when the transceiver is in DCE mode, use the following code:
    DWORD l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_SET_RI,
       (LPVOID) NULL,
       0,
       (LPVOID) NULL,
       0,
       (LPDWORD) &l_ByteCount,
       NULL
       );
  4. To clear the RS-232 signal RI when the transceiver is in DCE mode, use the following code:
    DWORD l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_CLR_RI,
       (LPVOID) NULL,
       0,
       (LPVOID) NULL,
       0,
       (LPDWORD) &l_ByteCount,
       NULL
       );
  5. To retrieve the current state of the RS-232 signal RI when the transceiver is in DCE mode, use the following code:
    SERIAL_RI_OUT l_SerialRiOut;
    DWORD         l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_GET_RI,
       (LPVOID) NULL,
       0,
       (LPVOID) &l_SerialRiOut,
       sizeof (l_SerialRiOut),
       (LPDWORD) &l_ByteCount,
       NULL
       );
  6. The SERIAL_DCD_OUT attribute can have the following values:
    • SERIAL_DCD_ON
    • SERIAL_DCD_OFF



  7. To set the RS-232 signal DCD when the transceiver is in DCE mode, use the following code:
    DWORD l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_SET_DCD,
       (LPVOID) NULL,
       0,
       (LPVOID) NULL,
       0,
       (LPDWORD) &l_ByteCount,
       NULL
       );
  8. To clear the RS-232 signal DCD when the transceiver is in DCE mode, use the following code:
    DWORD l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_CLR_DCD,
       (LPVOID) NULL,
       0,
       (LPVOID) NULL,
       0,
       (LPDWORD) &l_ByteCount,
       NULL
       );
  9. To retrieve the current state of the RS-232 signal DCD when the transceiver is in DCE mode, use the following code:
    SERIAL_DCD_OUT l_SerialDcdOut;
    DWORD          l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_GET_DCD,
       (LPVOID) NULL,
       0,
       (LPVOID) &l_SerialDcdOut,
       sizeof (l_SerialDcdOut),
       (LPDWORD) &l_ByteCount,
       NULL
       );