home *** CD-ROM | disk | FTP | other *** search
- /* wgetbt.c
- *
- * The Greenleaf Comm Library
- *
- * Copyright (C) 1989-90 Greenleaf Software Inc. All Rights Reserved.
- *
- * unsigned asiwgetb_timed( port, buffer, length, stat, ticks)
- * int port; - Port 0..MAX_PORT-1
- * char *buffer; - Points to buffer that is to receive characters
- * unsigned length; - Maximum number of characters that can be received
- * char *stat; - Pointer to destination status buffer
- * int ticks; - The number of ticks to wait before timing out.
- *
- * DESCRIPTION
- *
- * Transfers characters from receive queue to user buffer by repeatedly
- * calling asiwgetc(). If the buffer is empty, the routine will wait
- * around for some more characters until the tick timer runs out.
- *
- * SIDE EFFECTS
- * none
- *
- * RETURNS
- * returns the number of characters SUCCESSFULLY transferred. The global
- * variable _aserror can be examined to determine if an error was detected.
- * _aserror == 0 if no errors were detected. If the receive queue becomes
- * empty before the entire user buffer is filled _aserror will be set to
- * ASBUFREMPTY.
- *
- * Value Meaning
- * ------- --------
- * ASSUCCESS port initialized (no error)
- * ASINVPORT Requested port is out of range
- * ASNOTSETUP Requested port not setup with asifirst()
- * ASBUFREMPTY Receive buffer went empty before length characters
- * were transferred.
- * ASNOWIDERX Wide Track receive not enabled for this channel.
- *
- * MODIFICATIONS
- *
- */
- #include <stdio.h>
- #include "gf.h"
- #include "asiports.h"
-
- unsigned int GF_CONV asiwgetb_timed( int port,
- char *buffer,
- unsigned int length,
- char *stat,
- int ticks )
- {
- unsigned rx_count = 0;
- struct PORT_TABLE *p;
-
- p = _aschkcnl( port ) ;
- if ( p == NULL )
- return( 0 );
-
- if( p->chmode_bits.is_rxerror == 0 ) {
- _aserror = ASNOWIDERX;
- return(0);
- }
-
- while ( length != 0 ) {
- _aserror = asiwgetc( port, stat );
- if ( _aserror >= 0 ) {
- *buffer++ = ( char ) _aserror;
- rx_count++;
- length--;
- if ( stat != NULL )
- stat++;
- } else {
- if ( _aserror == ASBUFREMPTY ) {
- if ( ticks <= 0)
- return( rx_count );
- ticks--;
- timer(1);
- } else
- return( rx_count );
- }
- }
-
- _aserror=ASSUCCESS;
- return(rx_count);
- }
-