Retrieving the Serial Interface Type

NI Serial Hardware and Software

Retrieving the Serial Interface Type (RS-232 or RS-485)

There are two ways to retrieve the serial interface type (RS-232 or RS-485):

  • Read the NI-VISA wire mode attribute.
  • The NI-Serial software uses programmatic control codes and the DeviceIoControl Windows function to retrieve the serial interface type.

To retrieve the serial interface type 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_INTERFACE attribute can have the following values:
    • RS485_INTERFACE
    • RS232_INTERFACE


  3. To retrieve the serial interface type, use NISERIAL_GET_INTERFACE_TYPE and DeviceIoControl with the following code:
    SERIAL_INTERFACE l_SerialInterface;
    DWORD            l_ByteCount;
    
    DeviceIoControl (
       PortHandle,
       NISERIAL_GET_INTERFACE_TYPE,
       (LPVOID) NULL,
       0,
       (LPVOID) &l_SerialInterface,
       sizeof (l_SerialInterface),
       (LPDWORD) &l_ByteCount,
       NULL
       );