Skip to content

Instantly share code, notes, and snippets.

@osaether
Created December 8, 2018 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save osaether/aa7f82da4b5b4a8916fb239cb1fa6ebc to your computer and use it in GitHub Desktop.
Save osaether/aa7f82da4b5b4a8916fb239cb1fa6ebc to your computer and use it in GitHub Desktop.
Show state of Venus GX Relays
#!/usr/bin/env python
from pymodbus.constants import Defaults
from pymodbus.constants import Endian
from pymodbus.client.sync import ModbusTcpClient as ModbusClient
from pymodbus.payload import BinaryPayloadDecoder
Defaults.Timeout = 25
Defaults.Retries = 5
client = ModbusClient('ipaddress.of.venus', port='502')
result = client.read_input_registers(806, 2)
decoder = BinaryPayloadDecoder.fromRegisters(result.registers, endian=Endian.Big)
relay1=decoder.decode_16bit_uint()
relay2=decoder.decode_16bit_uint()
print("Relay1: %d, Relay2: %d" % (relay1, relay2))
@osaether
Copy link
Author

osaether commented Dec 8, 2018

If you get this error: "unexpected keyword argument 'endian'" try replacing
endian=Endian.Big
with
byteorder=Endian.Big

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment