Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!rutgers!ucsd!nosc!helios.ee.lbl.gov!ux1.lbl.gov!beard From: beard@ux1.lbl.gov (Patrick C Beard) Newsgroups: comp.sys.mac.programmer Subject: Re: Reading chars from serial port Message-ID: <560@helios.ee.lbl.gov> Date: 30 Jul 88 11:19:46 GMT References: <77900004@peterson> Sender: usenet@helios.ee.lbl.gov Reply-To: beard@ux1.lbl.gov (Patrick C Beard) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 67 In article <77900004@peterson> peterson@peterson.applicon.UUCP writes: > >I want to read (at fairly high speed) characters from the serial port >until I get a certain character. > >Joe Peterson >Schlumberger >Billerica, Ma > >uucp: ...mit-eddie!applicon!peterson Here is how I do it: /* serialhelp.c */ #include SetUpPort(port,buf,length, inRefPtr, outRefPtr) SPortSel port; /* selector for which port to set up */ char *buf; long length; int *inRefPtr, *outRefPtr; { /* decide which port to open -- port A is modem, B printer */ switch(port) { case sPortA: error=OpenDriver("\p.AIn",inRefPtr); error=OpenDriver("\p.Aout",outRefPtr); break; case sPortB: error=OpenDriver("\p.BIn",inRefPtr); error=OpenDriver("\p.Bout",outRefPtr); break; } /* set up the speed of the buffers -- hardwired to 1200 baud here */ SerReset(*outRefPtr,baud1200+stop10+data8+noParity); SerReset(*inRefPtr,baud1200+stop10+data8+noParity); /* set up the incoming buffer */ SerSetBuf(*inRefPtr, buf, length); } /* non-blocking read of serial port */ ModemGetChar(inRef) int inRef; /* reference to the serial port */ { long count, bytes; char theChar; SerGetBuf(inRef,&count); if(count) { /* if any characters, then read one of them */ bytes=1L; FSRead(inRef,&bytes,&theChar); } else { theChar=0; /* flag to indicate no character available */ } return(theChar); } I hope this helps you. Patrick Beard Lawrence Berkeley Laboratory beard@ux1.lbl.gov