From: robertm@terapin.com (Robert Michaels)
Newsgroups: comp.sys.amiga.programmer
Subject: Re: Programming Help Needed
Date: 2 Jan 93 17:32:32 PST
Organization: BBS

In article <kkPLwB3w165w@coyote.datalog.com>, cobra@coyote.datalog.com (Ken
Thompson) writes:
>  Greetings:
> 
> The following message is from a friend of mine...I know *very* little
>about C programming, and stretched my brain for a few milli-seconds &
>couldn't figure it out, so I'll forward it here...
> 
> If you would be as kind ast to E-Mail your responses, I will collect
>them and forward them to my friend.  Thanks!         -Ken
> 
> - - - - - - - - - - - (generic cutting line) - - - - - - - - - - - - - -
>Those who have done experimentation with the Serial port routines in C 
>or otherwise, please step forward
> 
>My problem:
> 
>I set up the typical things to do a serial port read such as open 
>up a MsgPort structure and then create a 'request block' with a 
>CreateExtIO() function.  I set up the baud rates and know that every-
>thing is working properly.
> 
>Now, I would like to receive one byte at a time from the serial port
>in real time.  No 2400 bytes per second or anything.  And, for every 
>one of those bytes from the serial port, I wish to get a MsgPort mes-
>sage sent to me for each one of those bits and then check for that mes-
>sage with a:
> 
>SerialPortSignal = 1 << ReadPortPtr->IOSer.io_Message.mn_ReplyPort->mp_Sig
>Bit
> 
>I wish to check two other message ports at the same time in the same
>manner.  One is from a window and the other from a timer.
> 
>Therefore, I wish to have three MessagePorts that all send me slow
>changing information, and I wish one of them to be from the serial
>port.
> 
>I can't use a 'Wait(Signals=SerialPortSignal (or) WindowPortSignal 
>(or) TimerPortSignal) because it locks up and I don't get any signals
>from either the timer or serial port if I do that.
> 
>Anybody got any code which may shed some light on this?
> 
>I don't wish to do continuous cycling and rechecking using the 
>CheckIO() function, I just want it to sit there until things are 
>done, or ready, then have it proceed.
> 
> - - - - - - - - - - - (generic cutting line) - - - - - - - - - - - - - -
> 
> Again, if responses could be E-mailed, it'd be appreciated...thanks!
> 
>
>
>           _____         ______________________   _____                
>       |/    |          | cobra@datalog.com   |     |        /\        
>       |\ en |hompson   | cobra@jab.tus.az.us |     |ucson, /--\rizona 
>     ------------------------------------------------------------------
First request that the serial device read exactly one byte as follows:

/*Issue read command for serial port, don't wait for IO to be completed*/

VOID readser(void)

{
   SerialRdIO->IOSer.io_Command=CMD_READ;
   SerialRdIO->IOSer.io_Length=1;
   SendIO((struct IORequest *)SerialRdIO);
}


Then use the following to wait for the read to take place...note that you can
add in as many other masks for events to wait for in addition to 'WINDMASK':


VOID WaitActivity(VOID)

{
   (VOID) Wait(windmask|sermask);
   if (CheckIO((struct IORequest *)SerialRdIO)) {
   WaitIO((struct IORequest *)SerialRdIO);  /*Serial read complete-celanup*/
   ...do whatever you want when byte is read...
   } else {
   ...check for other reason Wait returned...
}


Note that you can save the value returned by wait and test it against windmask,
sermask or other masks to see which event occurred.

Also, sermask=1L<<SerialMP.mp_SigBit.
Simularily to windmask would be 1L<<Window.UserPort.mp_SigBit.

Let me know if this is unclear or you have further questions.