Last active
June 25, 2023 07:11
-
-
Save git-developer/ec0c12d82ca3fe0fe7a9cbead819061c to your computer and use it in GitHub Desktop.
Python script to debug Modbus communication with a SBC ALD1D5FD energy meter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# | |
# required modules: pymodbus 'pymodbus[serial]' | |
# | |
from pymodbus.client import ModbusSerialClient | |
from pymodbus.framer.rtu_framer import ModbusRtuFramer | |
from pymodbus.framer.binary_framer import ModbusBinaryFramer | |
from pymodbus.framer.ascii_framer import ModbusAsciiFramer | |
import logging | |
def main(): | |
logging.basicConfig() | |
log = logging.getLogger() | |
log.setLevel(logging.DEBUG) | |
client = ModbusSerialClient( | |
port='/dev/ttyUSB0', | |
baudrate=19200, | |
bytesize=8, | |
parity='E', | |
stopbits=1, | |
timeout=1, | |
framer=ModbusRtuFramer | |
) | |
print('connected:', client.connect()) | |
print(client) | |
for address in range(3): | |
print('try address:', hex(address)) | |
for slave_id in range(30,31): | |
print(f'{slave_id=}') | |
print('read_holding_registers', client.read_holding_registers(address=address, count=1, slave=slave_id)) | |
print('read_device_information', client.read_device_information(address=address, count=1, slave=slave_id)) | |
client.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: