Linux 虚拟串口 [英] Virtual Serial Port for Linux

查看:40
本文介绍了Linux 虚拟串口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Linux上测试一个串口应用,但是我的测试机只有一个串口.

I need to test a serial port application on Linux, however, my test machine only has one serial port.

有没有办法向 Linux 添加虚拟串口并通过 shell 或脚本模拟设备来测试我的应用程序?

Is there a way to add a virtual serial port to Linux and test my application by emulating a device through a shell or script?

注意:我无法重新映射端口,它硬编码在 ttys2 上,我需要在编写应用程序时对其进行测试.

Note: I cannot remap the port, it hard coded on ttys2 and I need to test the application as it is written.

推荐答案

为此,您可以使用 pty(伪电传打字机",其中串行端口是真正的电传打字机").一方面,打开/dev/ptyp5,然后将你的程序附加到/dev/ttyp5ttyp5 就像一个串行端口,但会通过/dev/ptyp5 发送/接收它所做的一切.

You can use a pty ("pseudo-teletype", where a serial port is a "real teletype") for this. From one end, open /dev/ptyp5, and then attach your program to /dev/ttyp5; ttyp5 will act just like a serial port, but will send/receive everything it does via /dev/ptyp5.

如果您真的需要它与名为 /dev/ttys2 的文件通信,那么只需将旧的 /dev/ttys2 移开并创建符号链接从 ptyp5ttys2.

If you really need it to talk to a file called /dev/ttys2, then simply move your old /dev/ttys2 out of the way and make a symlink from ptyp5 to ttys2.

当然,您可以使用 ptyp5 以外的其他数字.也许选择一个数字大的以避免重复,因为您所有的登录终端也将使用 ptys.

Of course you can use some number other than ptyp5. Perhaps pick one with a high number to avoid duplicates, since all your login terminals will also be using ptys.

维基百科有更多关于 ptys 的信息:http://en.wikipedia.org/wiki/Pseudo_terminal

Wikipedia has more about ptys: http://en.wikipedia.org/wiki/Pseudo_terminal

这篇关于Linux 虚拟串口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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