Microsoft KB Archive/79957

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

Article ID: 79957

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 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 &quot;Com1:9600,n,8,,CS0,DS0,CD0&quot; FOR RANDOM AS #1 CLS PRINT &quot;Press d for RTS on, OR o for RTS off&quot; DO UNTIL keyinput$ = CHR$(27) keyinput$ = INKEY$ IF UCASE$(keyinput$) = &quot;D&quot; THEN OUT &H3FC, INP(&H3FC) OR 2  'Sets second bit to turn on RTS. ELSEIF UCASE$(keyinput$) = &quot;O&quot; THEN OUT &H3FC, INP(&H3FC) AND &HFD 'Clears second bit to turn off RTS END IF LOOP

Additional query words: QuickBas BasicCom 4.00 4.00b 4.50 7.00 7.10 6.00 6.00b

Keywords: KB79957

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.