如何在 Linux 中监视串行端口上的数据? [英] How can I monitor data on a serial port in Linux?

查看:110
本文介绍了如何在 Linux 中监视串行端口上的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试与串行设备的通信,我需要查看双向流动的所有数据.

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

在 Linux 上这似乎应该很容易,其中串行端口由文件表示.有什么方法可以让我做一种双向 tee",让我的程序连接到一个管道,该管道将数据复制到一个文件中,并将其混洗到/从实际的串行端口设备?

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?

我想我什至可能知道如何编写这样的野兽,但这似乎并不简单,尤其是让所有 ioctl 通过端口配置等.

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 是对此非常有用.您拥有所有 ioctl 调用的可视化,并解码了相应的结构.以下选项在您的情况下似乎特别有用:

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 读取=设置

对读取的所有数据执行完整的十六进制和 ASCII 转储中列出的文件描述符指定的集合.例如,查看所有文件描述符 3 上的输入活动和 5 使用 -e read=3,5.请注意,这独立于正常跟踪read(2) 系统调用是由选项 -e 控制跟踪=读取.

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 写入=设置

执行完整的十六进制和 ASCII转储所有写入文件的数据在指定的描述符中列出放.例如,查看所有输出文件描述符 3 和 5 上的活动使用-e write=3,5.请注意,这是独立于正常的追踪write(2) 系统调用是由选项 -e 控制跟踪=写.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆