home *** CD-ROM | disk | FTP | other *** search
- /*
- ** --- simple.c ---
- **
- ** EXAMPLE CODE: This example is meant to be the simpliest
- ** possible terminal emulator. Whatever is typed is sent out
- ** over the selected serial port, and whatever is received from
- ** the serial port is displayed on the screen.
- **
- ** This example program (not the PCL4C library) is donated to
- ** the Public Domain by MarshallSoft Computing, Inc. It is
- ** provided as an example of the use of the PCL4C.
- **
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <malloc.h>
- #include <dos.h>
- #include "allocseg.h"
- #include "pcl4c.h"
-
- #define FALSE 0
- #define TRUE !FALSE
- #define ESC 0x1b
-
-
- /*** Global Variables ***/
-
- int Port = COM1; /* Port COM1 */
- int BaudCode = Baud9600; /* Code for 9600 baud */
- int ErrorCheck(int Code);
-
- /*** main ***/
-
- void main(int argc, char *argv[])
- {
- char c;
- int i, rc;
- char *Ptr;
- if(argc!=2)
- {printf("Usage: SIMPLE port\n");
- exit(1);
- }
- /* get port number from command line */
- Port = atoi(argv[1]) - 1;
- if((Port<0) || (Port>3))
- {printf("Port must be COM1 to COM4\n");
- exit(1);
- }
- /* setup receive buffer */
- ErrorCheck( SioRxBuf(Port,AllocSeg(128),Size128) );
- /* set port parmameters */
- ErrorCheck( SioParms(Port,NoParity,OneStopBit,WordLength8) );
- /* reset the port */
- ErrorCheck( SioReset(Port,BaudCode) );
- printf("\nCOM%d @ 9600 Baud\n",1+Port);
- /* set DTR and RTS */
- ErrorCheck( SioDTR(Port,'S') );
- ErrorCheck( SioRTS(Port,'S') );
- printf("Enter terminal loop ( Type ESC to exit )\n");
- /* enter terminal loop */
- while(TRUE)
- {/* was key pressed ? */
- if(SioKeyPress())
- {i = SioKeyRead();
- if((char)i==ESC)
- {/* restore COM port status & exit */
- SioDone(Port);
- exit(1);
- }
- else SioPutc(Port,(char)i);
- } /* end if */
- /* any incoming over serial port ? */
- i = SioGetc(Port,0);
- if(i>-1) SioCrtWrite((char)i);
- } /* end while */
- } /* end main */
-
- int ErrorCheck(int Code)
- {/* trap PCL error codes */
- if(Code<0)
- {SioError(Code);
- SioDone(Port);
- exit(1);
- }
- return(0);
- } /* end ErrorCheck */