Cloud-Automation/node-modbus

SimpleServer.js example not working - listeners not called

Closed this issue · 1 comments

I was trying to run your SimpleServer example. (examples/javascript/tcp/SimpleServer.ts)
I was trying to use the readHoldingRegisters listener defined in the example.
The issue is that with the defined options for the server these listeners get never called.
This is the case for:

  • readCoils
  • readHoldingRegisters
  • readInputRegisters
  • readDiscreteInputs

Reason:

When the server.holding option is defined the event gets not triggered.

if (!this._server.coils) {
    debug('no coils buffer on server, trying readCoils handler');
    this._server.emit('readCoils', request, cb);
    return;
}

see modbus-server-response-handler.js:55

Solution/Workaround:

You can define the server options to undefined. Then the events will be emitted and the listeners get called.
Can you plaese change this in the example or at least add a comment to the example?

const server = new modbus.server.TCP(netServer, {
  coil: undefined,
  holding: undefined
})

Hi @TimT1919 , thanks for the hint and the workaround. Since this is an open source project I welcome every Merge Request developers are submitting. It would be great if you provide one for this case too.