Microsoft KB Archive/26471

= Workarounds for CLOSE of COM(n) Disconnecting Phone Connection =

Article ID: 26471

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

-



This article was previously published under Q26471



SUMMARY
QuickBasic disconnects the phone connection when a program CLOSEs the communications port or when the program ENDs. This happens because the DTR line is dropped on a CLOSE or END statement. Below are several possible workarounds that might help you to overcome this design limitation of Microsoft QuickBasic.

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
The first workaround is to attempt to reset the DTR line immediately after the CLOSE statement. To do this, the correct OUT instruction is sent to the modem control register to set DTR (pin 20) high. Consider the following example: OPEN &quot;COM(n): &quot; FOR AS #n ' The rest of your program code goes here. CLOSE #n OUT &H3FC,3 END However, this example may not work because there is a small period of time between the CLOSE and the OUT statements. The modem may disconnect the phone connection even in this small time period.

Some &quot;smart&quot; modems allow you to adjust the time-out period for the DTR line. If you set this time-out period higher, the modem will wait longer before disconnecting the phone connection. This gives you just enough time to execute the OUT instruction to set the DTR line higher. The following is an example: OPEN &quot;COM(n): &quot; FOR AS #n PRINT #n, ' The rest of your program code goes here. CLOSE #n OUT &H3FC,3 END In the above example, is a series of control codes sent to the modem to set the DTR time-out period higher. Consult the manual for your modem to determine the correct control code string. The following is an example of the above code modified to work with a Hayes Smartmodem: OPEN &quot;COM(n): &quot; FOR OUTPUT AS #1 PRINT #n, &quot;AT S25=100&quot; 'Sets the DTR time out to 100/100 seconds ' or 1 second. Note that a carriage return is sent after this ' PRINT statement. If you OPEN for BINARY, you have to send a    ' CHR$(13) also, which tells the modem you are at the end of the ' initial control string. CLOSE #1 OUT &H3FC,3 END In some cases, a complaint about losing DTR may really be about losing RTS. If this is the case, some modems allow you to ignore RTS, as follows: OPEN &quot;COM(n): &quot; FOR AS #n PRINT #n, ' The rest of your program code goes here. CLOSE #n END In this case, you would send a control string to the smart modem to tell it to ignore the RTS line.

Note: If you do not have a smart modem and the first workaround does not correct the problem for you, it will be very difficult to work around this limitation of QuickBasic. The best method is obtain a smart modem and attempt the second or third workarounds.

The above examples use software instructions to set the DTR time-out period or to ignore the RTS line. However, some modems also allow these adjustments to be made with DIP switches.

Notes on CHAINing and RUNning
Whenever you compile standalone programs (/O), the CLOSE is performed implicitly when you do a RUN or a CHAIN. If your programs use BRUNxxx.EXE and the COM port is not CLOSEd, DTR and RTS should stay high. Compiling with BCOMxxx.LIB or closing the COM port always drops DTR.

Additional query words: QuickBas

Keywords: KB26471

-

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

© Microsoft Corporation. All rights reserved.