在Linux上共享串行端口 [英] Share Serial Port on Linux

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

问题描述

我正在将Raspberry Pi用于一个项目,该项目需要能够从不同程序写入和读取串行端口.程序A必须能够从外围设备A正在发送数据的串行端口读取.程序B需要将数据写入到外围设备B正在侦听的串行端口(作为参考,在这种情况下,程序A为GPSD,程序B由我编写).程序A不需要编写,程序B则不需要读取.

I'm using a Raspberry Pi for a project that that needs to be able to write and read to a serial port, but from different programs. Program A needs to be able to read from the serial port, where peripheral A is sending data. Program B needs to write data to the serial port, where peripheral B is listening (For reference, in this case, program A is GPSD and program B is written by me). Program A never needs to write, and B never needs to read.

是否可以让两个程序同时访问该端口?如果不是这样,是否可以编写一个程序来创建两个设备节点(将/dev/ttyAMA 拆分为/dev/ttyAMA_1 /dev/ttyAMA_2,也许?)多路传输到串行端口?

Is it possible to have both programs access the port at once? If not, is it possible to write a program that creates two device nodes (split /dev/ttyAMA into something like /dev/ttyAMA_1 and /dev/ttyAMA_2, perhaps?) that multiplex into the serial port?

在此先感谢您的帮助!

-马修

推荐答案

我相信多个应用程序可以同时访问TTY设备.您正在从一个用户空间应用程序执行读取操作而从另一个用户空间应用程序执行写入操作这一事实意味着您不太可能遇到问题.

I believe it is possible for multiple applications to access a TTY device simultaneously. The fact that you are performing read operations from one userspace application and write operations from another means you are unlikely to encounter a problem.

要验证这一点,您可以使用控制台从串行读取到串行设备:

To verify this you can read from a serial into a serial device using the console:

cat/dev/ttyS0

如果打开另一个终端,则可以毫无问题地写入设备:

If you open another terminal, you can write to the device without any problem:

echo"stuff">/dev/ttyS0

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

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