Portál AbcLinuxu, 6. května 2025 23:01
#include <sys/ioctl.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> /* DTR, DSR state, as you wish */ int sig_dtr = 1; int sig_dsr = 0; int main(int argc, char **argv) { int fd; int lstate; /* exactly one argument must be given */ if (argc != 2) { printf("What device?\n"); exit(1); } /* open device */ fd = open(argv[1], O_RDWR | O_NDELAY); if (fd < 0) {perror(argv[1]); exit(-1); } ioctl(fd, TIOCMGET, &lstate); if (sig_dsr != 0) { lstate |= TIOCM_RTS; } else { lstate &= ~TIOCM_RTS; } if (sig_dtr != 0) { lstate |= TIOCM_DTR; } else { lstate &= ~TIOCM_DTR; } ioctl(fd, TIOCMSET, &lstate); sleep(10); close(fd); return 0; }
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.