linuxserial-portsniffingsniffersocat

Sniff multiple serial ports simultaneously with socat


I'm trying to record multiple serial ports simultaneously, I am able to log once at a time, but when I launch a new socat, the old process is terminated.

This are the commands I want to execute, just a simple socat sniff to file.

socat -lf /dev/stdout -x -s 2> USB1.log /dev/ttyUSB1,echo=0 - &
socat -lf /dev/stdout -x -s 2> USB2.log /dev/ttyUSB2,echo=0 - &
socat -lf /dev/stdout -x -s 2> USB3.log /dev/ttyUSB3,echo=0 - &

I'm able to read all simultaneously using jpnevulator, but I believe is interfering with the communication of the devices as they suddenly have communication failures, and when I close the jpnevulator the communication improves. The command I've tried with is jpnevulator --tty /dev/ttyUSB1 --read --timing-print


Solution

  • Apparently is because trying to use /dev/stdout multiple times with the -lf option. Instead, you must use PTY as intermediaries.

    socat -xs /dev/ttyUSB1,raw  PTY,link=/tmp/USB1,raw,echo=0 2 >> USB1.log &
    socat -xs /dev/ttyUSB2,raw  PTY,link=/tmp/USB2,raw,echo=0 2 >> USB2.log &
    socat -xs /dev/ttyUSB3,raw  PTY,link=/tmp/USB3,raw,echo=0 2 >> USB3.log &