Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SimpleServer.js example not working - listeners not called #337

Closed
TimT1919 opened this issue Apr 12, 2024 · 1 comment · Fixed by #343
Closed

SimpleServer.js example not working - listeners not called #337

TimT1919 opened this issue Apr 12, 2024 · 1 comment · Fixed by #343

Comments

@TimT1919
Copy link
Contributor

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
})
@stefanpoeter
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants