//***************************************************************************** // Kontrollprogramm für die I2C HoterModem // // g++ -o {prog} {prog.c} && ./prog /dev/ttyUSB0 //***************************************************************************** #include #include #include #include #include #include #include #include #include #include #include int fd = 0; int main(int argc, char** argv) { struct termios oldtios,options; int currstat = 0; if((argc < 2)||(argc > 3)) { printf("Fehler: Ungültige Parameter-Anzahl.\n"); printf("Aufruf:\n"); printf(" %s \n",argv[0]); return 1; } /* Das Device öffnen */ if((fd = open(argv[1], O_RDWR | O_NOCTTY | O_NDELAY)) < 0) { printf("Fehler: Device \"%s\" kann nicht geöffnet werden.\n", argv[1]); return 2; } tcgetattr(fd,&oldtios); options.c_cflag = 0; options.c_lflag = 0; options.c_iflag = 0; //options.c_cc = 0; fcntl(fd, F_SETFL, 0); if (tcgetattr(fd, &options) != 0) return(-1); printf ("\nVOR tcsetattr\n"); char cmd[20]; sprintf(cmd,"stty -a < %s",argv[1]); system(cmd); printf ("\n\n"); cfsetispeed(&options, B115200); /* setze 115200 bps */ cfsetospeed(&options, B115200); options.c_cflag &= ~PARENB; /* kein Paritybit */ options.c_cflag &= ~CSTOPB; /* 1 Stopbit */ options.c_cflag &= ~CSIZE; /* 8 Datenbits */ options.c_cflag |= CS8; options.c_cflag &= ~CRTSCTS; options.c_cflag |= (CLOCAL | CREAD); /* CD-Signal ignorieren */ /* Kein Echo, keine Steuerzeichen, keine Interrupts */ options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG | ECHOCTL); //options.c_oflag &= ~OPOST; /* setze "raw" Input */ options.c_oflag = OPOST | ONLCR; options.c_oflag &= ~IGNPAR; options.c_iflag &= ~(IXON | IXOFF | IXANY | IGNPAR); //options.c_iflag &= ~IGNPAR; //options.c_lflag &= ~IGNPAR; options.c_iflag = IGNPAR | ICRNL; options.c_cc[VMIN] = 0; /* warten auf min. 0 Zeichen */ options.c_cc[VTIME] = 10; /* Timeout 10 Sekunden */ tcflush(fd,TCIOFLUSH); if (tcsetattr(fd, TCSAFLUSH, &options) != 0) return(-1); char buffer[8]; printf ("\nNach tcsetattr\n"); sprintf(cmd,"stty -a < %s",argv[1]); system(cmd); printf ("\n\n"); // Version buffer[0]=0x0C; buffer[1]=0x00; buffer[2]=0x04; printf("-Eingabe---------------------\n"); int i; for (i=0; i<3; i++ ) { printf("0x%02x ",buffer[i]); } printf("\n"); printf("-----------------------------\n"); // buffer schreiben i = write(fd,buffer,3); //ist das OK? printf("geschrieben: %i\n",i); printf("-----------------------------\n"); int bb = 0; int x = 0; bool cmdOK=false; char cods[10]; /* ABHIER? Lese des Gerätes, antwort solte sein: 0x1A, 0x03, 0x02, 0x00, 0x00, 0x04 (0x04 sollte EOT sein) aber was ist da falsch? */ do { //printf("\n"); if((bb = read( fd, &cods[x], sizeof( cods )-x )) > 0) //if((bb = read( fd, &cods, 5 )) > 0) { for (i=x;i