Closed NNM11 closed 8 years ago
Can you confirm that branch v0.5.2 fixes that?
The v0.5.2 branch did not fix the problem.
Ah, I didn't saw that there is a full error description including code. I checked the simpleServer.js example and it works if you set the port to 502. Check the err variable before assigning handler.
The sample code with error checking will avoid this problem when port 502 is blocked by default.
// create Modbus TCP Server
modbus.createTCPServer(8888, '127.0.0.1', function (err, modbusServer) {
if (err) {
console.log(err);
process.exit(1);
}
// addHandler
modbusServer.addHandler(4, rirHandler);
modbusServer.addHandler(5, writeCoilHandler);
});
There is a async issue with the jsmodbus.js createTCPServer() call (line 91).
The code will fail if the server create() with port 502.
The serrver code
The createTCPServer() callbback with invalid 'modbusServer'
TypeError: Cannot read property 'addHandler' of undefined