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

  1. /*
  2. **                ---  simple.c ---
  3. **
  4. **  EXAMPLE CODE: This example is meant to be the simpliest
  5. **  possible terminal emulator. Whatever is typed is sent out
  6. **  over the selected serial port, and whatever is received from
  7. **  the serial port is displayed on the screen.
  8. **
  9. **  This example program (not the PCL4C library) is donated to
  10. **  the Public Domain by MarshallSoft Computing, Inc. It is
  11. **  provided as an example of the use of the PCL4C.
  12. **
  13. */
  14.  
  15. #include <stdio.h>
  16. #include "pcl4c.h"
  17.  
  18. #define FALSE 0
  19. #define TRUE !FALSE
  20. #define ESC 0x1b
  21.  
  22. /*** Global Variables ***/
  23.  
  24. int Port = 0;             /* COM port # 0 ( COM1 ) */
  25. int BaudCode = Baud2400;  /* Code for 2400 baud  */
  26. char RxBuf[16];       /* PCL_C receive buffer  */
  27.  
  28. /*** Main ***/
  29.  
  30. main()
  31. {
  32.  char c;
  33.  int i, rc;
  34.  /* setup receive buffer */
  35.  ErrorCheck( SioRxBuf(Port,RxBuf,Size16) );
  36.  /* set port parmameters */
  37.  ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
  38.  /* reset the port */
  39.  ErrorCheck( SioReset(Port,BaudCode) );
  40.  printf("Enter terminal loop ( COM1 @ 2400 Baud )\n");
  41.  printf("Type ESC to quit !\n");
  42.  /* enter terminal loop */
  43.  while(TRUE)
  44.      {/* was key pressed ? */
  45.       if(SioKeyPress())
  46.           {i = SioKeyRead();
  47.            if((char)i==ESC)
  48.               {/* restore COM port status & exit */
  49.                SioDone(Port);
  50.                exit(1);
  51.               }
  52.            else SioPutc(Port,i);
  53.           } /* end if */
  54.       /* any incoming over serial port ? */
  55.       i = SioGetc(Port,0);
  56.       if(i>-1) SioCrtWrite(i);
  57.      } /* end while */
  58. } /* end main */
  59.  
  60. int ErrorCheck(Code)
  61. int Code;
  62. {/* trap PCL error codes */
  63.  if(Code<0)
  64.      {SioError(Code);
  65.       exit(1);
  66.      }
  67. } /* end ErrorCheck */