Microsoft KB Archive/37093

= Toggling DTR Handshaking Line (Pin 20) with OUT Statement =

Article ID: 37093

Article Last Modified on 11/21/2006



This article was previously published under Q37093



SUMMARY
The communications port DTR line (Pin 20) can be toggled with an OUT statement. The OUT statement should access the modem control register in the UART. The modem control register can be accessed by the following statements:

For COM1, the statement is as follows: OUT &H3FC, INP(&H3FC) OR 1  ' Sets low bit to turn DTR on. OUT &H3FC, INP(&H3FC) AND &HFE ' Clears low bit to turn off DTR. For COM2, the statement is as follows: OUT &H2FC, INP(&H2FC) OR 1  ' Sets low bit to turn DTR on. OUT &H2FC, INP(&H2FC) AND &HFE ' Clears low bit to turn off DTR. This information applies to Microsoft QuickBasic Versions 4.00, 4.00b and 4.50, to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS, and to Microsoft Basic Professional Development System (PDS) Version 7.00 for MS-DOS.



MORE INFORMATION
Other information concerning hardware addresses for serial communications can be found in &quot;The Programmer's PC Sourcebook&quot; by Thom Hogan (Microsoft Press, 1988).

Code Example
'- DTR.BAS -- ' '   This program shows how to toggle on and off the DTR line for '   the RS-232 serial communications line in compiled Basic. ' '   The DTR (Data Terminal Ready) line is controlled by the lowest '   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 DTR on, OR o for DTR off&quot; DO UNTIL keyinput$ = CHR$(27) keyinput$ = INKEY$ IF (keyinput$ = &quot;d&quot;) OR (keyinput$ = &quot;D&quot;) THEN OUT &H3FC, INP(&H3FC) OR 1  ' Sets low bit to turn DTR on. ELSEIF (keyinput$ = &quot;o&quot;) OR (keyinput$ = &quot;O&quot;) THEN OUT &H3FC, INP(&H3FC) AND &HFE ' Clears low bit to turn off DTR. END IF LOOP

Additional query words: QuickBas BasicCom

Keywords: KB37093

-

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

© Microsoft Corporation. All rights reserved.