模拟串口

发布于 2024-09-14 12:31:35 字数 169 浏览 7 评论 0原文

我正在 Linux 中编写一个 C 程序,它将从串行端口读取/写入。我知道需要在端口上读取和写入的数据,但我当前没有串行端口来测试它。

有没有办法模拟串口?读/写文件就足够了吗?我可以让一个进程写入文件,而另一个进程读取该数据并将其他数据写回文件。或者还有其他可以用来模拟端口的工具吗?

谢谢

I am writing a C program in Linux which will read/write to/from a serial port. I know the data that needs to be read and written on the port but I don't have a serial port to currently test this with.

Is there any way to simulate a serial port? Would reading/writing to a file be sufficient? I can have one process write to the file while another process reads that data and writes back other data to the file. Or are there others tools that can be used to simulate a port?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青瓷清茶倾城歌 2024-09-21 12:31:35

Linux 上的串行端口是终端设备。一个接近的模拟是创建一个伪终端对;通常与串行端口通信的程序被告知打开伪终端的从机端,并且模拟器从主机端写入和读取。

pty(7) 手册页提供了更多信息。

Serial ports on Linux are terminal devices. A close simulation is to create a pseudo-terminal pair; the program that normally talks to the serial port is instead told to open the slave side of the pseudo-terminal, and the simulator writes and reads from the master side.

The pty(7) man page has more information.

反话 2024-09-21 12:31:35

尽管这是一个老话题,而且我的答案并不完全是OP想要的东西,但我决定分享我的经验,因为其他人可能会像我一样遇到它。我没有使用简单的模拟,而是使用了名为“串行转以太网连接器”的软件来访问测试应用程序所需的特定设备。对我来说效果很好。

Despite being an old topic, and my answer is not exactly something the OP was looking for, I decided to share my experience, as someone else might come across it like I did. Instead of straightforward simulation, I used the software called Serial to Ethernet Connector to gain access to the specific device I needed to test the app with. Worked nicely for me.

翻身的咸鱼 2024-09-21 12:31:35

如果您不关心端口设备特有的属性,那么字符设备,即使是像普通 stdinstdout 这样简单的设备也应该可以工作。

A character device, even something as simple as normal stdin and stdout should work if you don't care about attributes specific to port devices.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文