Page 1 of 1

qb45 com port program

Posted: Mon Apr 28, 2003 10:08 pm
by Guest
I am trying to capture & process ascii data coming into a com1 port using the following open statement:
OPEN "COM1:9600,N,8,1,ASC,RB4096" FOR INPUT AS #2     ' open com port

after opening an output file I turn com(1) on then set up a loop:

ix = 1

&nbsp;DO WHILE ix <> 0
&nbsp;ON COM(1) GOSUB 2000
&nbsp;LOOP

at 2000 I do a line input #2 and get the data ok [except for a couple &nbsp;missing characters at the end]

the data is triggered by a print command [redirected to the serial port] through a null modem connection.

My problem is that while I get the data, I can't tell when there is no more data coming thru com1 so I can transfer out and process the file.

Bottom line, I guess, is how do you query the status of a com port in qb4.5?

Thanks

Re: qb45 com port program

Posted: Tue Apr 29, 2003 4:27 am
by frankiebaby
Well, basically the com port will not send a signal for when there is no data to send. The way a com port works is that any data can be sent at anytime, unless the buffer is full (b/c data is coming in too fast) or if hardware handshaking, rts/cts is being used and tells the com port to wait until recieve buffer is emptied. Typically handshaking is not something you need to worry about on a slower computer, but it is usually done via software (XON/XOFF).

to keep it simple, there is a signal usually sent at the end of transmission by the program that is doing the transmission, that is the "end of file" flag. it can be the ASCII character for EOF, or anything you decide on.
I cannot imagine why you would be missing some characters in the end, unless maybe it is b/c you are using LINE INPUT, which only inputs until a carriage return(C/R) . Any data afterwards is left to the next LINE INPUT or other input command. A better way to input the data may be a single input at a time, checking for EOF character every time.

I hope this is some use. If you need further help, i have an old BASICA book with a sample TTY terminal program in it i could retype. It uses XON and XOFF characters to control data flow and waits for the EOF signal.

Do you have QB 4.5 or better?

Posted: Tue Apr 29, 2003 1:38 pm
by Guest
If you do, you should check out the OPEN COM statement.

I came across this info that may help to a solution:
The choices for optlist2 are described in the following list. The
argument m is given in milliseconds; the default value for m is 1000.

&nbsp;Option &nbsp; Description
&nbsp;ASC &nbsp; &nbsp; &nbsp;Opens the device in ASCII mode. In ASCII mode, tabs are
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; expanded to spaces, carriage returns are forced at the
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end-of-line, and CTRL+Z is treated as end-of-file. When
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the channel is closed, CTRL+Z is sent over the RS-232 line.

&nbsp;BIN &nbsp; &nbsp; &nbsp;Opens the device in binary mode. This option supersedes
and further down was this . . .

The OPEN COM statement performs the following steps in opening a
communications device:

&nbsp;1. The communications buffers are allocated and interrupts are
&nbsp; &nbsp; enabled.
&nbsp;2. The Data Terminal Ready line (DTR) is set high.
&nbsp;3. If either of the OP or DS options is nonzero, the statement waits
&nbsp; &nbsp; up to the indicated time for the Data Set Ready line (DSR) to be
&nbsp; &nbsp; high. If a timeout occurs, the process goes to step 6.
&nbsp;4. The Request To Send line (RTS) is set high if the RS option is
&nbsp; &nbsp; not specified.
&nbsp;5. If either of the OP or CD options is nonzero, OPEN COM waits up
&nbsp; &nbsp; to the indicated time for the Data Carrier Detect line (DCD) to
&nbsp; &nbsp; be high. If a timeout occurs, the process goes to step 6.
&nbsp; &nbsp; Otherwise, OPEN COM has succeeded.
&nbsp;6. The open has failed due to a timeout. The process deallocates
&nbsp; &nbsp; the buffers, disables interrupts, and clears all of the control
&nbsp; &nbsp; lines.

&nbsp;Note: Use a relatively large value for the OP option compared to the
&nbsp; &nbsp; &nbsp; &nbsp;CS, DS, or CD options. If two programs are attempting to establish
&nbsp; &nbsp; &nbsp; &nbsp;a communications link, they both need to attempt an OPEN during at
&nbsp; &nbsp; &nbsp; &nbsp;least half of the time they are executing.
You don't have a "device time-out" set in your Open statement above, maybe that's the culprit?

Hope something here helps.

--MiggyD

Re: qb45 com port program

Posted: Tue Apr 29, 2003 9:44 pm
by dickbuck
Thanks for the suggestions; I will definately try the one char in at a time strategy [note &nbsp;use it on the way out.

I read the help about a control Z char too, but what is the ascii or hex equiv of a ^Z ? I've seen a 4- hex character in the file dump at the end but it seems to me that isn't a valid hex code. &nbsp;

I used to have a thick qb 4.5 users and programmers manual and would give my eye teeth for another... know where any are?

Re: qb45 com port program

Posted: Wed Apr 30, 2003 4:09 am
by frankiebaby
in the QB help file under ASCII character chart,

026 &nbsp; (eof)
027 (esc)
028 (fs) &nbsp;

Re: qb45 com port program

Posted: Thu May 01, 2003 3:32 am
by Guest
the ctrl key returns a higher bit:

CTRLESC$ = CHR$(0) + CHR$(26)

CHR$(0) is the CTRL [and I think ALT as well]... it doesn't hurt to try this.

--MiggyD