如何在Linux的串行端口上监视数据? [英] How can I monitor data on a serial port in Linux?
问题描述
我正在调试与串行设备的通信,我需要查看所有双向流动的数据.
在串行端口由文件表示的Linux上,这似乎应该很容易.有什么方法可以做某种双向三通",我告诉程序连接到管道,该管道将数据复制到文件,还可以将数据从实际的串行端口设备中拖移到随机管道中?>
我想我什至可能会写这样的野兽,但这似乎并不简单,尤其是要让所有的ioctl通过端口配置等等.
有人已经建造了这样的东西吗?似乎太有用了(对于调试串行设备驱动程序的人来说),不存在.
strace 为此非常有用.您可以看到所有ioctl调用的可视化,并解码相应的结构.以下选项在您的情况下似乎特别有用:
-e read = set
对从中读取的所有数据执行完整的十六进制和ASCII转储 在文件描述符中列出 指定的集合.例如,查看全部 文件描述符上的输入活动3 和5使用-e read = 3,5.请注意, 与正常跟踪无关 read(2)系统调用的 由选项-e控制 trace = read.
-e write = set
执行完整的十六进制和ASCII 转储写入文件的所有数据 指定者中列出的描述符 放.例如,查看所有输出 文件描述符3和5上的活动 使用-e write = 3,5.请注意,这是 独立于正常跟踪 write(2)系统调用是 由选项-e控制 trace = write.
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.
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.
这篇关于如何在Linux的串行端口上监视数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!