RS232 Verbindung abbauen und wieder aufbauen
-
Hallo,
wie kann ich eine RS232 Verbindung abbauen, so dass die es Gegenstation merkt und wieder aufbauen.
Habe es wie folgt versucht. DTR und RTS auf 0 setzten. Dann warten, bis DSR und DCD nicht mehr gesetzt sind. Danach wieder DTR und RTS setzen und warten bis DSR und CTS gesetzt sind.unsigned int status; ioctl(m_Tty_fd, TIOCMGET, &status); // Clear DTR / RTS status &= ~TIOCM_DTR; status &= ~TIOCM_RTS; ioctl(m_Tty_fd, TIOCMSET, &status); // wait until DSR / DCD cleared timeout = time(NULL) + 2; do { if(time(NULL) > timeout) break; usleep(200000); // wait 200 ms ioctl(m_Tty_fd, TIOCMGET, &status); }while( status & (TIOCM_DSR|TIOCM_CD) ); if( status & TIOCM_DSR ) { status |= (TIOCM_DTR|TIOCM_RTS); ioctl(m_Tty_fd, TIOCMSET, &status); return -1; } if( status & TIOCM_CD ) { status |= (TIOCM_DTR|TIOCM_RTS); ioctl(m_Tty_fd, TIOCMSET, &status); return -1; } // set DTR / RTS ioctl(m_Tty_fd, TIOCMGET, &status); status |= (TIOCM_DTR|TIOCM_RTS); ioctl(m_Tty_fd, TIOCMSET, &status); // wait until DSR / CTS set; timeout = time(NULL) + 2; do { if(time(NULL) > timeout) break; usleep(200000); ioctl(m_Tty_fd, TIOCMGET, &status); }while( (status & (TIOCM_DSR|TIOCM_CTS)) != (TIOCM_DSR|TIOCM_CTS) ); if( !(status & TIOCM_DSR) ) { return -1; } if( !(status & TIOCM_CTS) ) { return -1; }
Klappt aber nciht. Das DSR und DCD bleiben auf 1.
Wie kann man es sonst machen.
Bin für alle Tipps dankbar.Gruß
dziuba
-
Ich könnte mir vorstellen, dass der Treiber für die COM-Ports (Modul "serial.o") die Leitungen automatisch wieder in den Ausgangszustand versetzt, da sie für Hardware-Handshake benötigt werden. Vielleicht lässt das Modul das manuelle Setzen dieser Leitungen auch garnicht zu.
Eine Alternative wäre das direkte Ansprechen des 16550 UART-Bausteins mit ioperm() und out_b(). Das erfordert jedoch (zeitweise) root-Rechte für das Programm. Wie solche Port-Zugriffe unter Linux programmiert werden, findest du unter anderem hier
Martin