home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 11 / 11.iso / n / n002 / 4.ddi / DEMOS.ZIP / TESTEC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  1.1 KB  |  56 lines

  1.  
  2. #include "xc.h"
  3. int a_count = 0;
  4. int send_count = 0;
  5.  
  6. main()
  7. {
  8. int ch;
  9. long int xc_test();
  10. int far event_func();
  11.  
  12. /* Initialize XCOMMS and set up COM1 */
  13.     xc_entr(8);        
  14.     xc_link(COM1,0);
  15.     xc_init(COM1,BAUD2400,NOPAR,DATA8,STOP1);
  16.  
  17. /* Set up an event handler for receive and transmit characters */
  18.     xc_set_int_exit(COM1,3,event_func);
  19. /* Loop sending keys pressed and printing keys received */
  20.     while(1)
  21.         {
  22.         if(xck_keyt())
  23.             {
  24.             ch = xck_getc();
  25.             if((unsigned char) ch == 'Q')        /* Hit Q to quit */
  26.                 break;
  27.             xc_putc(COM1, ch);
  28.             }
  29.         if(xc_test(COM1))
  30.             {
  31.             ch = xc_getc(COM1);
  32.             xcv_wtty(ch);
  33.             }
  34.         }
  35.  
  36. /*     Disable event handler by supplying a mask of zero */
  37.     xc_set_int_exit(COM1,0,event_func);
  38.     xc_exit();
  39.     printf("a_count = %d, send_count = %d",a_count, send_count);
  40. }
  41.  
  42. int far event_func(int port, int mask, int ch)
  43. {
  44.     if(mask == 1)    /* receive? */
  45.         {
  46.         if((char) ch == 'A')    /* If = A, increment count */
  47.             {            /* and change to a B.      */
  48.             a_count++;
  49.             return('B');
  50.             }
  51.         }
  52.     else            /* must be send */
  53.         send_count++;
  54.     return(0);
  55. }
  56.