home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / communic / encom100 / start.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-04  |  2.2 KB  |  80 lines

  1. /****************************************************************************/
  2. /*                                                                                                                                                    */
  3. /* START.C                                                                                                                                   */
  4. /*                                                                                                                                                    */
  5. /* This little program shows how easy it is to begin using EnCom!  If you   */
  6. /* have ANSI.SYS loaded, this program becomes a nice ANSI terminal -- and   */
  7. /* all in only a few lines of code!                                         */
  8. /*                                                                                                                                                    */
  9. /****************************************************************************/
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include "encom.h"
  13.  
  14. PORT Port;
  15.  
  16. /*********/
  17. /* ~main */
  18. /*       *********************************************************************/
  19. /*****************************************************************************/
  20. main( int argc, char *argv[] )
  21. {
  22.     int port = COM1;
  23.     long baud = 2400L;
  24.     int c, end_flag = 0, echo = 0;
  25.  
  26.     if( argc >= 2 )
  27.     {
  28.         switch(argv[1][0])
  29.         {
  30.             case '1': port = COM1; break;
  31.             case '2': port = COM2; break;
  32.             case '3': port = COM3; break;
  33.             case '4': port = COM4; break;
  34.         }
  35.     }
  36.     if( argc >= 3 )
  37.         baud = atol(argv[2]);
  38.     if( com_port_create(port, baud,'N',8,1, 2048, 2048, &Port) < 0 )
  39.     {
  40.         printf("Cannot create COM port");
  41.         return(0);
  42.     }
  43.     init_clock(0x3333);
  44.     init_ctrlc_hdlr();
  45.     printf("\r\nESC to quit - Ctrl-E to toggle Echo\r\n");
  46.     printf("To use another port, type: start [1-4] [baud_rate]\r\n");
  47.     printf("If ansi.sys is loaded, this will work as an ANSI terminal\r\n");
  48.     com_232_ctrl(ON, DTR | RTS | OUT2, &Port);
  49.     while( !end_flag )
  50.     {
  51.         if( (c = com_getc(&Port)) != -1 )                                /* get any characters        */
  52.             putchar(c);
  53.         if( kbhit() )
  54.         {
  55.             switch(c = getch())                                                        /* get the character        */
  56.             {
  57.                 case 27: end_flag = 1; break;                                /* esc to quit                */
  58.                 case  5: echo = !echo; break;                                /* ctrl-e is echo             */
  59.                 case 30:                                                                        /* translate ctrl-c            */
  60.                     if ( echo )
  61.                         putchar(3);
  62.                     com_putc(3, &Port);
  63.                     break;
  64.                 default:
  65.                     if( echo )
  66.                         putchar(c);
  67.                     com_putc(c, &Port);
  68.                     break;
  69.             }
  70.         }
  71.     }
  72.     end_clock();
  73.     end_ctrlc_hdlr();
  74.     com_port_destroy(&Port);
  75.     return(1);
  76. }
  77. /*** end of main ***/
  78.  
  79. /**** END OF FILE ****/
  80.