Closed kevingarman closed 6 years ago
Exactly that is the intended way of using it.
Ok cool, but it doesn't work right...all modbus clients are notified of data on the socket and all try to consume the data even when the unit ids don't match. I don't know if this is the best fix but it seems to work #179
We need to extract the response first in order to validate the unitId. Seems like the best way to do this to me.
My setup is a modbus tcp gateway with a handful of serial devices. Due to connection count limitations, I'm trying use a single socket to the gateway to communication with all serial units. I've done this with a single socket in the node app with multiple modbus tcp clients using the same socket. I believe is the intended usage but please correct me if I'm wrong.
I was getting a log of "request fc and response fc does not match" and "rejecting because of earlier OutOfSync error" errors. I believe the cause is that all ModbusClients using a given socket get notified of the incoming data on that socket and try to consume it without first verifying the unitId. I modified line 45 of modbus-client.js to the following:
if (!response || (this._unitId != response.unitId)) {
...and that seemed to make it work.