NISystemsEngineering / LabVIEW-Modbus-API

66 stars 38 forks source link

Mutex does not protect parallel access to same serial port correctly #9

Open SeasDiver opened 4 years ago

SeasDiver commented 4 years ago

If you have a multidrop serial configuration - multiple devices on same serial port using unique Device IDs, the mutex that is created to protect communications does not work if there are parallel accesses to the Read/Write register functions. The problem is that each Create Serial Master generates a unique Mutex whereas it should be a unique mutex for each serial port, not each device on the serial port. You will not see a problem if using a single device or if all of your register accesses are serialized, but if you parallelize the application, then you can have two different accesses to the same serial port which will screw up communications resulting in error 56.

SeasDiver commented 4 years ago

Note: This may also occur if you have multiple devices going to different IP Ports on the same TCP IP Address, but I have not tested that use case. It is a rare one and would only occur if you have multiple programs on the same computer offering multiple TCP Modbus interfaces on different ports which would be a fairly unusual use case.