home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-4.ZIP / GSAMP / EXAMP01.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-21  |  1.1 KB  |  46 lines

  1. /*
  2.  *  EXAMP01.C
  3.  *
  4.  *  The Greenleaf Comm Library
  5.  *
  6.  *  Copyright (C) 1989 Greenleaf Software Inc.  All Rights Reserved.
  7.  *
  8.  *  This example program demonstrates the use of polled I/O.  A more fully
  9.  *  developed polled I/O example is found in the demo program POLL.C.
  10.  *  Note that asiopen() won't work properly with polled mode, as it makes
  11.  *  a call to asistart(), turning on interrupts.
  12.  *
  13.  */
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <asiports.h>
  17. #include <ibmkeys.h>
  18. #include <gf.h>
  19.  
  20. void main( void );
  21.  
  22. void main()
  23. {
  24.     int c;
  25.     int status;
  26.  
  27.     status = asifirst( COM1, BINARY | NORMALRX, 100, 100);
  28.     if ( status > ASSUCCESS )
  29.         status = asiinit( COM1, 1200L, P_NONE, 1, 8 );
  30.     if ( status < ASSUCCESS ) {
  31.         printf( "Failed to open the port.  Status = %d\n", status );
  32.         exit( 1 );
  33.     }
  34.     for ( ; ; ) {
  35.         if ( gfkbhit() ) {
  36.             c = getkey();
  37.             if ( c == ESC )
  38.                 exit( 0 );
  39.             asputc( COM1, c );
  40.         }
  41.         c = asgetc( COM1 );
  42.         if ( c >= ASSUCCESS )
  43.             putc( c, stdout );
  44.    }
  45. }
  46.