home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / asycnch / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-01  |  899 b   |  62 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include "asynch.h"
  4. void Beep(void);
  5. int ctrlc(void)
  6. {
  7.     cputc(COM2,3);
  8.     return 1;
  9. }
  10. main()
  11. {
  12.     int RetCode, c;
  13.     if((RetCode = copen(COM2,2048,2400,NONE,DATA8,STOP1,0,0,0)) != 0)
  14.     {
  15.         printf("copen failed: Code: %d\n",RetCode);
  16.         return -1;
  17.     }
  18.     clrscr();
  19.     ctrlbrk(ctrlc);
  20.     fclose(stdout);
  21.     while(1)
  22.     {
  23.         if (kbhit())
  24.         {
  25.             c = getch();
  26.             if (c == 0)
  27.             {
  28.                 switch(getch()&0xFF)
  29.                 {
  30.                     case 68 :
  31.                         cclose(COM2);
  32.                         return 0;
  33.                     case 35 :
  34.                         ControlDTR(COM2,OFF);
  35.                         delay(500);
  36.                         ControlDTR(COM2,ON);
  37.                         break ;
  38.                     case 48 :
  39.                         SendBreak(COM2);
  40.                         break ;
  41.                     default :
  42.                         Beep();
  43.                         break;
  44.                 }
  45.                 
  46.             }
  47.             else
  48.                 cputc(COM2,c);
  49.         }
  50.         if ((c = cgetc(COM2)) >= 0)
  51.             fprintf(stderr,"%c",c);
  52.     }
  53. }
  54. void Beep()
  55. {
  56.     sound(1000);
  57.     delay(250);
  58.     nosound();
  59. }
  60.  
  61.     
  62.