The problem I ran into with libmodbus is that it expects to have exclusive access to the serial port. I can create a new modbus context by calling modbus_new_rtu but then I have to call modbus_connect to open the port. I'm currently trying this on a SUSE 11 system and, with the port already open in another thread, I can still call modbus_connect and everything works fine, even though this shouldn't work. I should get an "access denied" error. I don't like this approach and don't want to use it on our embedded device.
Another approach I tried was the hack libmodbus by adding in a function modbus_set_handle that sets the port handle in the _modbus struct. This *seems* to work but I don't know if there are other side effects from me dong this. Can someone tell me if this is a big no-no, other than the obvious "no support' issue.