Microsoft KB Archive/39386

= Error Message Explanations When Using COM1: and COM2 =

Article ID: 39386

Article Last Modified on 8/16/2005

-

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 Q39386



SUMMARY
The following error messages can appear when using the &quot;COM1:&quot; or &quot;COM2:&quot; device:   Error Message                     Number -                    --

File Already OPEN                (Error 55) Bad File Name or Number          (Error 52) Out of Memory                    (Error 7) Device Unavailable               (Error 68) Device I/O Error                 (Error 57) Communications Buffer Overflow   (Error 69) Device Timeout                   (Error 24) This article gives the logic used to determine when to display these errors during OPEN, INPUT, OUTPUT, and other statements when using the &quot;COM1:&quot; or &quot;COM2:&quot; device. This information applies to Microsoft QuickBasic versions 4.00, 4.00b, and 4.50 and to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2. For a related article concerning how to solve common communications port problems, search for the following words in this Knowledge Base:

solve and &quot;com1:&quot; and port and problems



MORE INFORMATION
The OPEN &quot;COM1:&quot; or OPEN &quot;COM2:&quot; statement uses the following logic, in order of execution, to check for errors:

 Check if was OPEN previously in the program. &quot;File Already OPEN&quot; displays if is already open. Parse the options used in the OPEN &quot;COM1:&quot; or OPEN &quot;COM2:&quot; statement. &quot;Bad File Name or Number&quot; displays if any of the following are true:

 Baud rate is not numeric or over 65,535 Parity is not N, O, E, M, or S Data bits are not 5, 6, 7, 8 Data bits are 8 and parity is O, E, M, or S</li> Stop bits are not 1 or 2 (1.5 is not supported)</li> One of the following arguments is misspelled (order is not significant for these; &quot;m&quot; can be null or a number from 0 to 65,535 milliseconds; buffersize &quot;x&quot; can be up to 32,767 bytes):

OPm, DSm, CSm, CDm, RBx, TBx, RS, LF, BIN, ASC

</li></ol> </li> Allocate transmit and receive buffers. &quot;Out of Memory&quot; displays if no room is left for buffers in the default data segment.</li> Initialize device interface.

<ol style="list-style-type: lower-alpha;"> &quot;Bad File Name&quot; displays when using anything other than &quot;COM1:&quot; or &quot;COM2:&quot; or when using a baud rate not equal to 75, 110, 150, 300, 600, 1200, 1800, 2400, 4800, 9600, or 19,200.</li> &quot;Device Unavailable&quot; displays if the communications interface is already in use or does not exist (according to the 4 bytes at 400 hex in low PC memory).

If no errors have occurred at this point in the OPEN, the baud rate, data size, parity, and stop bits are now set. DTR is set. RTS is set if the RS option is not specified. If you use the OPn (OPEN time-out) option, Item 4c (below) applies.</li> &quot;Device I/O Error&quot; displays if an OPn OPEN time-out occurs after waiting for DSR (Data Set Ready) or DCD (Data Carrier Detect).

(Note: QuickBasic versions 2.00, 2.01, and 3.00 use the DSn and CDn options for DSR and DCD time-out instead of the later versions 4.00, 4.00b, and 4.50 OPn option.)</li></ol> </li></ol>

Compiled Basic uses the following logic during INPUT from &quot;COM1:&quot; or &quot;COM2:&quot;:

<ol> Check for errors.

<ol style="list-style-type: lower-alpha;"> &quot;Communications Buffer Overflow&quot; displays for receive (or transmit) buffer overflow.</li>  &quot;Device I/O Error&quot; displays for any of the following conditions: <pre class="fixed_text">        Condition       Description -      ---

break          A special line condition where line voltage is held &quot;on&quot; (sending 1 bit, which is                        between -25 and -3 volts) over more than 10 bit-times. (Note that &quot;off&quot; means a 0 bit,                        which is between +3 and +25 volts).

parity error   Can occur if line is noisy, or the wrong baud or parity is being used.

overrun error  The character (a 10-bit data frame) was not read from the interface hardware in time before it was overwritten by the next received character.

framing error  The bit to be interpreted as the stop bit was not 0. A framing error can occur if the line is noisy, if the wrong baud rate is used, or                        if the clock speeds on the communicating PCs are mismatched. </li> &quot;Device Timeout Error&quot; displays if a CTS, DSR, or DCD time-out occurs.</li></ol> </li> If no errors occurred, get next character from receive buffer. If none, then loop.</li></ol>

Compiled Basic uses the following logic during OUTPUT to &quot;COM1:&quot; or &quot;COM2:&quot;:


 * 1) Check for errors. (Same as for INPUT above.)
 * 2) Test if transmit buffer is full. If full, loop back to 1.
 * 3) Put character into buffer.

The LOC(n) function does the following when used with &quot;COM1:&quot; or &quot;COM2:&quot;:


 * 1) Check for errors. (Same as for INPUT above.)
 * 2) LOC(n) returns the number of characters currently in the receive buffer.

The LOF(n) function does the following when used with &quot;COM1:&quot; or &quot;COM2:&quot;:


 * 1) Check for errors. (Same as for INPUT above.)
 * 2) LOF(n) returns the room left in the TRANSMIT buffer in QuickBasic versions 4.00, 4.00b, and 4.50 and Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2.

LOF(n) returns the room left in the RECEIVE buffer in QuickBasic versions 1.00, 1.02, 2.00, 2.01, and 3.00.

Basic uses the following logic when you CLOSE the &quot;COM1:&quot; or &quot;COM2:&quot; device:


 * 1) Transmit output. If using the ASC option (and not the BIN option), transmit an end-of-file (EOF) character (CTRL+Z).
 * 2) Wait for pending output to finish or time-out.
 * 3) Restore interrupt vectors.
 * 4) Deallocate transmit and receive buffers from Basic's default data segment.
 * 5) Report any pending errors.

Additional query words: QuickBas BasicCom

Keywords: KB39386

-

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

© Microsoft Corporation. All rights reserved.