Quellcode zur Steuerung von DTR am seriellen Port

#include <termios.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>

main (){
    // open the serial device
    int fd;
    fd = open("/dev/ttyUSB0", O_RDWR | O_NONBLOCK);

    // adjust serial communuication parameters
    struct termios ComParams;
    tcgetattr(fd, &ComParams);
    ComParams.c_cflag &= ~CBAUD; // baud rate = 9600 bd
    ComParams.c_cflag |= B9600;
    tcsetattr( fd, TCSANOW, &ComParams );

    int state;

    // get current state
    ioctl(fd, TIOCMGET, &state);

    // switch on
    state &= ~TIOCM_DTR;
    ioctl(fd, TIOCMSET, &state);

    usleep(8000000);

    // switch off
    state |= TIOCM_DTR;
    ioctl(fd, TIOCMSET, &state);

}