File: uartcount.c

package info (click to toggle)
xringd 1.20-1
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 164 kB
  • ctags: 107
  • sloc: ansic: 863; makefile: 71; sh: 29
file content (26 lines) | stat: -rw-r--r-- 644 bytes parent folder | download | duplicates (8)
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
/* uartcount: (linux) display the modem input interrupt counters */

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

int main(int argc, char **argv)
{
	int fd;
	struct serial_icounter_struct c;

	if ((fd = open(argc == 2 ? argv[1] : "/dev/modem", 
			O_RDONLY | O_NONBLOCK | O_NOCTTY)) < 0) {
		perror("cannot open modem device");
		exit(1);
	}
	while (1) {
		if (ioctl(fd, TIOCGICOUNT, &c) != 0)
			exit(1);
		printf("Count: RI=%6d # CD=%6d # CTS=%6d # DSR=%6d\n",
		       c.rng, c.dcd, c.cts, c.dsr);
		ioctl(fd, TIOCMIWAIT, TIOCM_RNG | TIOCM_CTS | TIOCM_DSR | TIOCM_CD);
	}
}