#include #include #include #include #include #include #include #include #include #define TC0 "/dev/usb/ttyUSB1" /* Set to _your_ port */ //#define TC0 "/dev/ttyS0" /* Set to _your_ port */ static struct termios pots; int pfda; /* restore original terminal settings on exit */ void cleanup_termios(int signal) { tcsetattr(pfda, TCSANOW, &pots); exit(0); } void send() { int i; char cmd[10]; sprintf(cmd,"I"); write(pfda,&cmd,strlen(cmd)); usleep(10); read(pfda,&cmd,strlen(cmd)); printf("%s:",cmd); sprintf(cmd,"1"); write(pfda,&cmd,strlen(cmd)); usleep(10); read(pfda,&cmd,strlen(cmd)); printf("%s: ",cmd); sprintf(cmd,"%x",0x0d); write(pfda,&cmd,strlen(cmd)); read(pfda,&cmd,strlen(cmd)); usleep(10); printf("%s \n",cmd); usleep(10); usleep(100); read(pfda,&cmd,2); // printf("%s",cmd); char* tmpPtr=(char*)&cmd; usleep(100); // read(pfda,&cmd,1); // printf("%s",cmd); read(pfda,cmd,5); printf("%s\n",cmd); // tmpPtr++; // tmpPtr++; // // read(pfda,tmpPtr++,1); // // printf("%s\n",cmd); // read(pfda,tmpPtr++,1); // printf("%s\n",cmd); // read(pfda, tmpPtr,2); // printf("%s\n\n",cmd); int blub=atoi((char*)&cmd); printf("%i\n",blub); } int main(int argc, char *argv[]) { struct termios pts; /* termios settings on port */ struct sigaction sact;/* used to initialize the signal handler */ char key; /* Section to configure TC0 port */ pfda = open( TC0, O_RDWR); if (pfda < 0) { perror("problem opening TC0 port"); exit(2); } /* modify the port configuration */ tcgetattr(pfda, &pts); pots = pts; pts.c_lflag &= ~ICANON; pts.c_lflag &= ~(ECHO | ECHOCTL | ECHONL); pts.c_cflag |= HUPCL; pts.c_cflag &= ~PARENB; pts.c_cflag &= ~PARODD; pts.c_cc[VMIN] = 1; pts.c_cc[VTIME] = 0; pts.c_oflag &= ~ONLCR; pts.c_iflag &= ~ICRNL; cfsetospeed(&pts, B9600); /* All this sets the port to UPS defaults */ /* set the signal handler to restore the old * termios handler */ sact.sa_handler = cleanup_termios; sigaction(SIGHUP, &sact, NULL); sigaction(SIGINT, &sact, NULL); sigaction(SIGPIPE, &sact, NULL); sigaction(SIGTERM, &sact, NULL); tcsetattr(pfda, TCSANOW, &pts); send(); // read(); tcsetattr(pfda, TCSANOW, &pots); exit(0); }