Microsoft KB Archive/39386

From BetaArchive Wiki
Knowledge Base


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 "COM1:" or "COM2:" 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 "COM1:" or "COM2:" 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 "com1:" and port and problems


MORE INFORMATION

The OPEN "COM1:" or OPEN "COM2:" statement uses the following logic, in order of execution, to check for errors:

  1. Check if <device number> was OPEN previously in the program. "File Already OPEN" displays if <file number> is already open.
  2. Parse the options used in the OPEN "COM1:" or OPEN "COM2:" statement. "Bad File Name or Number" displays if any of the following are true:

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

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

  3. Allocate transmit and receive buffers. "Out of Memory" displays if no room is left for buffers in the default data segment.
  4. Initialize device interface.

    1. "Bad File Name" displays when using anything other than "COM1:" or "COM2:" or when using a baud rate not equal to 75, 110, 150, 300, 600, 1200, 1800, 2400, 4800, 9600, or 19,200.
    2. "Device Unavailable" 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.
    3. "Device I/O Error" 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.)

Compiled Basic uses the following logic during INPUT from "COM1:" or "COM2:":

  1. Check for errors.

    1. "Communications Buffer Overflow" displays for receive (or transmit) buffer overflow.
    2. "Device I/O Error" displays for any of the following conditions:

               Condition       Description
               ---------       -----------
      
               break           A special line condition where line voltage
                               is held "on" (sending 1 bit, which is
                               between -25 and -3 volts) over more than 10
                               bit-times. (Note that "off" 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.
                                      
    3. "Device Timeout Error" displays if a CTS, DSR, or DCD time-out occurs.
  2. If no errors occurred, get next character from receive buffer. If none, then loop.

Compiled Basic uses the following logic during OUTPUT to "COM1:" or "COM2:":

  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 "COM1:" or "COM2:":

  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 "COM1:" or "COM2:":

  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 "COM1:" or "COM2:" 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