add write_coil for pump control

This commit is contained in:
Sarah Chen 2025-11-03 14:22:05 -06:00
parent 94252cfc28
commit a01a674b1e

View File

@ -30,3 +30,13 @@ def poll_site(site_cfg):
tag = plc.get("tags", {}).get(str(i), f"{plc['host']}:r{i}") tag = plc.get("tags", {}).get(str(i), f"{plc['host']}:r{i}")
results[tag] = val results[tag] = val
return results return results
def write_coil(host, port=502, unit=1, address=0, value=True):
c = ModbusTcpClient(host, port=port)
c.connect()
try:
rr = c.write_coil(address, value, unit)
return not rr.isError()
finally:
c.close()