som*_*ser 7 telnet serial macos
我正在尝试在 Mac OS X 10.9.5 (Mavericks) 上设置反向 Telnet(Telnet 到 COM)。Mac 连接到串行设备。我使用屏幕从 Mac 访问串行设备没有问题:
screen /dev/cu.USBserial
Run Code Online (Sandbox Code Playgroud)
但是,我想通过 Telnet 远程访问该设备。
我尝试使用 Netcat ( nc) 并取得了有限的成功。我使用的命令是:
nc -l 9999 > /dev/cu.USBserial < /dev/cu.USBserial
Run Code Online (Sandbox Code Playgroud)
然后我可以 Telnet 到设备。但是,它不起作用有两个原因:
正确的做法是什么?
我找到了解决方案。Python PySerial 包有一个 rfc2217 类。他们有一个用作 telnet 服务器的示例应用程序:
https://pyserial.readthedocs.org/en/latest/examples.html
$ python rfc2217_server.py /dev/tty.serial
Run Code Online (Sandbox Code Playgroud)
打开允许 telnet 连接的端口 2217。这正是我想要的。