X-Git-Url: https://git.realraum.at/?p=svn42.git;a=blobdiff_plain;f=reset_tty%2Freset_tty.c;fp=reset_tty%2Freset_tty.c;h=bf1c0a01a72ac26615b34979f6cc0ae7f9eb5a74;hp=0000000000000000000000000000000000000000;hb=8682625b18daa7a9f6ae5d3fff47e9e3158d19ef;hpb=75d3e955b7445b15c9c25a425e888ae76af6c3db diff --git a/reset_tty/reset_tty.c b/reset_tty/reset_tty.c new file mode 100644 index 0000000..bf1c0a0 --- /dev/null +++ b/reset_tty/reset_tty.c @@ -0,0 +1,42 @@ +#include +#include +#include +#include +#include +#include +#include + +#define STATE_OFF 0 +#define STATE_ON 1 + +void setDTRState (int fd, int state) { + int flags; + + ioctl(fd, TIOCMGET, &flags); + flags = (state == STATE_ON ? flags | TIOCM_DTR : flags & ~TIOCM_DTR); + ioctl(fd, TIOCMSET, &flags); +} + +int +main(int argc, char* argv[]) +{ + char* device = argc < 2 ? "/dev/ttyUSB0" : argv[1]; + int fd = open(device, O_RDWR); + if (fd == 0) { + fprintf(stderr, "Could not open %s\n", device); + return EXIT_FAILURE; + } + + setDTRState(fd, STATE_ON); + struct timeval sleeptime = {0, 100000}; // 100ms + select(0, NULL, NULL, NULL, &sleeptime); + setDTRState(fd, STATE_OFF); + sleeptime.tv_sec = 0; + sleeptime.tv_usec = 100000; + select(0, NULL, NULL, NULL, &sleeptime); + setDTRState(fd, STATE_ON); + close(fd); + + return EXIT_SUCCESS; +} +