/* Copyright (C) Magna Carta Software, Inc. 1990. All Rights Reserved C COMMUNICATIONS TOOLKIT COMMIO.C -- Basic serial I/O functions (no data translation) */ #define CCT_DEVELOPMENT #if (defined(CCTW) || defined(_WINDOWS)) #include #endif #include #include #include /* C_WAITC -- Waits a specified time for a character to be received and then returns: c -- character received; EOF -- if no character received; USER_CANCELLED -- if abort key pressed. Note: 1) Duration is measured in milliseconds (e.g. 500 = 1/2 second); 2) Maximum value of duration approx = 1 min (60000 ms). Call repeatedly for longer delays; */ short c_waitc(COMM_PORT *p, short ch, WORD duration) { WORD ticks, ticksnow; short inchar; /* CONVERT MILLISECONDS TO 18ths OF A SECOND */ ticks = max(duration/55, 1); ticksnow = peek(REAL_SEG, LOW_TIME); /* initialize reference count */ _enable(); /* CHECK UART FOR BYTE READY */ while (ticks > 0) { if (is_key(p->abort_key)) return(USER_CANCELLED); /* IF A CHARACTER IS READY RETURN IT */ if ((*p->rxstat)(p)) { inchar = (*p->c_read)(p); if ((ch == EOF) || (inchar == ch)) return (inchar); } if ((WORD) peek(REAL_SEG, LOW_TIME) != ticksnow) { /* compare new count to old */ ticksnow = peek(REAL_SEG, LOW_TIME); /* get new reference point */ ticks--; /* and reduce timeout */ } } return (EOF); /* timed out -- no byte received */ }