Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!agate!ucbvax!dewey.soe.berkeley.edu!oster From: oster@dewey.soe.berkeley.edu (David Phillip Oster) Newsgroups: comp.sys.mac.programmer Subject: Re: need serial driver help Keywords: flow control Message-ID: <29977@ucbvax.BERKELEY.EDU> Date: 7 Jul 89 00:45:31 GMT References: <1677@neoucom.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: oster@dewey.soe.berkeley.edu.UUCP (David Phillip Oster) Organization: School of Education, UC-Berkeley Lines: 28 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.