Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm debugging communications with a serial device, and I need to see all the data flowing both directions.

It seems like this should be easy on Linux, where the serial port is represented by a file. Is there some way that I can do a sort of "bi-directional tee", where I tell my program to connect to a pipe that copies the data to a file and also shuffles it to/from the actual serial port device?

I think I might even know how to write such a beast, but it seems non-trivial, especially to get all of the ioctls passed through for port configuration, etc.

Has anyone already built such a thing? It seems too useful (for people debugging serial device drivers) not to exist already.

like image 877
divegeek Avatar asked Jun 02 '09 16:06

divegeek


People also ask

How do you check if a device is connected to serial port Linux?

If you mean to find out if the port itself is present in the system, then you could check for the existence of a loaded module which would support it, check for the existence of a device such as /dev/ttyS0 or /dev/ttyUSB0, and verify that you can open it (for example, I have a /dev/ttyS0 device file present on a system ...

How do I access the serial console in Linux?

To enable the serial console for your custom Linux VM image, enable console access in the file /etc/inittab to run a terminal on ttyS0 . For example: S0:12345:respawn:/sbin/agetty -L 115200 console vt102 . You may also need to spawn a getty on ttyS0. This can be done with systemctl start [email protected] .


1 Answers

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.

like image 111
shodanex Avatar answered Sep 21 '22 11:09

shodanex