EscapeCommFunction für Linux



  • Hallo,
    ich habe folgenden Code (hier aus dem Forum) vorliegen:

    #include <windows.h> 
    
    int main (void) 
    { 
        HANDLE hPort; 
    
        hPort =  CreateFile (TEXT("COM1"), 
            GENERIC_READ | GENERIC_WRITE, 
            0, 
            0, 
            OPEN_EXISTING, 
            0, 
            0); 
    
        EscapeCommFunction (hPort, SETRTS); // RTS setzten 
        Sleep (2000); 
        EscapeCommFunction (hPort, CLRRTS); // RTS rücksetzten 
        Sleep (2000); 
        EscapeCommFunction (hPort, SETRTS); // RTS setzten 
        Sleep (2000); 
    
        CloseHandle (hPort); 
    
        return (0); 
    }
    

    Dieser steuert die RTS-Leitung von Com1 in 2sec-Abständen auf +10V und auf -10V (nur mal so zu testzwecken, mal sehn ob's funzt).
    Jetzt die Frage: Wie realisiere ich sowas unter Linux. Gibt es da etwas ähnliches wie "EscapeCommFunction" (und in welcher Library liegt das)?
    Linux.h anstatt Windows.h? 😃

    Schon mal danke im Voraus!



  • Schau mal in "man tty_ioctl" unter "Modem control" nach.

    Modem control
    TIOCMGET int *argp
    get the status of modem bits.

    TIOCMSET const int *argp
    set the status of modem bits.

    TIOCMBIC const int *argp
    clear the indicated modem bits.

    TIOCMBIS const int *argp
    set the indicated modem bits.

    Bits used by these four ioctls:

    TIOCM_LE DSR (data set ready/line enable)
    TIOCM_DTR DTR (data terminal ready)
    TIOCM_RTS RTS (request to send)
    TIOCM_ST Secondary TXD (transmit)
    TIOCM_SR Secondary RXD (receive)
    TIOCM_CTS CTS (clear to send)
    TIOCM_CAR DCD (data carrier detect)
    TIOCM_CD see TIOCM_CAR
    TIOCM_RNG RNG (ring)
    TIOCM_RI see TIOCM_RNG
    TIOCM_DSR DSR (data set ready)

    Du müsstest also folgendes schreiben:

    #include <termios.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    
    int main(int argc, char *argv[])
    {
    	int fd=open("/dev/ttyS0",O_RDWR);
    	if(fd<0)
    		return(1);
    	int flags=TIOCM_RTS;
    //setze RST
    	ioctl(fd, TIOCMSET, &flags);//returns 0 on success
    //:
    //:
    	flags=0;
    //loesche RST
    	ioctl(fd, TIOCMSET, &flags);
    //:
    //:
    	close(fd);
    	return(0);
    }
    

    Es ist auch möglich nur bestimmte Flags zu setzen, und die anderen bei zu behalten...



  • wozu gibt es wohl die FAQ? 😡


Anmelden zum Antworten