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

ModbusRTU.writeRegisters doesn't accept negative int 16 ... #568

Open
volkmarnissen opened this issue Nov 16, 2024 · 1 comment
Open

ModbusRTU.writeRegisters doesn't accept negative int 16 ... #568

volkmarnissen opened this issue Nov 16, 2024 · 1 comment

Comments

@volkmarnissen
Copy link

... You get an out of range exception, when you try it.
RangeError [ERR_OUT_OF_RANGE]: The value of "value" is out of range. It must be >= 0 and <= 65535. Received -10

However, it's easy to convert the value to unsigned int 16:

        if( value < 0 && value >= -32768){
          let b = Buffer.allocUnsafe(2)
          b.writeInt16BE(value)
          return b.readUInt16BE()
        }

This can be a workaround and if implemented also a solution.

@yaacov
Copy link
Owner

yaacov commented Nov 16, 2024

Thank you for the issue, can you make a pull request ?

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

No branches or pull requests

2 participants