Modbus Registers Mapping Broken?
hschlabach last edited by
I have a Neuron M203 with freshly installed Rasbian Jessy Lite and after installation of evok i tried to access the device with python via modbusTCP:
from pyModbusTCP.client import ModbusClient import time try: c = ModbusClient(host="localhost", port=502, unit_id=0, debug=False) except ValueError: print("Error with host or port params") running=True while running: if c.is_open(): print (c.read_coils(0,12)) print (c.read_coils(1000,4)) print (c.read_coils(1016,12)) print (c.read_holding_registers(0,20)) print (c.read_holding_registers(1000,32)) print (c.read_holding_registers(100,1)) running=False else: c.open()
As stated in the documentation Chapter 3.1 Modbus register and coil mapping description:
For accessing each of the registers and coils there are two possible methods. As each group features its own processor all the registers of the given group are accessible through unit (address) according to the Group number (i.e. 1 –3) and at the same time through unit 0 through which all registers /coils of the given product are accessible. If access through unit 0 is used register number s are shifted according to 100*(group_number –1) formule. Thus, it is possible to use both methods. Example Register 1 of the Group 1 is accessible through the unit 1 on the address 1 and through the unit 0 on the register 1 as well. Register 1 of the group 2 is accessible through the unit 2 on register 1 and through the unit 0 on the register 101.
I should be able to read the registers from Group 2 through Group 1 shifted by 100. Reading the registers from Group 1 works fine but reading from 2 fails.
Output from script is as follows, the last line does not return the register value but None, which means no data returned.
pi@raspberrypi:~ $ python test.py [False, False, False, False, False, False, False, False, True, True, True, False] [False, False, False, False] [False, False, False, False, False, False, False, False, False, False, False, False] [0, 0, 0, 1, 7, 11317, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [1280, 1028, 785, 16, 16, 5125, 0, 5, 5000, 12192, 50, 50, 50, 50, 0, 0, 0, 4799, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 15] None
Can someone explain how to read the second module from modbusTCP?
Maybe the documentation has to be more clear how this is practically implemented.
tomas_hora administrators last edited by
@hschlabach I have not checked it deeply but it seems that the unit_id is not set properly. I have tested different module which works ok: https://github.com/riptideio/pymodbus/blob/master/examples/common/synchronous-client.py
Otherwise, your approach and understanding are OK.
hschlabach last edited by
Tomas thank you for your fast reply.
Using pymodbus.client fixed it. pyModbusTCP.client I used seems to be broken.