Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modbus Holding Register Scanner
40001: 0000110000000001
40002: 0000100000000001
40003: 0000000000000000
40004: 0000000000000000
40005: 0000000000000000
40006: 0000000000000000
40007: 0000000100000010
40008: 0000000000011100
40009: 0100001010001011
40010: 0101100111101011
40011: 0000000111111001
40012: 0000000000000000
40013: 0000000000000000
40014: 0011111111000000
40015: 0000000000000000
40016: 0100000001000000
40017: 0000000000000000
40018: 0000000000000000
40019: 0000000000000000
40020: 0000000000000000
"""
Modbus Holding Register Scanner
A simple blocking script intended to print out all the holding registers on a
modbus device in binary. Used to compare data with user manual specifications.
"""
ip_address = "192.168.1.100"
registers = {"start": 40001, "end": 40020}
from pymodbus.client.sync import ModbusTcpClient
client = ModbusTcpClient(ip_address)
success = client.connect()
if not success:
raise Exception("Could not connect to {}".format(ip_address))
result = client.read_holding_registers(address=registers["start"] - 40001,
count=registers["end"] - registers["start"] + 1)
print("\n".join("{}: {:016b}".format(registers["start"] + i, r)
for i, r in enumerate(result.registers)))
client.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment