4

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

Matthew Kennedy
  • 616
  • 4
  • 19

2 Answers2

2

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

timmins
  • 104
  • 5
0

If you need to have control about the message and response, you could use a third process that manage the access of the serial port. Something like: https://stackoverflow.com/a/63537265/4702399

Baurin Leza
  • 2,004
  • 1
  • 13
  • 15