Help with a QB program reading data from serial port please

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
adamjsawyer
Newbie
Posts: 4
Joined: Thu Aug 11, 2005 10:56 am

Help with a QB program reading data from serial port please

Post by adamjsawyer »

:shock: I have a quickbasic (QBC) program I'm trying to understand. It is reading data from a serial port and saving it into a file. Here is the section of code I'm interested in, I am particularly interested in the settings for the serial communication. The sender is a bastardised PDP11 machine, and I have to write a windows program to do the same thing as this old DOS one:


OPEN "COM2:4800,N,8,1,CD0,CS0,DS0,RB6000" FOR INPUT AS #1

ATLgen$ = pathc$ + "\GEN\INV" + inv$ + ".GEN"
IF NOT openf(ATLgen$, "OUTPUT", 9) THEN RETURN
closes 9

LOCATE 22, 1: PRINT s80$;
VIEW PRINT 4 TO 24

DO ' Start of a new BATCH of staples
nl = 2
FOR i = 1 TO 100: l$(i) = "": NEXT i

DO ' Wait for a printing char to start (ignore FF,CR,LF)
c$ = "": IF INKEY$ = ESC$ GOTO atl8 ' No more batches if OPR did ESC
IF LOC(1) > 0 THEN c$ = INPUT$(1, 1)
LOOP UNTIL c$ >= " " AND c$ <= "z"
DO ' Get all all i/p for a batch
t1# = TIMER
IF c$ >= " " AND c$ <= "z" THEN PRINT c$; : l$(nl) = l$(nl) + c$
IF c$ = CR$ THEN PRINT c$; : nl = nl + 1
DO ' Wait for next char,or i/p timeout, or OPR ESC
IF INKEY$ = ESC$ GOTO atl8
IF TIMER - t1# > 5 GOTO atl4
LOOP UNTIL LOC(1) > 0
c$ = INPUT$(1, 1)
LOOP
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

For one thing, if you want to do a windows program, QB won't do that for you. What Window language do you use? once we know that we'll be able to better guide you?

DO you plan on using FreeBasic? do you have VisualBasic? which ?
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
adamjsawyer
Newbie
Posts: 4
Joined: Thu Aug 11, 2005 10:56 am

Post by adamjsawyer »

The old receiving program is quickbasic. i need to understand that program so i can write a windows program to replace it. i'm thinking of using Delphi 6, since the workstation the program will run on is win98 with no .NET
I'm very interested in the exact setup of the serial communications, as there are some things in that OPEN line I do not understand. I get the COM2 part, the 4800 baud, and the N for no parity, and the 1 for 1 stop bit... that's about it.

thx
adam
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

Well technically that's all you need to know...

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

is all you need...to open a com port.

If I recall correctly, here's what I believe the others mean;

CD Carrier Detect
CS Carrier Send
DS Not sure off the top of my head. But it's another thing being Sent like CS
RB6000 I believe sets the read buffer to accept 6000 bytes of data at a time.

Hope this helps.
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
adamjsawyer
Newbie
Posts: 4
Joined: Thu Aug 11, 2005 10:56 am

Post by adamjsawyer »

thanks I'll keep that in mind
MystikShadows
Veteran
Posts: 703
Joined: Sun Nov 14, 2004 7:36 am
Contact:

Post by MystikShadows »

No problem :-)...I'm thinking the RB6000 might be there for a reason..Perhaps the device it's communicating with is sending data 6000 bytes at a time. :-)_
When God created light, so too was born, the first Shadow!

MystikShadows

Need hosting? http://www.jc-hosting.net

Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

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
I have left this dump.
adamjsawyer
Newbie
Posts: 4
Joined: Thu Aug 11, 2005 10:56 am

Post by adamjsawyer »

wow i appreciate the in depth information. I have already grabbed a java program which can send data to and pro between two win xp machines. I need to modify that program to receive the data from the PDP11. Probably the only question I have now is whether the OPEN COM statement in the code I provided indicates any Flow Control or not. In the java program I have it has a flow control open for RTS/CTS

appreciate any help
adam
Post Reply