[comp.sys.mac.programmer] need serial driver help

sam@neoucom.UUCP (Scott A. Mason) (07/05/89)

I am writing a program that reads input from the serial port, and have been
having problems implementing flow control.  I'd like to read the serial
port on the interrupts, but don't know how this is done on the Mac.  So,
that's my question.

How does one write interrupt driven code for the Mac? (serial port code in
particular)  If this isn't possible, I'd like any suggestions you might
have.  I had planned on using a ring buffer to read and write at the same
time, but this just isn't efficient if you can't read the serial port on
the interrupts.  Thanks for your help.

-- 
--------------------------------------------------------------------------------
"If it ain't broke, don't fix it," and certainly don't blame me.
UUCP:  {pitt,scooter,hal,cwjcc,aablue}!neoucom!sam   INTERNET:  sam@neoucom.UUCP
Scott A. Mason, Coordinator of Systems Operations, NEOUCOM

oster@dewey.soe.berkeley.edu (David Phillip Oster) (07/07/89)

In article <1677@neoucom.UUCP> sam@neoucom.UUCP (Scott A. Mason) writes:
>I am writing a program that reads input from the serial port, and have been
>having problems implementing flow control.  I'd like to read the serial
>port on the interrupts, but don't know how this is done on the Mac. 

For almost any use of the serial port, you don't need to read it directly.
Just use Apple's serial driver. Give it a Status() call. If it responds,
some other program is using it, so show an error message. It it isn't
there, open it. (Use RAMSDopen() if you care about the 64k ROMS,
otherwise, just open it plain.)
Tell it to use either ^s/^Q (ie.,
XOFF/XON) or DTR handshaking. Give it a big buffer at the beginning of the
program, and remember to tell it the buffer is going away when you quit.
Remember to close it when you are done.
During the program, do asynchronous reads. Use completion routines to
restart the read when it finishes. In your event loop, poll ioActCount in
the read's parameter block to see how many characters have been read. If
you turn off interrupts, you can get away storing into ioBuffer and
ioActCount from your main program (although this is questionable practice
and will probably break in future systems.)

As long as the driver is open and there is room in the buffer, the driver
reads for you at interrupt level. Your PBReads() just drain its buffer.

If you really want to write your own interrupt driven serial port driver,
see the Device Manager chapter of Inside Mac Vol. 2, which has a
description of how hardware interrupts interact with the operating
system. You'll probably also need a data sheet for the serial chip.