Compare commits
No commits in common. "35c4b0da19574ca3616aea7c7579809acdd3f529" and "eb740a91c064508a12d361ef4d192eaf9d18697d" have entirely different histories.
35c4b0da19
...
eb740a91c0
14
README.md
14
README.md
@ -1,2 +1,16 @@
|
|||||||
# 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,3 +1,4 @@
|
|||||||
|
# Copy to sites.yaml and populate with real site data
|
||||||
sites:
|
sites:
|
||||||
walnut_creek:
|
walnut_creek:
|
||||||
plcs:
|
plcs:
|
||||||
@ -9,6 +10,7 @@ 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,6 +19,7 @@ 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(
|
||||||
@ -33,6 +34,7 @@ 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:
|
||||||
@ -40,4 +42,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()
|
||||||
# increase timeout for slow RTUs
|
fix timeout on slow RTUs
|
||||||
|
|||||||
10
galion_modbus/sites.py
Normal file
10
galion_modbus/sites.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
"""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