grid-x / modbus

BSD 3-Clause "New" or "Revised" License
78 stars 26 forks source link

Fix Modbus-CLI for WriteMultipleRegisters #61

Closed dammarco closed 1 year ago

dammarco commented 1 year ago

During field tests, we were not able to successfully use function code 16 (0x10, WriteMultipleRegisters). It returns an Expcetion for Illegal Data Value.

When enabling logs with log-frame, we got:

modbus: send 00 01 00 00 00 09 01 10 00 00 00 02 02 00 00
modbus: recv 00 01 00 00 00 03 01 90 03
modbus: exception '3' (illegal data value), function '144'

If we look closer at the modbus frame that was sent, i.e. 10 00 00 00 02 02 00 00 and decode it following http://pps2.com/images/smf/MB_16_Write_Reg.jpg, we get:

10 << Function Code 16
00 00 
00 02 << 2 registers that should be written
02 << 2 bytes that are written
00 00 << data: 00 00

The number of bytes matches the number of registers which is the issue here. A register has 16 bit and thus, it must be half the length of bytes.

After fixing, we were able to successfully write registers using this function code.

dammarco commented 1 year ago

@frzifus hmm what do you mean? Is there a compiled version for the modbus-cli somewhere here that I didn't see? :thinking:

frzifus commented 1 year ago

There is one in the release section release section [v1.0] :smiley:.

dammarco commented 1 year ago

uhh nice didn't see this one. Is this automated somehow or do I have to build the binaries manually?

frzifus commented 1 year ago

@tretmar not that i would know of. But via github actions it shouldn't be too hard to set up.

Something like that could be used as a trigger.

on:
  push:
    tags: [ 'v*' ]