Microsoft KB Archive/37417

= SHELL Statement Loses Current Data in Serial Port Input Buffer =

Article ID: 37417

Article Last Modified on 11/21/2006



This article was previously published under Q37417



SYMPTOMS
A SHELL statement will empty the input buffer (thus losing data) of the currently opened serial communications port (COM1 or COM2).



STATUS
Microsoft has confirmed this to be a bug in Microsoft QuickBasic versions 4.00, 4.00b, and 4.50; in Microsoft Basic Compiler versions 6.00 and 6.00b (buglist6.00, buglist6.00b); and in Microsoft Basic Professional Development System (PDS) version 7.00 (buglist7.00).

This problem is corrected in Microsoft Basic PDS 7.10 (fixlist7.10) if you compile with BC /O or run in the QBX.EXE environment. However, if you compile your program in 7.10 to use the BRT71xxx.EXE run-time module (in other words, you don't compile with BC /O), you will still lose data in the communications input buffer because the support for communications is in the run-time module, and the run-time module is released from memory during a SHELL to make more room for other programs to load. This is not a problem; it is a design limitation.

To work around the problem, empty the buffer (such as with the INPUT$ statement) before invoking the SHELL statement to retain information that would have been lost.



MORE INFORMATION
The following steps reproduce the behavior:


 * 1) Open a serial port (COM1 or COM2).
 * 2) Allow the buffer to be filled.
 * 3) Using the LOC function, print out the number of bytes in the buffer.
 * 4) Execute the SHELL statement with any valid parameter (such as SHELL &quot;DIR&quot;).
 * 5) Using the LOC function again, print out the number of bytes in the buffer. This number will be 0 (zero).

The following code will reproduce the above behavior. (Please note that the size of the buffer after the SHELL statement will be 0.) OPEN &quot;com1:9600&quot; FOR RANDOM AS #1 ' This loop will allow data to begin flowing into COM1. ' The loop terminates when an ESC key is pressed. DO UNTIL INKEY$ = CHR$(27) LOOP PRINT &quot;Size of buffer before SHELL statement: &quot;, LOC(1) PRINT PRINT &quot;press any key to shell&quot; WHILE (INKEY$ = &quot;&quot;): WEND SHELL &quot;dir&quot; PRINT &quot;Size of buffer after SHELL statement: &quot;, LOC(1) CLOSE

Additional query words: QuickBas BasicCom B_BasicCom buglist4.00 buglist4.00b buglist4.50

Keywords: KB37417

-

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

© Microsoft Corporation. All rights reserved.