POCloud Driver Work
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
"""Define Meshify channel class."""
|
||||
import time
|
||||
from pycomm.ab_comm.clx import Driver as ClxDriver
|
||||
from pycomm.cip.cip_base import CommError, DataError
|
||||
import time
|
||||
|
||||
TAG_DATAERROR_SLEEPTIME = 5
|
||||
|
||||
|
||||
def binarray(intval):
|
||||
@@ -15,6 +17,8 @@ def binarray(intval):
|
||||
def read_tag(addr, tag, plc_type="CLX"):
|
||||
"""Read a tag from the PLC."""
|
||||
direct = plc_type == "Micro800"
|
||||
addr = str(addr)
|
||||
tag = str(tag)
|
||||
c = ClxDriver()
|
||||
try:
|
||||
if c.open(addr, direct_connection=direct):
|
||||
@@ -23,7 +27,11 @@ def read_tag(addr, tag, plc_type="CLX"):
|
||||
return v
|
||||
except DataError as e:
|
||||
c.close()
|
||||
print("Data Error during readTag({}, {}): {}".format(addr, tag, e))
|
||||
time.sleep(TAG_DATAERROR_SLEEPTIME)
|
||||
print("Data Error during readTag({}, {}, plc_type='{}'): {}".format(addr, tag, plc_type, e))
|
||||
else:
|
||||
raise DataError("no data")
|
||||
|
||||
except CommError:
|
||||
# err = c.get_status()
|
||||
c.close()
|
||||
@@ -33,7 +41,6 @@ def read_tag(addr, tag, plc_type="CLX"):
|
||||
c.close()
|
||||
print("AttributeError during readTag({}, {}): \n{}".format(addr, tag, e))
|
||||
c.close()
|
||||
return False
|
||||
|
||||
|
||||
def read_array(addr, tag, start, end, plc_type="CLX"):
|
||||
@@ -49,17 +56,18 @@ def read_array(addr, tag, start, end, plc_type="CLX"):
|
||||
# print('{} - {}'.format(tag_w_index, v))
|
||||
arr_vals.append(round(v[0], 4))
|
||||
# print(v)
|
||||
if len(arr_vals) > 0:
|
||||
if arr_vals:
|
||||
return arr_vals
|
||||
else:
|
||||
print("No length for {}".format(addr))
|
||||
return False
|
||||
print("No length for {}".format(addr))
|
||||
return False
|
||||
except Exception:
|
||||
print("Error during readArray({}, {}, {}, {})".format(addr, tag, start, end))
|
||||
err = c.get_status()
|
||||
c.close()
|
||||
print(err)
|
||||
return False
|
||||
c.close()
|
||||
return False
|
||||
|
||||
|
||||
def write_tag(addr, tag, val, plc_type="CLX"):
|
||||
@@ -84,7 +92,6 @@ def write_tag(addr, tag, val, plc_type="CLX"):
|
||||
c.close()
|
||||
print("Could not connect during writeTag({}, {}, {})".format(addr, tag, val))
|
||||
|
||||
|
||||
class Channel(object):
|
||||
"""Holds the configuration for a Meshify channel."""
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import time
|
||||
import logging
|
||||
from random import randint
|
||||
from device_base import deviceBase
|
||||
from Channel import Channel, read_tag, write_tag
|
||||
from Channel import PLCChannel, read_tag, write_tag
|
||||
import persistence
|
||||
from utilities import get_public_ip_address
|
||||
|
||||
@@ -37,8 +37,21 @@ logger.info("transferlite startup")
|
||||
WAIT_FOR_CONNECTION_SECONDS = 15
|
||||
WATCHDOG_ENABLE = True
|
||||
WATCHDOG_SEND_PERIOD = 3600 # Seconds, the longest amount of time before sending watchdog status
|
||||
PLC_IP_ADDRESS = "192.168.1.10"
|
||||
CHANNELS = []
|
||||
PLC_IP_ADDRESS = "10.20.4.37"
|
||||
CHANNELS = [
|
||||
PLCChannel(PLC_IP_ADDRESS, "ft01_flowmeter_bpd", "FT01_Flowmeter_BPD", "REAL", 100.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "auto_manual", "sts_autoMode", "BOOL", 1, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "ft01_flowmeter_gpm", "FT01_Flowmeter.val", "REAL", 10.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "lt11_pondlevel", "LT11_PondLevel.val", "REAL", 1.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "lt21_pondlevel", "LT21_PondLevel.val", "REAL", 1.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pt11_dischargepressure", "PT11_DischargePressure.val", "REAL", 10, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pt21_dischargepressure", "PT21_DischargePressure.val", "REAL", 10, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "flow_rate_setpoint", "set_FlowRateSetpoint", "REAL", 1.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "system1_frequency_setpoint", "set_ManualFrequencySP_System1", "REAL", 1.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "system2_frequency_setpoint", "set_ManualFrequencySP_System2", "REAL", 1.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "ft01_flowmeter_bpd_yesterday", "FT01_Flowmeter_History[1]", "REAL", 1.0, 600),
|
||||
PLCChannel(PLC_IP_ADDRESS, "ft01_flowmeter_bpd_today", "FT01_Flowmeter_History[0]", "REAL",100.0, 600)
|
||||
]
|
||||
|
||||
# PERSISTENCE FILE
|
||||
PERSIST = persistence.load()
|
||||
@@ -94,9 +107,10 @@ class start(threading.Thread, deviceBase):
|
||||
logger.warning("FORCE SEND: TRUE")
|
||||
|
||||
for chan in CHANNELS:
|
||||
chan.read()
|
||||
if chan.check(self.force_send):
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'transferlite')
|
||||
read_val = chan.read()
|
||||
if read_val is not None: # read returns None if it fails
|
||||
if chan.check(read_val, self.force_send):
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'transferlite')
|
||||
|
||||
|
||||
# print("transferlite driver still alive...")
|
||||
|
||||
Reference in New Issue
Block a user