How can I monitor data on a serial port in Linux? How can I monitor data on a serial port in Linux? linux linux

How can I monitor data on a serial port in Linux?


strace is very useful for this. You have a visualisation of all ioctl calls, with the corresponding structure decoded. The following options seems particularly useful in your case:

-e read=set

Perform a full hexadecimal and ASCII dump of all the data read from file descriptors listed in the specified set. For example, to see all input activity on file descriptors 3 and 5 use -e read=3,5. Note that this is independent from the normal tracing of the read(2) system call which is controlled by the option -e trace=read.

-e write=set

Perform a full hexadecimal and ASCII dump of all the data written to file descriptors listed in the specified set. For example, to see all output activity on file descriptors 3 and 5 use -e write=3,5. Note that this is independent from the normal tracing of the write(2) system call which is controlled by the option -e trace=write.


I have found pyserial to be quite usable, so if you're into Python it shouldn't be too hard to write such a thing.


A simple method would be to write an application which openedthe master side of a pty and the tty under test. You would thenpass your tty application the slave side of the pty as the 'tty device'.

You would have to monitor the pty attributes with tcgetattr() on the ptymaster and call tcsetattr() on the real tty, if the attributes changed.

The rest would be a simple select() on both fd's copying data bi-directionally and copying it to a log.