Microsoft KB Archive/37093: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - "&" to "&")
 
Line 36: Line 36:
<br />
<br />
For COM1, the statement is as follows:
For COM1, the statement is as follows:
<pre class="codesample">  OUT &amp;H3FC, INP(&amp;H3FC) OR 1  ' Sets low bit to turn DTR on.
<pre class="codesample">  OUT &H3FC, INP(&H3FC) OR 1  ' Sets low bit to turn DTR on.
   OUT &amp;H3FC, INP(&amp;H3FC) AND &amp;HFE  ' Clears low bit to turn off DTR.
   OUT &H3FC, INP(&H3FC) AND &HFE  ' Clears low bit to turn off DTR.
                 </pre>
                 </pre>
For COM2, the statement is as follows:
For COM2, the statement is as follows:
<pre class="codesample">    OUT &amp;H2FC, INP(&amp;H2FC) OR 1  ' Sets low bit to turn DTR on.
<pre class="codesample">    OUT &H2FC, INP(&H2FC) OR 1  ' Sets low bit to turn DTR on.
     OUT &amp;H2FC, INP(&amp;H2FC) AND &amp;HFE  ' Clears low bit to turn off DTR.
     OUT &H2FC, INP(&H2FC) AND &HFE  ' Clears low bit to turn off DTR.
                 </pre>
                 </pre>
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.
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.
Line 68: Line 68:
     keyinput$ = INKEY$
     keyinput$ = INKEY$
     IF (keyinput$ = &quot;d&quot;) OR (keyinput$ = &quot;D&quot;) THEN
     IF (keyinput$ = &quot;d&quot;) OR (keyinput$ = &quot;D&quot;) THEN
       OUT &amp;H3FC, INP(&amp;H3FC) OR 1  ' Sets low bit to turn DTR on.
       OUT &H3FC, INP(&H3FC) OR 1  ' Sets low bit to turn DTR on.
     ELSEIF (keyinput$ = &quot;o&quot;) OR (keyinput$ = &quot;O&quot;) THEN
     ELSEIF (keyinput$ = &quot;o&quot;) OR (keyinput$ = &quot;O&quot;) THEN
       OUT &amp;H3FC, INP(&amp;H3FC) AND &amp;HFE  ' Clears low bit to turn off DTR.
       OUT &H3FC, INP(&H3FC) AND &HFE  ' Clears low bit to turn off DTR.
     END IF
     END IF
LOOP
LOOP

Latest revision as of 14:13, 21 July 2020

Knowledge Base


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 "The Programmer's PC Sourcebook" 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 "Com1:9600,n,8,,CS0,DS0,CD0" FOR RANDOM AS 1
CLS
PRINT "Press d for DTR on, OR o for DTR off"
DO UNTIL keyinput$ = CHR$(27)
    keyinput$ = INKEY$
    IF (keyinput$ = "d") OR (keyinput$ = "D") THEN
       OUT &H3FC, INP(&H3FC) OR 1   ' Sets low bit to turn DTR on.
    ELSEIF (keyinput$ = "o") OR (keyinput$ = "O") THEN
       OUT &H3FC, INP(&H3FC) AND &HFE  ' Clears low bit to turn off DTR.
    END IF
LOOP
                


Additional query words: QuickBas BasicCom

Keywords: KB37093