Socat串口嗅探

Adr*_*aub 4 serial-port socat buildroot

我目前正在尝试访问连接到应用程序的串行端口的两个方向上的数据。
我想做的是:
ttymxc0 <-----> socat sniff <--------> ttyV0 <------> 应用程序
ttymxc0 是真实端口,ttyV0 是虚拟端口。

我发现 socat 命令适用于 Ubuntu 16.04: http://www.iheartrobotics.com/2010/02/debugginng-serial-interfaces.html

但是当我使用 buildroot 在嵌入式系统上使用它时,我收到此错误:

socat -d /dev/ttymxc0,raw,echo=0 SYSTEM:'tee input.txt | socat - "PTY,link=/tmp/ttyV0,raw,echo=0,waitslave" | tee output.txt'
 socat[3167.1996369920] E address "GOPEN..." in intermediate context, leftdirs=4, rightdirs=7, with 1 parameter(s) is not available
 socat[3167.1996369920] W cannot restore terminal settings on fd 3: Bad file descriptor
Run Code Online (Sandbox Code Playgroud)

我尝试查看文件的访问属性,但没有成功。当您不要求打印输入和输出时它可以工作,但这对我的使用没有用

在这种情况下,buildroot 和 Ubuntu 之间有什么不同吗?

Die*_*ego 7

您已经回答了自己的问题,但这个稍微现代化的答案是:

$ socat -x -v /dev/ttyUSB0,rawer,b115200,crnl PTY,link=ttyV1,rawer,crnl
< 2022/01/12 15:34:47.845709  length=11 from=0 to=10
 65 63 68 6f 20 48 65 6c 6c 6f 0a                 echo Hello.
--
> 2022/01/12 15:34:47.847937  length=12 from=0 to=11
 65 63 68 6f 20 48 65 6c 6c 6f 0d 0a              echo Hello..
--
> 2022/01/12 15:34:47.876068  length=7 from=12 to=18
 48 65 6c 6c 6f 0d 0a                             Hello..
--
> 2022/01/12 15:34:47.905274  length=1 from=19 to=19
 24                                               $
--
Run Code Online (Sandbox Code Playgroud)

socat手册中:

  1. -v“将传输的数据不仅写入目标流,还写入stderr。输出格式是文本,经过一些转换以提高可读性,并以“>”或“<”为前缀指示流方向。”
  2. raw已过时,rawer“使终端比原始选项更原始。此选项隐式关闭回声。”
  3. b115200“将串行线路速度设置为 115200 波特”,这是一个非常常见的设置。当然,请根据您的情况设置正确的值。