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

问题描述

限时删除!!

我需要在Linux上测试一个串行端口应用程序,但是,我的测试计算机只有一个串行端口.

是否可以通过Linux通过Shell或脚本模拟设备来向虚拟端口添加虚拟串行端口并测试我的应用程序?

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

解决方案

为此,您可以使用pty("pseudo-teletype",其中串行端口是真实电传打字机").从一端打开/dev/ptyp5,然后将程序附加到/dev/ttyp5ttyp5的作用类似于串行端口,但会通过/dev/ptyp5发送/接收其所做的一切.

如果您真的需要它与名为/dev/ttys2的文件进行对话,则只需将旧的/dev/ttys2移开,并从ptyp5ttys2建立符号链接.

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

Wikipedia有关pty的更多信息: http://en.wikipedia.org/wiki/Pseudo_terminal

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

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?

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

解决方案

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.

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.

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.

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

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

1403页,肝出来的..

09-06 21:29