Compare commits
No commits in common. "eb740a91c064508a12d361ef4d192eaf9d18697d" and "35c4b0da19574ca3616aea7c7579809acdd3f529" have entirely different histories.
eb740a91c0
...
35c4b0da19
14
README.md
14
README.md
@ -1,16 +1,2 @@
|
|||||||
# modbus-utils
|
# modbus-utils
|
||||||
|
|
||||||
Internal Modbus TCP polling scripts for Galion Systems client sites.
|
Internal Modbus TCP polling scripts for Galion Systems client sites.
|
||||||
|
|
||||||
Reads holding registers from client PLCs, returns tag:value pairs for
|
|
||||||
upstream logging. See `config/sites.yaml.example` for config format.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```python
|
|
||||||
from galion_modbus.poll import poll_site
|
|
||||||
from galion_modbus.sites import load_sites
|
|
||||||
|
|
||||||
sites = load_sites()
|
|
||||||
data = poll_site(sites["walnut_creek"])
|
|
||||||
```
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
# Copy to sites.yaml and populate with real site data
|
|
||||||
sites:
|
sites:
|
||||||
walnut_creek:
|
walnut_creek:
|
||||||
plcs:
|
plcs:
|
||||||
@ -10,7 +9,6 @@ sites:
|
|||||||
"0": flow_rate_gpm
|
"0": flow_rate_gpm
|
||||||
"1": tank_level_ft
|
"1": tank_level_ft
|
||||||
"2": pump1_status
|
"2": pump1_status
|
||||||
"3": pump2_status
|
|
||||||
gary_in:
|
gary_in:
|
||||||
plcs:
|
plcs:
|
||||||
- host: 10.20.1.10
|
- host: 10.20.1.10
|
||||||
|
|||||||
@ -19,7 +19,6 @@ def read_holding_registers(host, port=502, unit=1, address=0, count=10):
|
|||||||
|
|
||||||
|
|
||||||
def poll_site(site_cfg):
|
def poll_site(site_cfg):
|
||||||
"""Poll all configured PLCs for a site and return {tag: value}."""
|
|
||||||
results = {}
|
results = {}
|
||||||
for plc in site_cfg.get("plcs", []):
|
for plc in site_cfg.get("plcs", []):
|
||||||
regs = read_holding_registers(
|
regs = read_holding_registers(
|
||||||
@ -34,7 +33,6 @@ def poll_site(site_cfg):
|
|||||||
|
|
||||||
|
|
||||||
def write_coil(host, port=502, unit=1, address=0, value=True):
|
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 = ModbusTcpClient(host, port=port)
|
||||||
c.connect()
|
c.connect()
|
||||||
try:
|
try:
|
||||||
@ -42,4 +40,4 @@ def write_coil(host, port=502, unit=1, address=0, value=True):
|
|||||||
return not rr.isError()
|
return not rr.isError()
|
||||||
finally:
|
finally:
|
||||||
c.close()
|
c.close()
|
||||||
fix timeout on slow RTUs
|
# increase timeout for slow RTUs
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
"""Site PLC configs — loaded from sites.yaml at runtime."""
|
|
||||||
import yaml
|
|
||||||
import os
|
|
||||||
|
|
||||||
_SITES_PATH = os.path.join(os.path.dirname(__file__), "..", "config", "sites.yaml")
|
|
||||||
|
|
||||||
|
|
||||||
def load_sites():
|
|
||||||
with open(_SITES_PATH) as fh:
|
|
||||||
return yaml.safe_load(fh)
|
|
||||||
Loading…
Reference in New Issue
Block a user