0
votes

I am using a pi3 which talks to an arduino via serial0 (ttyAMA0)

It all works fine. I can talk to it with minicom, bidirectionally. However, a python based server also wants this port. I notice when minicom is running, the python code can write to serial0 but not read from it. At least minicom reports the python server has sent a message.

Can someone let me know how this serial port handles contention, if at all? I notice running two minicom session to the same serial port wrecks both sessions. Is it possible to have multiple writers and readers if they are coordinated not to act at the same time? Or can there be multiple readers (several terms running cat /dev/serial0)

I have googled around for answers but most hits are about using multiple serial ports or getting a serial port to work at all.

Cheers

1
AFAIK serial port can only be accessed by one application at a time, because serial communication is between two devices and typically can’t be shared/multiplexed. Of course it’s possible to create a protoclol for allowing multiple apps to communicate with multiple things at the other end of the serial connection, but you’d probably have to be in control of the other end things too to stand any chance of making this work.balmy

1 Answers

1
votes

Since two minicoms can attempt to use the port and there are collisions minicom must not set an advisory lock on local writes to the serial port. I guess that the first app to read received remote serial message clears it, since serial doesn't buffer. When a local app writes to serial, minicom displays this and it gets sent. I'm going to make this assumed summary

  1. when a local process puts a message on the serial port everyone can see it and it gets sent to remote.
  2. when a remote message arrives on serial, the first local process to get it, gets it. The others can't see it.
  3. for some reason, minicom has privilege over arriving messages. This is why two minicoms break the message.