brainelectronics / micropython-modbus

MicroPython Modbus RTU Slave/Master and TCP Server/Slave library
GNU General Public License v3.0
115 stars 47 forks source link

Read/Write register at some location of definition #35

Closed brainelectronics closed 1 year ago

brainelectronics commented 1 year ago

Found during #33, see https://github.com/brainelectronics/micropython-modbus/pull/33#issuecomment-1336274272 at section "Problem 3" and "Problem 5"

Defining a register on the MicroPython Modbus client device as e.g. (valid for HREGS, COILS, ISTS, IREGS)

{
    "HREGS": {
        "HREG_NAME": {
            "register": 93,
            "len": 3,
            "val": [29, 38, 0]
        }
    }
}

does not allow to read ONLY register 94 which would hold 38.

Reason/Root cause: Registers are defined as specified by the register element, see https://github.com/brainelectronics/micropython-modbus/blob/c45d6cc334b4adf0e0ffd9152c8f08724e1902d9/umodbus/modbus.py#L53-L55 for a coil. The provided value is added as value to the dictionary at the key register, here 93. Thereby no element/key 94 exists in the Modbus _register_dict