home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_01 / 1n01058a < prev    next >
Text File  |  1990-05-17  |  2KB  |  62 lines

  1. *****Listing 2*****
  2.  
  3. /*
  4.  *  TERM.C
  5.  *
  6.  *  Copyright (C) Mark R. Nelson 1990
  7.  *
  8.  * This file contains the main() procedure for a skeletal
  9.  * terminal emulator program.  This code has no bells or
  10.  * whistles, as it exists only to exercise and test the
  11.  * RS-232 interface code.  Keyboard input is done using the
  12.  * MS-DOS specific compiler calls to kbhit() and getch().
  13.  * Screen output is done using standard I/O calls to
  14.  * stdout.
  15.  *
  16.  * To build this program in Turbo C:
  17.  *
  18.  * tcc -w term.c com.c
  19.  *
  20.  * To build this program in Quick C:
  21.  *
  22.  * qcl -W3 term.c com.c
  23.  */
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <conio.h>
  27. #include "com.h"
  28.  
  29. main()
  30. {
  31.     PORT *port;
  32.     int c;
  33.  
  34.     port = port_open( COM1_UART, COM1_INTERRUPT );
  35.     if ( port== NULL ) {
  36.         printf( "Failed to open the port!\n" );
  37.         exit( 1 );
  38.     }
  39.     port_set( port, 2400L, 'N', 8, 1 );
  40. /*
  41.  * The program stays in this loop until the user hits the
  42.  * Escape key.  The loop reads in a character from the
  43.  * keyboard and sends it to the COM port.  It then reads
  44.  * in a character from the COM port, and prints it on the
  45.  * screen.
  46.  */
  47.     for ( ; ; ) {
  48.         if ( kbhit() ) {
  49.             c = getch();
  50.             if ( c == 27 )
  51.                 break;
  52.             else
  53.                 port_putc( (unsigned char) c, port );
  54.         }
  55.         c = port_getc( port );
  56.         if ( c >= 0 )
  57.             putc( c, stdout );
  58.     }
  59.     port_close( port );
  60.     return( 0 );
  61. }
  62.