home *** CD-ROM | disk | FTP | other *** search
- Path: jane.cs.waikato.ac.nz!not-for-mail
- From: trigg@jane.cs.waikato.ac.nz (Len Trigg)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Simple Serial/Timer problem
- Date: 7 Feb 1996 04:07:31 GMT
- Organization: University of Waikato, New Zealand
- Sender: trigg@waikato.ac.nz
- Message-ID: <4f98i3$1e48@thebes.waikato.ac.nz>
- Reply-To: trigg@waikato.ac.nz
- NNTP-Posting-Host: jane.cs.waikato.ac.nz
- X-Newsreader: TIN [AMIGA 1.3 950726BETA PL0]
-
-
- Hi all. I'm hoping you can help me out with a small problem.
- I'm trying to write a program to talk to a Newton through the
- serial line. Below is my code to read a character from the
- serial device - I'm wanting it to timeout if no character is
- available. I thought the way to do this is to have a timer and
- then just wait until either the timer or the character came back,
- then cancel the request for the other. Unfortunately it does not
- work :-)
-
- The first time the routine gets called and a character is
- available it works. The second time it gets called, the signal
- for the both the character and the timer is set, even though a
- character is available immediately.
-
- There's probably something simple I'm not doing (as you can tell
- from the ugly code, I haven't really done much AmigaDOS
- programming)
-
-
- /* NewtonReadChar - Either get a single char from the Newton or timeout
- */
- LONG NewtonReadChar(char *achar)
- {
- LONG Result = NewtonOK;
- ULONG SignalSet;
-
- /* Ask for a byte from the serial line, or a timeout,
- * whichever comes first
- */
-
- /* Set command to TR_ADDREQUEST
- */
- TimerRequest->tr_node.io_Command = TR_ADDREQUEST;
- TimerRequest->tr_time.tv_secs = 5; /* 5 second timeout */
- TimerRequest->tr_time.tv_micro = 0;
- SendIO((struct IORequest *)TimerRequest);
-
- /* Request a single byte from the
- * serial line.
- */
- SerReadRequest->IOSer.io_Command = CMD_READ;
- SerReadRequest->IOSer.io_Length = 1;
- SerReadRequest->IOSer.io_Data = achar;
- SendIO((struct IORequest *)&SerReadRequest -> IOSer);
-
-
- /* Wait and see what we get */
- SignalSet = Wait(SIG_SERIAL | SIG_TIMER | SIGBREAKF_CTRL_C);
-
-
- /* Did we get a signal from the serial line?
- */
- if(SignalSet & SIG_SERIAL)
- {
-
- WaitIO((struct IORequest *)&SerReadRequest -> IOSer);
-
- /* Clear the timeout
- */
- AbortIO((struct IORequest *)TimerRequest);
- WaitIO((struct IORequest *)TimerRequest);
-
- /* Echo the single character to the logfile
- */
- if (logfile)
- fprintf(logfile, "%d %c ", *achar, *achar);
- }
-
-
- /* Did we get CTRL_C
- */
- if(SignalSet & SIGBREAKF_CTRL_C)
- {
- Result = NewtonBREAK;
-
- if (logfile)
- fprintf(logfile, "Received CTRL_C\n");
-
- /* Clear both the timeout and the serial request
- */
- AbortIO((struct IORequest *)TimerRequest);
- WaitIO((struct IORequest *)TimerRequest);
- AbortIO((struct IORequest *)&SerReadRequest -> IOSer);
- WaitIO((struct IORequest *)&SerReadRequest -> IOSer);
- }
-
-
- /* Did we get a timeout
- */
- if(SignalSet & SIG_TIMER)
- {
- Result = NewtonTIMEOUT;
-
- if (logfile)
- fprintf(logfile, "Received TIMER\n");
-
- WaitIO((struct IORequest *)TimerRequest);
-
- /* Abort the serial read request */
- AbortIO((struct IORequest *)&SerReadRequest -> IOSer);
- WaitIO((struct IORequest *)&SerReadRequest -> IOSer);
-
- }
-
- return Result;
- }
-
-
- --
- Len Trigg ===================================================
- Comp Sci Grad DoD#1334 trigg@cs.waikato.ac.nz
- Waikato Uni GPX250 http://www.cs.waikato.ac.nz/~trigg
- Finger trigg@jane.cs.waikato.ac.nz for PGP Public key
-