[comp.sys.mac.programmer] Serial I/O

ralph@computing-maths.cardiff.ac.uk (Ralph Martin) (07/20/88)

Please not that I am posting this for Sak Wathanasin, and replies should go to
him, not to me. Thanks, Ralph.

I'm encountering a curious problem when using the modem and AppleTalk
ports simultaneously. This problem only occurs when running with the 64K
roms; in essence, I get a "hardware overrun error" (SerStatus returns
0x20 in cumErrs). It doesn't always happen but when it does I have a
PAPWrite outstanding (i.e., the write has been issued but not completed).
The reason for my doing this is to fill a second buffer from the serial
line while the LW is busy (if you haven't already guessed, the program
takes PostScript from the modem port and puts it out on AppleTalk).
If I understand IM Vol 2 correctly, a hardware overrun
should only occur if interrupts have been turned off too long.
What is turning interrupts off? (I don't do this in my code directly;
I do however call the PAP routines.)

I am using the SERD and AppleTalk drivers from the June'87(?) Software
supplement (the last I ever got from Apple), with XON/XOFF and
(via a call to SerSetBuf) an input buffer 1K big and two 4K
buffers for the PAP output (all buffers are static data, and
therefore locked). When all drivers have been loaded, I have about 2K
bytes free in a 128K Mac (not a lot, but everything I need is now allocated
and in memory - I think). Oh yes, and I'm using System 2.1 (!) on the 128K Mac.
The PAP routines come from the LW 3.1 driver (loaded using the technique
described in MacTutor).

If I issue XON/XOFF sequences in the appropriate places so that the
double-buffering effectively does not take place, the problem goes away.
This would point at something in my code, but I'm completely stumped because
the program runs without problems on a Mac+ (and Mac II) and under
MF in a 70K partition to boot (I have also run with TMON strict
discipline and heap scramble in that configuration with no problems).
Also if I define "showpage" in the PS stream so that it does nothing
("/showpage {} def" at the beginning of the job), the whole thing works;
i.e. the problem only occurs if the LW actually prints.

Can anyone help? Hints, and suggestions of things to try all gratefully
received. It already works with the 128K roms, but we would like this to work
with the 128K Mac as well 'cos it's ideal for this job. (And, yes, I'll
post the program to the net when I've sorted out the problem.)
Thanks in advance,

Sak Wathanasin

uucp:     ...!ukc!kernel!sw
JANET:  sw%kernel.uucp@uk.ac.ukc
BITNET: sw%kernel.uucp%ukc.ac.uk@ukacrl.bitnet
other:    sw%kernel.uucp@ukc.ac.uk
phone:    (+44) 532 444566
snail:    Kernel Technology Ltd, 46 The Calls, Leeds LS2 7EY

reynhout@cs.uri.edu (Andrew Reynhout) (06/11/91)

   From the Usenet Macintosh Programmer's Guide:
You can anonymous ftp a simple C program (source included) called "Capture"
that demonstrates Macintosh serial port control from "noc.byu.edu"
(128.187.7.2).  Get a file in the "pub" directory called "CaptureSit.hqx".
It includes a "LightSpeed 3.x" C project, source code, and resource file.

   It's not there any more.  Does anyone have any idea where I can find it?
   Should I ignore old stuff anyway and concentrate on CTB code?  I'd really
like to get some things written that use my serial ports, but I've been
frustrated at every turn by incomprehensible IM documentation, and inexplicable
problems with my code.  I have yet to successfully open the serial ports,
using the RAM or the ROM drivers.  Every example I've seen has agreed with my
code to the letter, and theirs apparently works.  Mine does not.
   Anyway, if anyone can point me to some sample code, I would be most
appreciative.  I would also like CTB code...  C is the language of choice.

   Thanks very much!
-- 
   <reynhout@cs.uri.edu>