Retrieving the RS-232 Transceiver State

NI Serial Hardware and Software

Retrieving the RS-232 Transceiver State

The NI-Serial software returns which mode the RS-232 transceivers are currently operating in, and whether the serial connection is valid.

Note  Transceiver mode refers to the programmed mode. Transceiver state refers to the physical state of the transceivers (actual operating mode and whether valid or invalid).

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

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

To 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 RS-232 transceiver state attribute is contained within a struct of type SERIAL_RS232_STATE. The struct members and possible values are shown below:
    Member Name Values
    PortMode RS232_MODE_DTE
    RS232_MODE_DCE
    RS232_MODE_AUTO
    Connection SERIAL_CONNECTION_INVALID
    SERIAL_CONNECTION_VALID
  3. To retrieve the current RS-232 transceiver state, use NISERIAL_GET_RS232_STATE and DeviceIoControl with the following code:

    SERIAL_RS232_STATE l_SerialRs232State;
    DWORD              l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_GET_RS232_STATE,
       (LPVOID) NULL,
       0,
       (LPVOID) &l_SerialRs232State,
       sizeof (l_SerialRs232State),
       (LPDWORD) &l_ByteCount,
       NULL
       );