/*Serial.c serial send/receive program */ /*! @defgroup Serial e12_serial - Serial.c This module is used to build the e12_serial application. The e12_serial program is used to set the baud rate of the 37e12's serial ports and to send/receive data over them. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define ARGCHECK(num){if(argc!=num){printf("invalid number of arguements\n");help();return -1;}} #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}} static int help(void) { const char *help_table = "**************************************************** *E12_Serial * *Nathan Z. Gustavson * *Emac.inc * *"__DATE__" * *usage: * *E12_Serial device 422/232 r/w/b chars/string/baud * * * *ex: * *E12_Serial /dev/37e12 232 r 2 * *reads 2 characters from the 232 port * * * *E12_Serial /dev/37e12 422 w hello * *writes hello to the 422 port * * * *E12_Serial /dev/37e12 232 b 9600 * *sets the baud rate of the 232 port to zero * ****************************************************\n"; printf("%s",help_table); return 0; } int main(int argc, char *argv[]) { int fd; int device=0; int command; int chars; char *string=NULL; int baud; Cop_Data *Cop; unsigned char buffer[100]; int charnum; ARGCHECK(5); OPENDEV(fd,argv[1]); if(!strcmp("232",argv[2])) device = RS232PORT; else { if(!strcmp("422",argv[2])) device = RS422PORT; else { printf("invalid device, %s\n",argv[2]); help(); } } switch(command=*argv[3]) { case 'r':/*read command*/ chars = strtoul(argv[4],NULL,0); Cop = CopDeviceCreate(0); switch(device) { case RS232PORT: string = Cop->RS232_string; break; case RS422PORT: string = Cop->RS422_string; break; } while(strlen(string)