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_CommPorts(_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<sizeof(buffer)));
printf("\nFrom port<<%s",buffer);
}
while (1);
}
else
printf("\n Unable to establish port!\n");
delete com; // VERY IMPORTANT! Delete SerialPort before exit...