I’m designing a control system which should handle too many actuators (or sets of actuators) over a serial port. The new design (not implemented yet) is supposed to control actuators over multiple POSIX threads.
Is this possible to open a serial port multiple times (by multiple threads)?
If yes, I’m gonna write a synchronous write / asynchronous read mechanism. There will be n threads M[0] to M[n-1] which can write data directly to serial port. They’re not supposed to read from serial port directly. Instead, a thread R is supposed to read data from port in a while(true) loop and serve data to corresponding threads waiting for it. (Wake up M[i] which is waiting for response, when data is ready and it belongs to ith thread)
It’s all depended on the question if it’s possible to write to serial port by multiple threads or not.
notes: I can’t test the behavior of serial port, because currently I have no access to devices in mechatronics lab of my university,
I’m using kernel 2.6.38-8 patched with Xenomai real-time subsystem (if important)
I’m porting code to traditional Linux way of communicating with serial port. (Open /dev/ttyS0, set baudrate, read(), write(), etc.) Currently a third party library is used to talk with serial port.
You can open the same serial port only once. The second trial fails with Access Denied. Once the port is opened, you can work with it in different threads, using the port handle. Of course, you need to synchronize port access between these threads.