Added flowunits channel
This commit is contained in:
@@ -2,22 +2,33 @@
|
||||
|
||||
import threading
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from random import randint
|
||||
# PERSISTENCE FILE
|
||||
import persistence
|
||||
PERSIST = persistence.load("extra_data.json")
|
||||
if not PERSIST:
|
||||
PERSIST = {'ip_address': '192.168.1.10', 'download_pycomm': True}
|
||||
PERSIST = {'ip_address': '192.168.1.10', 'download_pycomm': True, 'flowmeter_units': 'GPM'}
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
os.system('echo "" > /root/python_firmware/drivers/modbusMap.p')
|
||||
PLC_IP_ADDRESS = PERSIST['ip_address']
|
||||
from device_base import deviceBase
|
||||
import urllib
|
||||
if PERSIST['download_pycomm']:
|
||||
try:
|
||||
urllib.urlretrieve('http://s3.amazonaws.com/pocloud-drivers/pycomm/clx.py', '/root/python_firmware/pycomm/ab_comm/clx.py')
|
||||
urllib.urlretrieve('http://s3.amazonaws.com/pocloud-drivers/pycomm/cip_base.py', '/root/python_firmware/pycomm/cip/cip_base.py')
|
||||
PERSIST['download_pycomm'] = False
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
except Exception as e:
|
||||
print("Could not download latest pycomm update: {}".format(e))
|
||||
|
||||
from Channel import PLCChannel, ModbusChannel,read_tag, write_tag, TAG_DATAERROR_SLEEPTIME
|
||||
from utilities import get_public_ip_address, get_additional_tags, convert_int
|
||||
from file_logger import filelogger as log
|
||||
from Tags import tags
|
||||
import os
|
||||
import urllib
|
||||
|
||||
|
||||
path = "/root/python_firmware/drivers/additional_tags.py"
|
||||
|
||||
@@ -28,6 +39,8 @@ if os.stat(path).st_size == 0:
|
||||
f.write("from advvfdipp import PLC_IP_ADDRESS\n")
|
||||
f.write("additional_tags = []")
|
||||
f.close()
|
||||
|
||||
|
||||
from additional_tags import additional_tags
|
||||
|
||||
_ = None
|
||||
@@ -35,7 +48,7 @@ _ = None
|
||||
log.info("advvfdipp startup")
|
||||
|
||||
# GLOBAL VARIABLES
|
||||
WAIT_FOR_CONNECTION_SECONDS = 60
|
||||
WAIT_FOR_CONNECTION_SECONDS = 30
|
||||
IP_CHECK_PERIOD = 60
|
||||
WATCHDOG_ENABLE = False
|
||||
WATCHDOG_CHECK_PERIOD = 60
|
||||
@@ -56,7 +69,7 @@ class start(threading.Thread, deviceBase):
|
||||
mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "13"
|
||||
self.version = "14"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
@@ -81,20 +94,22 @@ class start(threading.Thread, deviceBase):
|
||||
time.sleep(1)
|
||||
log.info("BOOM! Starting advvfdipp driver...")
|
||||
|
||||
if PERSIST['download_pycomm']:
|
||||
try:
|
||||
urllib.urlretrieve('http://s3.amazonaws.com/pocloud-drivers/pycomm/clx.py', '/root/python_firmware/pycomm/ab_comm/clx.py')
|
||||
urllib.urlretrieve('http://s3.amazonaws.com/pocloud-drivers/pycomm/cip_base.py', '/root/python_firmware/pycomm/cip/cip_base.py')
|
||||
PERSIST['download_pycomm'] = False
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
except Exception as e:
|
||||
print("Could not download latest pycomm update: {}".format(e))
|
||||
|
||||
|
||||
#self._check_watchdog()
|
||||
self._check_ip_address()
|
||||
|
||||
self.nodes["advvfdipp_0199"] = self
|
||||
|
||||
try:
|
||||
if PERSIST['flowmeter_units']:
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipp')
|
||||
else:
|
||||
PERSIST['flowmeter_units'] = "GPM"
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipp')
|
||||
except:
|
||||
PERSIST['flowmeter_units'] = "GPM"
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipp')
|
||||
send_loops = 0
|
||||
convert_list = ["Device_Status_INT","sts_PID_Control","Downhole_Sensor_Status_INT","alarm_Flowmeter","alarm_IntakePressure",
|
||||
"alarm_IntakeTemperature","alarm_TubingPressure","alarm_VFD","alarm_Lockout","alarm_FluidLevel","Run_Permissive_INT",
|
||||
@@ -197,3 +212,9 @@ class start(threading.Thread, deviceBase):
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
def advvfdipp_flowunits(self, name, value):
|
||||
new_val = json.loads(str(value).replace("'", '"'))
|
||||
PERSIST['flowmeter_units'] = new_val
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipp')
|
||||
@@ -8,7 +8,7 @@
|
||||
"file4": "Tags.py"
|
||||
},
|
||||
"deviceName": "advvfdipp",
|
||||
"releaseVersion": "13",
|
||||
"releaseVersion": "14",
|
||||
"driverFileName": "advvfdipp.py",
|
||||
"driverId": "0100"
|
||||
}
|
||||
Reference in New Issue
Block a user