Skip to content

Instantly share code, notes, and snippets.

@ondrejh
Last active May 30, 2019 19:52
Show Gist options
  • Save ondrejh/fd19fd33b1760115eb3970b08b1c3b4b to your computer and use it in GitHub Desktop.
Save ondrejh/fd19fd33b1760115eb3970b08b1c3b4b to your computer and use it in GitHub Desktop.
first succesfull sdm120 module communication
#!/usr/bin/env python3
# http://www.eastrongroup.com/data/uploads/Eastron_SDM120-Modbus_user_manual_2016_V2_6.pdf
# http://www.eastroneurope.com/media/_system/tech_specs/3914/SDM120%20PROTOCOL.pdf
from serial import *
from time import sleep
PORT_NAME = "/dev/ttyUSB0"
BAUD_RATE = 2400
PARITY = PARITY_NONE
PERIOD = 5
if __name__ == "__main__":
while True:
with Serial(PORT_NAME, BAUD_RATE, parity=PARITY, timeout=0.5) as port:
#msg = b'\x01\x08\x00\x00\xAA\x55\x5E\x94' # diagnostics (doesn't work - not implemented probably)
msg = b'\x01\x03\x00\x00\x00\x02\xC4\x0B' # read holding registers (answers)
port.write(msg)
answ = port.readlines()
print(msg, answ)
sleep(PERIOD)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment