Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!mephisto!prism!cc100aa From: cc100aa@prism.gatech.EDU (Ray Spalding) Newsgroups: comp.sys.mac.programmer Subject: Re: FSRead hangs on the serial driver Message-ID: <4713@hydra.gatech.EDU> Date: 9 Jan 90 23:00:57 GMT References: <7770@unix.SRI.COM> Reply-To: cc100aa@prism.gatech.EDU (Ray Spalding) Organization: Georgia Institute of Technology Lines: 63 In article <7770@unix.SRI.COM> gil@ginger.sri.com (Gil Porat) writes: [regarding FSRead with the serial driver] >1) Why does the second FSRead hang? Because it will not return until it gets the exact number of characters you asked it to read. >2) Doesn't FSRead return as much as it can? No, see above. >3) Is there a way to get the serial driver and/or FSRead to time out? The way to accomplish this is to use asynchronous I/O (in the sense of IM vol IV, not in the sense of async data communications). You start an asynchronous read request, then go about your business processing events and so on. Periodically, you check the request block for completion: 0 == normal completion; 1 == still in progress; anything else == error. If you want to time it out, you have to watch the time yourself (using TickCount). Caveat: Be sure to call SystemTask (or WaitNextEvent) periodically so that the serial driver will get a slice of CPU. Some fragments of the code I use (MPW C): ParamBlockRec commInPB; static unsigned char commInChar; static short commInPort = -6; CommStartIn() /* Queue serial port input request and return */ { commInPB.ioParam.ioCompletion = NULL; commInPB.ioParam.ioVRefNum = 0; commInPB.ioParam.ioRefNum = commInPort; commInPB.ioParam.ioBuffer = &commInChar; commInPB.ioParam.ioReqCount = 1; /* ask for one character only */ commInPB.ioParam.ioPosMode = 0; PBRead(&commInPB,true); } CommDisp() /* Check for serial port input completion */ { int rc; SystemTask(); rc = commInPB.ioParam.ioResult; if (rc == 1) return; /* or check for timeout here */ if (rc != noErr) { /* process errors */ return;} /* ... process one input character ... */ CommStartIn(); /* queue request for next character */ return; } >4) Does FSRead need an EOT to return? No, EOT is passed through to you like any other character. -- Ray Spalding, Office of Computing Services Georgia Institute of Technology, Atlanta Georgia, 30332-0275 uucp: ...!{allegra,amd,hplabs,ut-ngp}!gatech!prism!cc100aa Internet: cc100aa@prism.gatech.edu