aboutsummaryrefslogtreecommitdiff
path: root/src/clear_rts.c
blob: c50a9fcb3c870b65d1d21afc8ddc8b32719de597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Compile with:
	gcc -o clear_rts clear_rts.c

	Change PORT if necessary.
 */
#define PORT "/dev/ttyUSB0"

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <linux/serial.h>

int main(int argc, char **argv) {
	int fd, status;
	char *port;

	if(argc == 2)
		port = argv[1];
	else
		port = PORT;

	fd = open(PORT, O_RDWR);
	if(fd < 0) {
		perror(PORT);
		return 1;
	}

	ioctl(fd, TIOCMGET, &status);

	/* This always says it was on. Opening the port sets it? */
	/*
	fprintf(stderr, "%s: RTS was ", port);
	if(status & TIOCM_RTS) {
		fputs("on", stderr);
	} else {
		fputs("already off", stderr);
	}
	fputc('\n', stderr);
	*/

	status &= ~TIOCM_RTS;
	ioctl(fd, TIOCMSET, &status);
	fprintf(stderr, "%s: RTS forced off (Tucker SIO2PC)\n", port);
	return 0;
}