home *** CD-ROM | disk | FTP | other *** search
- /* getbt.c
- *
- * The Greenleaf Comm Library
- *
- * Copyright (C) 1985-1990 Greenleaf Software Inc. All Rights Reserved.
- *
- * unsigned asigetb( port, buffer, length, 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
- * unsigned int ticks; - The number of ticks to wait before returning
- * the ASBUFREMPTY code when no characters available.
- *
- * DESCRIPTION
- *
- * Transfers characters from receive queue to user buffer by repeatedly
- * calling asigetc(). Unlike asigetb(), this function will keep trying
- * to fill the buffer even when it detects no characters available.
- * It will keep trying to read characters in until it times 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.
- *
- * MODIFICATIONS
- */
- #include <stdio.h>
- #include "gf.h"
- #include "asiports.h"
-
- unsigned GF_CONV asigetb_timed( int port,
- char *buffer,
- unsigned int length,
- int ticks)
- {
- unsigned int rx_count;
-
- rx_count = 0;
-
- while ( length != 0 ) {
- _aserror = asigetc( port );
- if ( _aserror >= 0 ) {
- *buffer++ = ( char ) _aserror;
- rx_count++;
- length--;
- } else {
- if ( _aserror == ASBUFREMPTY ) {
- if ( ticks <= 0 )
- return( rx_count );
- ticks--;
- timer(1);
- } else
- return( rx_count );
- }
- }
- _aserror = ASSUCCESS;
- return( rx_count );
- }