在OSX上嗅探USB串口通信的方法是什么?

huangapple go评论76阅读模式
英文:

method to sniff usb-serial communication on osx

问题

在Windows上,有几个不错的替代品(大多是付费的),可以让你监控串口通信。在OSX上,有很多终端应用程序可以让你与串口设备进行通信,但我还没有找到一种机制来监视串口通信。

具体的使用情况是:
我有一个USB-串口设备,位于/dev/tty.usbmodem99999。

我编写了一个运行多个命令的集成测试(成功运行)。

然而,重新运行命令时,设备没有响应。我已经尽力确认设备是正常的。它在其他平台上按预期工作。然而,在OSX上,我只能在重置设备(重新上电)后重新运行测试。

我的理论是,我的代码没有正确释放设备,但是当我看不到设备和应用程序之间的通信时,很难确认。

这个应用程序:"http://www.aggsoft.com/serial-port-monitor.htm" 有一个我一直无法在OSX上找到类似功能的"spy"功能。我已经尝试过在OSX上使用"serial tools",但它似乎不会在单个端口上执行"spy"操作,它看起来更像是在两个设备之间进行透传,而不是在端口上进行监视。

非常感谢任何想法。

英文:

On windows, there are several decent alternatives (mostly paid) which allow you to monitor serial port communications. On OSX there are lots of terminal applications which let you talk to serial devices but I haven't found a mechanism to monitor serial port communication.

The specific use case is:
I have a USB-Serial device that lives on /dev/tty.usbmodem99999

I have written an integration test that runs multiple commands (successfully).

However on re-running the command the device does not respond. I've confirmed (as well as I can) that the device is fine. It works on other platforms as expected. However on OSX I can only re-run the tests after resetting the device (power cycle).

My theory is that my code is not releasing the device properly but that's hard to confirm when I can't see the communication between my device and my application.

This application: "http://www.aggsoft.com/serial-port-monitor.htm" has a 'spy' feature that I have been unable to find similiar functionality to on OSX. I've experimented with 'serial tools' on osx, but it doesn't look like it does spy operations on a single port, in that case it looks like the use case is as a passthrough between two devices rather than monitoring at the port.

Any thoughts greatly appreciated.

serial library being used is:
https://github.com/jacobsa/go-serial

答案1

得分: 6

你使用过DTrace吗?

我使用它来监控FTDI USB/串口转换器和第三方"Black Box"应用程序之间的USB通信。这样我就可以获取应用程序发送到USB串口的所有内容。

这很简单,因为我知道应用程序的名称,所以DTrace可以观察到它。我编写了一个DTrace脚本来观察应用程序打开的文件描述符(寻找"/dev/tty.usbmodem..."),然后观察与该文件描述符的交互。

我没有观察过设备驱动程序。原则上,如果内核或设备驱动程序编译为与DTrace配合工作,DTrace可以做到这一点,尽管不能确定是否已经这样编译。苹果还可以构建对DTrace"不可见"的代码(例如,我相信iTunes被设置为对DTrace不可见,以保护其DRM机制)。

因此,一个可能的起点是观察所有的操作系统打开/创建调用,寻找/dev/tty.usbmodemXXX,并尝试识别子系统并观察它。你可能会发现子系统是可观察的,这应该有助于了解操作系统和设备驱动程序的工作原理。

这并不是一件简单的事情。如果你的时间有价值,那么更便宜、更可靠的方法可能是购买一个硬件USB嗅探器并将其放入电缆中,特别是如果它只是1.2Mbits或12MBits USB(对于更高的数据速率,嗅探器的价格更高)。

以下链接可能会有所帮助:
DTrace简介
DTrace指南
DTrace书籍
Brendan Gregg的Mac OS X前10个DTrace脚本
苹果DTrace手册
DTrace入门

英文:

Have you used DTrace?

I have used it to monitor USB comms between an FTDI USB/serial converter and a 3rd party 'Black Box' application. So I could get at everything that the application sent to the USB serial port.

That was pretty straightforward because I knew the name of the application, so DTrace could observe that. I wrote DTrace script to observe the file descriptors the application opened, (looking for the '/dev/tty.usbmodem...') then observed interactions with that file descriptor.

I have not observed a device driver. In principle DTrace can do that if the kernel or device driver is compiled to work with DTrace, though there is no certainty that it is. Apple can also build code which is 'invisible' to DTrace (for example I believe iTunes was made opaque to DTrace to protect its DRM mechanisms.)

So one possible starting point is to observe all OS open/creat calls, looking for /dev/tty.usbmodemXXX, and try to identify the subsystem and observe that. You may find that the subsytem can be observed, and that should help see what the OS+device driver is doing.

This isn't trivial. If your time has any value, it may be cheaper and more reliable to get a hardware USB sniffer and put it into the cable, especially if its only 1.2Mbits or 12MBits USB (sniffers are much more expensive for higher data rates).

These links may help:
About DTrace
DTrace Guide
DTrace book
Brendan Gregg's Top 10 DTrace scripts for Mac OS X
Apple DTrace manual
Hooked on DTrace

huangapple
  • 本文由 发表于 2015年11月17日 04:45:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/33744279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定