Serial communication with multiple nodes
hey,
I've got a short question. When i have two nodes, both want to communicate via a serial port. One wants to send a command an receive an answer. The other one just sends a command. How can I be sure, that they do not send parallel at the same time? And, no one sends, while an answer is received?
ah, and I would like to use the serial.h libary
EDDIT: The Nodes are running on one PC and would like to communicate to external Hardware, such as a control board used for reading sensors und moving motors.
Thanks a lot
L
Can you clarify the question a little. Are the two nodes on different computers which are communicating via a serial link? Or are both nodes on the same computer trying to share a serial port to a third device, which is not possible as far as I know.
The Nodes are running on one PC and would like to communicate to external Hardware, such as a control board used for reading sensors und moving motors. Thanks!
Not a complete answer (as it involves a node), but shared_serial is a package that seems to implement what you are after.
Your question is a classic "concurrent access to a shared resource" problem.
Normally you could use a mutex or one of the various locks to protect access to the shared resource.
In the case of multiple processes though (nodes are processes) this becomes more difficult. Sharing mutexes using ..
.. a shared memory segment is a possibility, but will of course completely lock your two nodes together (both at the design as well as the implementation level).
Introducing a 'gateway' node / entity that serialises access to the shared resource is a common approach used in these cases.
The ..
.. setup would have three nodes:
if A or B want to access the resource, they have to go through the gateway. All nodes communicate using messages.
In the case of ROS, you could use nodelets to remove the msging overhead, but that is an optimisation.