#include #include #include #include #include #include #include #include /* rs232io.c with no CR LF after output * configuration: edit to suit your needs * could be done at runtime by reading from a file */ //#ifdef OLD_PTY /* may be set with preprocessor flags */ //#ifndef DEVICE //#define DEVICE "/dev/ttyS0" //#define DEVICE "/dev/ttyS1" //#endif //#endif //#define BAUDRATE B115200 #define BAUDRATE B9600 //#define ARGPOSTFIX "\r\n" #define ARGPOSTFIX "" void send(int fd,const char *buf,int len) { int c = write(fd,buf,len); if(c != len) { fprintf(stderr,"*** write: %s\n",strerror(errno)); exit(1); } } int main(int argc,char* argv[]) { int fd; struct termios oldtio,newtio; char *device; /* force device to this value*/ device="/dev/ttyS1"; fd = open(device,O_RDWR); if(fd < 0) { fprintf(stderr,"*** open %s: %s\n",device,strerror(errno)); exit(-1); } /* set correct baudrate, etc ... * (WARNING: doesn't work because the kernel has no support for that yet) */ tcgetattr(fd,&oldtio); /* save current port settings */ bzero(&newtio,sizeof(newtio)); newtio.c_cflag = (CS8 | CREAD | CLOCAL | CRTSCTS); newtio.c_lflag = 0; newtio.c_iflag = IGNPAR; newtio.c_oflag = 0; cfsetospeed(&newtio,BAUDRATE); newtio.c_cc[VTIME] = 0; /* inter-character timer unused */ newtio.c_cc[VMIN] = 1; /* blocking read until 1 char received */ tcflush(fd,TCIFLUSH); tcsetattr(fd,TCSANOW,&newtio); if(argc > 1) { int postlen = strlen(ARGPOSTFIX); int i; for(i = 1; i < argc; i++) { send(fd,argv[i],strlen(argv[i])); if(postlen) send(fd,ARGPOSTFIX,postlen); } } else { char buf[512]; while(1) { int count = fread(buf,1,sizeof(buf),stdin); if(count == 0) { if(feof(stdin)) break; fprintf(stderr,"*** read: %s\n",strerror(errno)); return 1; } #if 0 { int i; fprintf(stderr,"got %d bytes:",count); for(i = 0; i < count; i++) fprintf(stderr," %d(0x%02x)",buf[i],buf[i]); fprintf(stderr,"\n"); } #endif send(fd,buf,count); } } return 0; }