home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / PCL4C30.ZIP / NORESET.C < prev    next >
Text File  |  1992-01-20  |  2KB  |  87 lines

  1. /*
  2. **
  3. **        ---  noreset.c ---
  4. **
  5. **   EXAMPLE CODE: Gain control w/o resetting UART.
  6. **
  7. **   (1) Start your communications program such as PROCOMM
  8. **   (2) Select "DOS gateway" to get the DOS prompt.
  9. **   (3) Start this program. You will gain control of the
  10. **       COM port without resetting the UART or dropping the
  11. **       modem carrier.
  12. **   (4) When done, exit this program, then type EXIT to
  13. **       return to MSDOS.
  14. **
  15. **   For more information, see documentation.
  16. **
  17. **   This example program (not the PCL4C library) is donated to
  18. **   the Public Domain by MarshallSoft Computing, Inc. It is
  19. **   provided as an example of the use of the PCL4C.
  20. **
  21. */
  22.  
  23. #include <stdio.h>
  24. #include "pcl4c.h"
  25.  
  26. #define FALSE 0
  27. #define TRUE !FALSE
  28. #define ESC 0x1b
  29.  
  30. /*** Global Variables ***/
  31.  
  32. int Port;
  33. char RxBuf[16];       /* PCL4C receive buffer  */
  34.  
  35. /*** Main ***/
  36.  
  37. main(argc,argv)
  38. int argc;
  39. char *argv[];
  40. {
  41.  char c;
  42.  char *ptr;
  43.  int i, rc;
  44.  /* get comm port */
  45.  if(argc!=2)
  46.    {printf("Usage: 'NORESET port' where port is 1,2,3, or 4\n");
  47.     exit(1);
  48.    }
  49.  ptr = argv[1];
  50.  if((*ptr<'1')||(*ptr>'4'))
  51.     {printf("COM port must be 1 to 4, not %s\n",ptr);
  52.      exit(1);
  53.     }
  54.  Port = atoi(ptr) - 1;
  55.  printf("NORESET: COM%d\n",1+Port);
  56.  /* setup receive buffer */
  57.  ErrorCheck( SioRxBuf(Port,RxBuf,Size16) );
  58.  /* 'reset' the port */
  59.  ErrorCheck( SioReset(Port,NORESET) );
  60.  printf("Enter terminal loop ( COM%d )\n",1+Port);
  61.  printf("Type ESC to quit !\n");
  62.  /* enter terminal loop */
  63.  while(TRUE)
  64.      {/* was key pressed ? */
  65.       if(SioKeyPress())
  66.           {i = SioKeyRead();
  67.            if((char)i==ESC)
  68.               {/* restore COM port status & exit */
  69.                SioDone(Port);
  70.                exit(1);
  71.               }
  72.            else SioPutc(Port,i);
  73.           } /* end if */
  74.       /* any incoming over serial port ? */
  75.       i = SioGetc(Port,0);
  76.       if(i>-1) SioCrtWrite(i);
  77.      } /* end while */
  78. } /* end main */
  79.  
  80. int ErrorCheck(Code)
  81. int Code;
  82. {/* trap PCL error codes */
  83.  if(Code<0)
  84.      {SioError(Code);
  85.       exit(1);
  86.      }
  87. } /* end ErrorCheck */