COM

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

COM

Post by RayBritton » Sun Apr 10, 2005 10:36 am

Is there any way of sending a "ping" in a COM port (without wanting a reply). just number such as 1

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Sun Apr 10, 2005 1:09 pm

No, not when running under windows.
I have left this dump.

RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton » Mon Apr 11, 2005 10:07 am

ok, then how would i do it in DOS or could i do it in freebasic (i'm getting trouble with this)

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Mon Apr 11, 2005 3:43 pm

Under pure DOS, you can do it with:
Open COM (or something, look in the QB help)

With FB you cant access com ports afaik
I have left this dump.

RayBritton
Veteran
Posts: 109
Joined: Thu Feb 10, 2005 12:38 pm

Post by RayBritton » Tue Apr 12, 2005 2:20 am

ok, but its port 4 an IR port will that create a problem

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Tue Apr 12, 2005 6:30 am

Code: Select all

OPEN "COMn: optlist1 optlist2" [FOR mode] AS [#]filenum% [LEN=reclen%]

  _ n           The communications port to open (1 = COM1, 2 = COM2)
  _ optlist1    The most-often-used communications parameters:
                    [speed] [,[parity] [,[data] [,[stop]]]]
                Defaults: 300 baud, even parity, 7 data bits, 1 stop bit.
  _ optlist2    Up to 10 other optional, less-often used data
                communications parameters.
  _ mode        One of the keywords OUTPUT, INPUT, or RANDOM (the
                default).
  _ filenum%    Any unused file number between 1 and 255, inclusive.
  _ reclen%     The size of a random-access-mode buffer (128 bytes is
                default).

Code: Select all

Opens and initializes a communications channel for I/O. The OPEN COM
statement must be executed before a device can be used for communication
using an RS232 interface.

Optimization Note
    _ If there is not an OPEN COM statement in your program, you can
      reduce the size of the .EXE file by linking with the stub file
      NOCOM.OBJ.

OPEN "COMn: optlist1 optlist2" [FOR mode] AS [#]filenum% [LEN=reclen%]
    _ If there are syntax errors in the OPEN COM statement, BASIC generates
      the error message, "Bad file name."
    _ The argument filenum% is the number used to open the file.
    _ The OPEN COM statement has many options, which can be separated into
      two option lists:
        - optlist1 contains the most general and often-used parameters;
        - optlist2 contains options used in special situations.
    _ optlist1 specifies the communication line parameters and
      has the following syntax:

       [speed] [,[parity] [,[data] [,[stop]]]]

    _ Following are the valid values for optlist1 options:

      Option    Description                     Range (default in bold)
      -------   ------------------------------  ---------------------------
      speed     Baud rate (bits per second)     75, 110, 150, 300, 600,
                                                1200, 1800, 2400, 9600
      parity    Method of parity checking       N, E, O, S, M, PE
                (none, even, odd, space,
                mark, error checking)
      data      Number of data bits per byte    5, 6, 7, or 8
      stop      Number of stop bits             1, 1.5, or 2(1)
      ---------------------------------------------------------------------
      (1) The default value is 1 for baud rates greater than 110. For
          baud rates less than or equal to 110, the default value is
          1.5 when data is 5; otherwise, the value is 2.

    _ Options in this list must be entered in the order shown. Use
      comma placeholders for defaults. For example,

        OPEN "COM1: ,N,8," FOR INPUT AS #1

    _ 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).

Important
    _ Because BASIC uses complete bytes (8 bits) for numbers, you must
      specify 8 data bits when transmitting or receiving numeric data.
    _ If any options from optlist2 are chosen, comma placeholders must
      still be used even if all of the optlist1 options are defaults.
      For example:

        OPEN "COM1: ,,,,CD1500" FOR INPUT AS #1

    _ The optlist2 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.
    _ The 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.             Ignored
                 Used to enable communication files              (as part
                 to be printed on a serial line printer.         of BIN
                 Causes a LF character (0AH) to be               default)
                 automatically sent after each CR (0DH).

                 Note that the carriage return may be sent as
                 a result of the width setting for the device.

                 Note also that INPUT and LINE INPUT, when used
                 from a COM file that was opened with the LF
                 option, ignore the line feed.

    _ The 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 QBX 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, the
                 default is 512 bytes.

    _ 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 is 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 is omitted                   Range, if m specified
                 ------------------------------    -----------------------
                 m = 1000 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 times the CD or    10 seconds    0 - 65,535 milliseconds
                 DS timeout value,
                 whichever is greater

Usage Notes
    _ 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.
    _ Use a relatively large value for the OP option compared to the CS,
      DS, or CD options.
    _ The argument mode is one of the following string expressions:

      Mode       Description
      ------     ---------------------------------
      OUTPUT     Specifies sequential output mode.
      INPUT      Specifies sequential input mode.
      RANDOM     Specifies random-access mode.
      If mode is omitted, it is assumed to be random-access input/output.

    _ 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 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
All from the QB 7.1 help.

So, opening COM 4 seems to be impossible. I think there's a patch somewhere made by Plasma (If I remember correctly) that allowed the use of COM 3 and 4 and higher bauds (higher speeds)
I have left this dump.

Guest

Post by Guest » Tue Apr 12, 2005 7:17 am

ok, just wanted to see to if i change change channel on my tv or something similar but that seems rather diffcult

Post Reply