Newsgroups: comp.sys.atari.st
From: andre@cix.compulink.co.uk (Cygnus Software Ltd)
Subject: Re: How to handle the RS232 under GFA-Basic?
Reply-To: andre@cix.compulink.co.uk
Date: Wed, 11 Nov 1992 10:25:00 +0000


nienaber@sonne.zedat.fu-berlin.de (H. Nienaber) wrote:
>I am writing a pttle rogram wich will read the data from a GOULD 1604-
>Oscilloscope. The serial port is with XBIOS(15,1,0,-1,...) for 9600Bps and
>XON, XOFF configurated. The scope is also set to this parameters. The problem
>is: the serial interface dont stop the incoming data-stream even when i dont
>get the byte stream.
>[stuff deleted]
>If i connect my terminal (CoNnect :-)) to the scope i can pause the incoming
>stream of data with ^S and continue with ^Q.
>In my program i use the INPAUX$-command to get the incoming data. The GFA-Basic
>is a version 3.5(or so) wich was distributed some weeks ago by the german TOS-
>magazine.
>Is there anyone who has experience with the RS232 und GFA or some tips, 
>routines, sources?

First, sorry for the delay in replying, I don't know if anyone has already
responded, but here goes:

My first tip would be to avoid INPAUX$. I know it's a nice command (I used
to use it a lot too), but it seems to screw up CTS/RTS flow control completely,
and I've no doubt it does the same for XON/XOFF too. I assume it works by
pulling bytes directly from the RS232 buffer, and then adjusting the pointers,
which must confuse the OS in some way - at least, it does with my extended
buffers, anyway.

Stick to multiple INP?(1) and INP(1) commands, or their GEMDOS equivalents.
If that still doesn't work, try sending Control-S directly from your program
and see if that stops the data stream correctly.

If all else fails, simply extend the buffer size to give you more time
to read the data. Mind you, this is only a solution for bursts of data; if
the scope keeps sending data all the time, you'll only be postponing the
inevitable.

To enlarge the RS232 buffer, first use iorec(0) [XBIOS(14,0)] which returns
the address of the current serial I/O table. This is a structure with the
following contents:

  LONG  Pointer to the current RS232 buffer in memory
  WORD  Current size of the buffer (in bytes)
  WORD  Head index (in bytes) i.e. pointer to next unread byte of data
  WORD  Tail index (in bytes) i.e. pointer to last byte of data waiting
  WORD  Low watermark (in bytes)
  WORD  High watermark (in bytes)

This table is followed in memory by another, identical, one for outgoing
data, but that doesn't usually need to be changed.

The High and Low watermarks are used for flow control - when there are
more unread bytes in the buffer than allowed for by the High value, a
'stop flow' command is issued. The start flow will only be issued when the
buffer has been emptied down to the Low level. A good rule of thumb for
these would be around 75% to 90% of the buffer size for the High value, and
around 50% to 75% for the low value, depending on how quickly your device
responds to XOFF.

To change the buffer size, first store the existing values so you can
reset them later, then MALLOC a nice big buffer and store its address
into the first LONG. Don't go beyond about 32k. Next store the buffer size
into the next WORD, and set up the High and Low watermark values
accordiningly. Finally, zero the Head and Tail indexes. It's best to do all
this while there's no data coming in from the RS232 port, otherwise you'll
lose some of it.

I hope at least some of the above was helpful.

Andre

Andre Willey                       |  Email: andre@cix.compulink.co.uk
7 Oaklands Road, Sutton Coldfield, |         andre@cix.uucp
West Midlands, B74 2TB, England.   |         ...{mcsun}!uknet!cix!andre
Phone: (UK) 021-308-5251           |  "Il est mort, Jean Luc..."
Newsgroups: comp.sys.atari.st