add write_coil for pump control commands

This commit is contained in:
Sarah Chen 2026-08-28 19:28:13 -05:00
parent 0fe31a31a5
commit 1eb1675ec3

View File

@ -31,3 +31,14 @@ 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):
"""Write single coil — used for pump enable/disable commands."""
c = ModbusTcpClient(host, port=port)
c.connect()
try:
rr = c.write_coil(address, value, unit)
return not rr.isError()
finally:
c.close()