SciFiDryer / ModbusMechanic

Cross platform GUI MODBUS TCP/RTU simulator & gateway. Interprets data types including ascii float and int.
Apache License 2.0
158 stars 14 forks source link

(Preset) Write Single Register (6) incorrect value transmission #16

Open Pratched opened 1 year ago

Pratched commented 1 year ago

I was trying to see if my FunctionCode 0x06 works alright, but realised that the implementation in Modbusmechanic v2.5 seems to be a little bit faulty?

When I setup the simulator as Holding Register 50000 (UINT16), no swaps, I am not able to overwrite this value with FnC 0x06 correctly. No matter what I want to write, it always defaults to 0. Attached youl find screenshots of the WireShark capture of different write requests, always with the same data value.

ModbusMechanic client with 0x06 request and value=5. grafik

WireShark Output for my own implementation, same settings. grafik

ModbusMechanic client with 0x10 request and value=5 seems to work okay... grafik ... but as far as I understand simply writing one register (u16) should be possible with 0x06 as well?

Sorry in advance, if I missed something. EDIT: My understandings in this are based on "MODBUS APPLICATION PROTOCOL SPECIFICATION V1.1b3" from Modbus.org but might be oudated. grafik grafik

SciFiDryer commented 1 year ago

Thanks for testing and reporting this bug. I was able to reproduce and correct it to the extent that I can in f6d0839. I identified an underlying bug in JLibModbus that prevents values larger than 32767 from being accepted as the register value, so the values for the write single register function will be limited from 0-32767.

Pratched commented 1 year ago

No worries. Address 50000 was just the easiest workaround for testing purposes. Some sources additionally limit the register address to specific ranges based on functioncode (Ive never seen 50000 used somewhere anyway).

Cheers. PS: The english word Register as a noun (not a verb in terms of to register) translates in German to Register as well. Its not commonly used very much, but still valid. Registrieren would be the verb.

SciFiDryer commented 1 year ago

Feedback from a native speaker is helpful. I am using auto translation for the localization. The DE localization has been updated. You'll see it in the next release which also includes a TCP and RTU register scanner for devices where the register numbers are not known.

Just to clarify, the value of the register being written using function code 6 is what is limited to 32768. The registers themselves can go up to the full 65535. Of course you could always use function code 16 to write a value higher than 32768 if you need to do it in the GUI.