Chapter 4 Using Your Serial Hardware
©
National Instruments Corporation
4-3
Serial for Windows NT
Setting the Transceiver Control Mode
The recommended method for setting the transceiver control mode is
with the serial configuration utility located in the Windows NT Control
Panel. For more information, refer to the General Port Settings section in
Chapter 3, Configuration. The mode you select in the Control Panel is
automatically configured when you open a port on a serial interface. You
can also set the hardware transceiver control mode from within a DOS
application. For each port you want to control, write the control byte for
the mode you want to select to the scratch register of the UART.
Table 4-2 shows the control bytes for each mode.
Table 4-2.
Transceiver Mode Control Bytes
Transceiver Mode
Control Byte
Four-wire mode
0x00
Two-wire mode:
DTR
with echo
0x01
Two-wire mode:
DTR
controlled
0x02
Two-wire mode:
TXR DY
auto control
0x03
The scratch register is located at offset 7 from the base address of the
port. For example, if COM2 were located at base address 0x3F8, and you
wanted to set the AT-485 board to two-wire mode with
DTR
control, you
would write a 0x02 to I/O address 0x3FF. The AT-485 board would
immediately switch to the two-wire mode with
DTR
control.
Setting the Transceiver Mode with DeviceIoControl
The NI Serial software extends the Windows function
DeviceIoControl
for programming the transceiver control mode. To
program the transceiver control mode using
DeviceIoControl
,
complete the following steps.
1.
Add the following lines to your source code.
#include <winioctl.h>
#define IOCTL_SERIAL_SET_TRANSCEIVER_MODE
CTL_CODE(FILE_DEVICE_SERIAL_PORT,37,METHOD_BUFFERED,
FILE_ANY_ACCESS)
2.
Use the Win32 function
DeviceIoControl
. Use the defined control
code value listed in Step 1 to set the transceiver mode, and the input