advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
OPEN COM Statement Details
  Summary  Details  Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 OPEN "COMn: optlist" [FOR mode] AS [#]filenum% [LEN=reclen%]
 
 Usage Notes
   ■ If there is no OPEN COM statement in your program, you can reduce the
     .EXE file size by linking with the stub file NOCOM.OBJ.
 
   ■ Because Visual Basic uses complete bytes (8 bits) for numbers, you must
     specify 8 data bits when transmitting or receiving numeric data.
 
   ■ Additional options require comma placeholders even if all of the options
     are defaults. For example:
 
         OPEN "COM1: ,,,,CD1500" FOR INPUT AS #1
 
   ■ If there are syntax errors in the OPEN COM statement, Visual Basic
     generates the error message, "Bad file name."
 
   ■ Specifying the argument reclen% is effective only in random-access mode.
     You can use any of the random-access I/O statements, such as GET and
     PUT, to treat the device as if it were a random-access file.
     See: GET Statement (File I/O)  PUT Statement (File I/O)
 
   ■ The OPEN COM statement performs the following steps in opening a
     communications device:
     1. The communications buffers are allocated and interrupts are enabled.
     2. The Data Terminal Ready line (DTR) is set high.
     3. If either of the OP or DS options is nonzero, the statement waits
        for the timeout period for the Data Set Ready line (DSR) to go high.
        If a timeout occurs, the process goes to step 6.
     4. If the RS option is not specified, the Request To Send line (RTS) is
        set high.
     5. If either of the OP or CD options is nonzero, the statement waits for
        the timeout period for the Data Carrier Detect line (DCD) to go high.
        If a timeout occurs, the process goes to step 6. Otherwise, the RS232
        device has been successfully opened.
     6. If there is a timeout, the open fails. The process deallocates the
        buffers, disables interrupts, clears all of the control lines, and
        generates the message, "Device timeout." In addition, for MS-DOS, the
        process sets the value of ERDEV$ to COM and sets ERDEV to a value
        that indicates the signal line that timed out, according to the
        following table:
 
              ERDEV Value    Signal Line
              ═══════════    ═══════════════════════════════════════════════
              128 (80H)      Clear to Send (CTS) timeout
              129 (81H)      Data Set Ready (DSR) timeout
              130 (82H)      Data Carrier Detect (DCD) timeout
 
        Note: Only the baud rates shown are supported. Any other value for
        speed is invalid. The PE parity value turns on error checking for
        parity errors. If you set data to eight bits per byte, you must
        specify no parity (N).
 
   ■ In addition to speed, parity, data, and stop, OPEN COM supports the
     options described below. Options can be specified in any order, and
     must be separated from one another by commas. There are three types
     of options: data mode, buffer size, and handshaking:
     • Data-mode options (ASC, BIN, and LF):
 
         Option     Description                                     Default
         ══════     ═══════════════════════════════════════════     ════════
         ASC or     Specifies treatment of tabs, carriage           BIN
         BIN        returns, and Ctrl+Z in the data stream:
 
                                                      ASC   BIN
                                                      ═══   ═══
                    Tabs expanded to blanks           Yes   No
                    CR forced at end of line          Yes   No
                    Ctrl+Z means end-of-file          Yes   No
                    Ctrl+Z sent when device closed    Yes   No
 
         LF         Effective only with the ASC option. Used        Ignored
                    to print communication files on a serial        (as part
                    line printer. Causes a linefeed character       of BIN
                    (0AH) to be sent automatically after each       default)
                    carriage return (0DH):
                    ■ The carriage return can be sent as a
                      a result of the width setting for the
                      device.
                    ■ INPUT and LINE INPUT, when used from a
                      COM file opened with the LF option,
                      ignore the linefeed character.
 
     • Buffer-size options for sequential modes (RB and TB):
 
         Option     Description
         ══════     ════════════════════════════════════════════════════════
         RB[n]      Receive buffer size (in bytes)
 
                    If the RB option is not used or n is omitted, the default
                    is 512 bytes, unless overridden by the /C option in the
                    BC or VB command line. Maximum receive buffer size is
                    32,767 bytes.
 
         TB[n]      Transmit buffer size (in bytes)
 
                    If the TB option is not used or n is omitted, default
                    is 512 bytes (max is 32,767).
 
     • Handshake and timing options (RS, CD, CS, DS, and OP):
 
         Option     Description
         ══════     ════════════════════════════════════════════════════════
         RS         Suppresses detection of Request To Send (RTS).
 
         CD[m]      Specifies the timeout period on the Data Carrier Detect
                    line (DCD). If no signal appears on the DCD line (the DCD
                    line remains low) for more than m milliseconds, a device
                    timeout occurs. If a CD timeout occurs, ERDEV contains
                    130 (82H).
 
                    Default if CD option not used,
                    m is omitted, or m = 0            Range, if m specified
                    ──────────────────────────────    ──────────────────────
                    m = 0, which means ignore the     0 - 65,535 milliseconds
                    state of the DCD line.
 
         CS[m]      Specifies the timeout period on the Clear To Send line
                    (CTS). If no signal appears on the CTS line (the CTS
                    line remains low) for more than m milliseconds, a device
                    timeout occurs. If a CS timeout occurs, ERDEV contains
                    128 (80H).
 
                    Default if CS option not used
                    or m omitted                      Range, if m specified
                    ──────────────────────────────    ──────────────────────
                    m = 1000 milliseconds             0 - 65,535 milliseconds
                                                      (m = 0 means ignore the
                                                      state of the CTS line)
 
 
         DS[m]      Specifies the timeout period on the Data Set Ready line
                    (DSR). If no signal appears on the DSR line (the DSR line
                    remains low) for more than m milliseconds, a device
                    timeout occurs. If a DS timeout occurs, ERDEV contains
                    129 (81H).
 
                    Default if DS option not used
                    or m omitted                      Range, if m specified
                    ──────────────────────────────    ──────────────────────
                    m = 1,000 milliseconds            0 - 65,535 milliseconds
                                                      (m = 0 means ignore the
                                                      state of the DSR line)
 
         OP[m]      Specifies how long the OPEN statement waits for all
                    communications lines to become active:
 
                                         Default if
                    Default if OP        OP used but
                    not used             m omitted   Range, if m specified
                    ───────────────────  ──────────  ───────────────────────
                    10 * CD or DS time-  10 seconds  0 - 65,535 milliseconds
                    out value, whichever
                    is greater
 
     • Use a relatively large value for the OP option compared to the CS,
       DS, or CD options.