//============================================================================ // // SPPDEMO.CPP // // Demo program for Serial++ Library SPP.LIB Ver. 1.10 // // Copyright (c) 1991,1992 Cortlandt Technologies, All rights reserved. // // Cortlandt Technologies, P.O. Box 195, Pleasantville NY 10570 // // Please direct all inquiries to the above address, // or via Compuserve: 71066,155 // //============================================================================ #include #include #include #include #include #include "serial.h" //============================================================================ // // Setup up command line defaults CommPort cp = COM_1; // COM1: Baud bd = B_1200; // 1200 baud DataBits db = D_8; // 8 data bits Parity ps = P_N; // no parity StopBits sb = S_1; // 1 stop bit //============================================================================ // // Globals char buffer[255]; // buffer for messages SerialPort *com; // pointer to a SerialPort -- used in // main routine to establish port //============================================================================ // // Prototypes of functions in this file StopBits cl_StopBits(const char *cltok); Parity cl_Parity(const char *cltok); DataBits cl_DataBits(const char *cltok); Baud cl_Baud(const char *cltok); CommPort cl_CommPort(const char *cltok); void printUsage(void); //============================================================================ // // Main program // //---------------------------------------------------------------------------- void main(void) { unsigned char cc; // Banner printf("\n SPPDEMO - Demo program for SPP.LIB\n Copyright (c) 1991 Cortlandt Technologies, All rights reserved.\n\n Type $$$ at prompt or press Ctrl-Break to exit.\n"); // parse command line switch (_argc) // depending on number of { // command line arguments case 6: sb = cl_StopBits(_argv[5]); // override stop bits case 5: ps = cl_Parity(_argv[4]); // override parity case 4: db = cl_DataBits(_argv[3]); // override data bits case 3: bd = cl_Baud(_argv[2]); // override baud case 2: cp = cl_CommPort(_argv[1]); // override port break; default: // bad command line - printUsage(); // print help and exit exit(0); } // establish port com = new SerialPort(cp,bd,db,ps,sb); // taking defaults for buffer size // and break trapping: see SERIAL.H if (com->lineOK()) { // loop sending messages back and forth do { printf("\n To port>>"); gets(buffer); // string "$$$" causes program to exit if (strcmp(buffer,"$$$")==0) break; // send message out port com->outstr(buffer); // the message as a string com->outbyte(0x0d); // add a carriage return // clear buffer to use for incoming message memset(buffer,'\0',sizeof(buffer)); // read port until quiet for 2 seconds int ii=0; while ( (com->inbyte((unsigned char)buffer[ii++],2000)) &&(ii