Toggling RTS Handshaking Line (Pin 4) with OUT Statement (79957)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0
  • Microsoft QuickBASIC 4.0b
  • Microsoft QuickBASIC 4.5
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System for MS-DOS 7.0
  • Microsoft Basic Professional Development System for MS-DOS 7.1

This article was previously published under Q79957

SUMMARY

The communications port Request to Send (RTS) line (pin 4) can be toggled with a Basic OUT statement. The OUT statement should access the modem control register I/O port in the Universal Asychronous Receiver Transmitter (UART). The modem control register is a byte that indicates the status of the UART Loopback test mode, OUT2 signal, OUT1 signal, RTS output, and Data Terminal Ready (DTR) output.

This information applies to Microsoft QuickBasic versions 4.0, 4.0b, and 4.5; Microsoft Basic Compiler versions 6.0 and 6.0b for MS-DOS; and Microsoft Basic Professional Development System (PDS) versions 7.0 and 7.1 for MS-DOS.

MORE INFORMATION

The modem control register contains the following information:
Bit Number
01234567   Function            Allowable Values
--------   --------            ----------------

x          DTR output          0=DTR forced high;1=DTR forced low
 x         RTS output          0=RTS forced high; 1=RTS forced low
  x        OUT1 signal         0=OUT1 forced high;1=OUT1 foced low
   x       OUT2 signal         0=OUT2 forced high;1=OUT2 forced low
    x      Loopback Test Mode  0=disabled; 1=enabled
     xxx   Always zero         No function
				
The modem control register contains the bit (bit 1) to force the RTS line high or low, and can be accessed from Basic with the following statements:
  'For COM1, the statement is as follows:
 OUT &H3FC, INP(&H3FC) OR 2      ' Sets second bit to turn on RTS.
 OUT &H3FC, INP(&H3FC) AND &HFD  ' Clears second bit to turn off RTS.

  'For COM2, the statement is as follows:
  OUT &H2FC, INP(&H2FC) OR 2      ' Sets second bit to turn on RTS.
  OUT &H2FC, INP(&H2FC) AND &HFD  ' Clears second bit to turn off RTS.
				

Code Example

'------------------------- RTS.BAS -------------------------
'
'    This program shows how to toggle on and off the RTS
'line for the RS-232 serial communications line in compiled Basic.
'
'    The RTS line is controlled by the second
'    bit in the modem control register, which is located at port
'    address 3FC hex for COM1: or 2FC hex for COM2:.
'
OPEN "Com1:9600,n,8,,CS0,DS0,CD0" FOR RANDOM AS #1
CLS
PRINT "Press d for RTS on, OR o for RTS off"
DO UNTIL keyinput$ = CHR$(27)
    keyinput$ = INKEY$
    IF UCASE$(keyinput$) = "D" THEN
     OUT &H3FC, INP(&H3FC) OR 2   'Sets second bit to turn on RTS.
    ELSEIF UCASE$(keyinput$) = "O" THEN
     OUT &H3FC, INP(&H3FC) AND &HFD 'Clears second bit to turn off RTS
    END IF
LOOP
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB79957