Mac 上的 USB 串行端口使用 socat

chr*_*ris 5 macos usb serial-port tty socat

我有一个通过 Prolific Serial 转 USB 电缆连接的硬件,我需要使用 socat 向该端口和 TCP 端口发送/接收流量。到目前为止,它已经安装完毕并且可以与 minicom 一起正常工作,使用:

minicom -D /dev/tty.usbserial -b 9600

Socat 使用以下方式在一个方向上工作到 TCP 端口:

socat /dev/tty.usbserial,clocal=1,nonblock=1,cread=1,cs8,ixon=1,ixoff=1 TCP4:localhost:8080

我如何让它以两种方式工作?我经常看到重复的字符或双线,这表明串行设置不正确,对吗?

谢谢!克里斯

编辑:一些示例代码(实际上并不以双向方式工作)。

Chris-MacBookAir:~ chrisbridges$ socat -d -d - /dev/tty.usbserial,clocal=1,nonblock=1,cs8,ixon=1,ixoff=1,ispeed=9600,ospeed=9600,icanon=1
2013/01/09 13:13:34 socat[8501] N reading from and writing to stdio
2013/01/09 13:13:34 socat[8501] N opening character device "/dev/tty.usbserial" for reading and writing
2013/01/09 13:13:34 socat[8501] N starting data transfer loop with FDs [0,1] and [3,3]
Run Code Online (Sandbox Code Playgroud)

小智 4

谢谢您的帮助。我现在已经解决了,可以正常沟通了。Socat确实是一个复杂的工具。这是我的最终设置:

sudo socat -U -d -d -d /dev/tty.usbserial,clocal=1,cs8,nonblock=1,ixoff=0,ixon=0,ispeed=9600,ospeed=9600,raw,echo=0,crtscts=0 FILE:tnc-start.hex
Run Code Online (Sandbox Code Playgroud)

其中“ixon”启用 XON/XOFF 流量控制,“ixoff”启用发送开始/停止字符,而有趣的是“echo”不会打印到控制台,但 echo 是发送回发送方的任何内容......奇怪!