kochedykov / jlibmodbus

JLibModbus - is an implementation of the Modbus protocol v1.1b in java language. Java modbus library. It works. Welcome.
http://kochedykov.github.io/jlibmodbus/
Apache License 2.0
307 stars 128 forks source link

Modbus.checkRegisterValue wrong cast? #48

Open civic9 opened 4 years ago

civic9 commented 4 years ago

https://github.com/kochedykov/jlibmodbus/blob/38fcf02f3dda8177372849b6cf3340164b8be437/src/com/intelligt/modbus/jlibmodbus/Modbus.java#L293

Why value is casted to short? Short is signed in java, and with such castings this method returns false for values above 32767. Is there any reason? I am not sure if I can fix this by removing that cast.

djlabbe commented 4 years ago

It looks like this was put in to fix a different reported bug where someone was trying to use this method for values between Short.MIN and Short.MAX instead of 0 to Modbus.MAX_REGISTER_VALUE. It definitely doesn't work to cast to short, and then check range between 0 and 65535.