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

  1.  
  2. #include "xc.h"
  3. int a_count = 0;
  4. int send_count = 0;
  5. int msr = 0;
  6. int lsr = 0;
  7. int hits[4] = {0,0,0,0};
  8. int msr_in[100] = {0};
  9. int lsr_in[100] = {0};
  10. int i;
  11.  
  12. main()
  13. {
  14. int ch;
  15. long int xc_test();
  16. int far event_func();
  17. printf("Using setport for multiport board 0, 3F8Hex, COM3\n");
  18.  
  19.  
  20. /* Initialize XCOMMS and set up COM3 */
  21.     xc_entr(8);
  22.    setport(0x3f8,1,4,COM3,0);
  23.     xc_link(COM3,0);
  24.     xc_init(COM3,BAUD2400,NOPAR,DATA8,STOP1);
  25.  
  26. /* Set up an event handler for receive and transmit characters */
  27.     xc_set_int_exit(2,0xf,event_func);
  28. /* Loop sending keys pressed and printing keys received */
  29.     while(1)
  30.         {
  31.         if(xck_keyt())
  32.             {
  33.             ch = xck_getc();
  34.             if((unsigned char) ch == 'Q')        /* Hit Q to quit */
  35.                 break;
  36.             xc_putc(COM3, ch);
  37.             }
  38.         if(xc_test(COM3))
  39.             {
  40.             ch = xc_getc(COM3);
  41.             xcv_wtty(ch);
  42.             }
  43.         }
  44.  
  45. /*     Disable event handler by supplying a mask of zero */
  46.     xc_set_int_exit(2,0,event_func);
  47.     xc_exit();
  48.     printf("\na_count = %d, send_count = %d\n",a_count, send_count);
  49.    printf("port hits = %d %d %d %d\n",hits[0],hits[1],hits[2],hits[3]);
  50.    printf("msr count = %d, lsr count = %d\n",msr,lsr);
  51.    for(i=0;lsr_in[i] != 0;i++)
  52.       {
  53.       printf("%x\n",lsr_in[i]);
  54.       }
  55. }
  56.  
  57. int far event_func(int port, int mask, int ch)
  58. {
  59.    hits[port]++;
  60.     if(mask == 1)    /* receive? */
  61.         {
  62.         if((char) ch == 'A')    /* If = A, increment count */
  63.             {            /* and change to a B.      */
  64.             a_count++;
  65.             return('B');
  66.             }
  67.         }
  68.     else            /* must be send */
  69.       if(mask == 2)
  70.            send_count++;
  71.       else
  72.       if(mask == 3)
  73.          msr++;
  74.       else
  75.       if(mask == 4)
  76.       {   
  77.          lsr_in[lsr] = ch;
  78.          lsr++;
  79.          }
  80.  
  81.  
  82.     return(0);
  83. }
  84.  
  85.