Share Serial Port on Linux

天大地大妈咪最大 提交于 2019-12-23 16:23:14

问题


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.

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?

Thanks in advance for any help!

-Matthew


回答1:


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



来源:https://stackoverflow.com/questions/17093446/share-serial-port-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!