Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
I'm originally a Windows guy, and I work on both now. I'm used to COM ports being exclusive! Thanks! –  Matthew Kennedy Jun 13 '13 at 19:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.