2

I have been trying to get a HEX dump of what is being sent/received to CP2102 serial converter chip. I can find examples of people monitoring hardware serial ports /dev/TTYS0 and the like.

socat -d -d pty,link=/dev/ttyUSB0,raw,echo=0 pty,link=/dev/ttyUSB1,raw,echo=0

Does anyone know of a resource that could tell me how to monitor a USB port like this? So far nothing has worked. Maybe I just don't understand the rerouting side of serial monitoring or something?

2
  • Like I said, I am just trying to get a HEX dump of what is being sent and received through the port.
    – regor2
    Commented Oct 7, 2017 at 0:27
  • Right now I have software communicating to an external serial port. I want to monitor what is being sent and received between the two. I should have said so, sorry. Thanks
    – regor2
    Commented Oct 8, 2017 at 21:50

1 Answer 1

1

If possible, the easiest may be to adjust the software to emit hex. Most software will likely already have sdio.h (or equivalent) and hex-of-the-serial-data simply requires printf calls (or equivalent) on the data going to and from the serial file descriptor. No complication of an extra process ferrying the data to and fro and little extra latency.

If you're in a hurry something like strace (or sysdig SystemTap etc) could be used to record the communication though strace will slow a process down, a lot, and the output will require post-processing; the other two are kernel modules so may not be suitable.

strace -xx -y -e trace=read,write -p $pid_of_your_program_here

At the hardware level a Bus Pirate or similar may be another way to tap into the communication.

Meanwhile, socat(1) does appear to have a handy -x for hex option:

   -x     Writes  the  transferred  data not only to their target streams,
          but also to stderr. The output format is  hexadecimal,  prefixed
          with  ">  "  or "< " indicating flow directions. Can be combined
          with -v .

which after some experimentation I was able to listen in on a random Arduino via:

socat -x PTY,link=/dev/blah,raw,wait-slave /dev/serial/by-id/usb-Arduino...

and then your software could open up /dev/blah (or maybe instead run it via EXEC?). Note that no raw option was specified after the /dev/serial/by-id/usb-Arduino... path as with that set there were tcgetattr(6, ...): Inappropriate ioctl for device errors when socat tried to configure it. The socat output will likely also require post-processing, as it looks something like:

--
2017/10/09 16:32:20 socat[30806] I transferred 1 bytes from 6 to 5
< 2017/10/09 16:32:20.475916  length=31 from=2042 to=2072
 52 65 71 75 65 73 74 69 6e 67 20 74 65 6d 70 65  Requesting tempe
 72 61 74 75 72 65 73 2e 2e 2e 44 4f 4e 45 0a     ratures...DONE.
--
1
  • Thank you so much for your time! strace it is! I am now able to debug this crazy program...
    – regor2
    Commented Oct 9, 2017 at 23:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .