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

前端 未结 5 1352
忘掉有多难
忘掉有多难 2021-01-30 14:07

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

相关标签:
5条回答
  • 2021-01-30 14:40

    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.

    0 讨论(0)
  • 2021-01-30 14:43

    Much like @MBR, I was looking into serial sniffers, but the ptys broke the parity check. However, his sniffer was not helping me, as I'm using a CP2102, and not a FT232. So I wrote my own sniffer, by following this, and now I have one that can record file I/O on arbitrary files: I called it tracie.

    0 讨论(0)
  • 2021-01-30 14:47

    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.

    0 讨论(0)
  • 2021-01-30 14:47

    I looked at a lot of serial sniffers. All of them are based on the idea of making a virtual serial port and sniff data from that port. However, any baud/parity/flow changes will break connection.

    So, I wrote my own sniffer :). Most of the serial ports now are just USB-to-serial converters. My sniffer collects data from USB through debugfs, parse it and output to the console. Also any baudrate changes, flow control, line events, and serial errors are also recorded. The project is in the early stage of development and for now, only FTDI is supported.

    http://code.google.com/p/uscmon/

    0 讨论(0)
  • 2021-01-30 15:04

    A simple method would be to write an application which opened the master side of a pty and the tty under test. You would then pass 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 pty master 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.

    0 讨论(0)
提交回复
热议问题