|
|
|
|
@@ -3,12 +3,15 @@
|
|
|
|
|
import threading
|
|
|
|
|
import traceback
|
|
|
|
|
import time
|
|
|
|
|
import json
|
|
|
|
|
import socket
|
|
|
|
|
import os
|
|
|
|
|
from device_base import deviceBase
|
|
|
|
|
import micro800 as u800
|
|
|
|
|
|
|
|
|
|
addr = '10.20.4.5'
|
|
|
|
|
channels = {}
|
|
|
|
|
version = "4"
|
|
|
|
|
version = "7"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e300_current = {
|
|
|
|
|
@@ -175,6 +178,10 @@ class start(threading.Thread, deviceBase):
|
|
|
|
|
global channels
|
|
|
|
|
channels = {
|
|
|
|
|
'automode': Channel('automode', 'Auto_Mode', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
'alarmdhpressure': Channel('alarmdhpressure', 'alarm_DHPressure', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
'alarmdhtemperature': Channel('alarmdhtemperature', 'alarm_DHTemperature', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
'alarme300': Channel('alarme300', 'alarm_E300', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
'alarmtubingpressure': Channel('alarmtubingpressure', 'alarm_TubingPressure', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
'cfgcflasetting': Channel('cfgcflasetting', 'cfg_C_FLASetting', 86400, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=True),
|
|
|
|
|
'cfgcleartripcountafter': Channel('cfgcleartripcountafter', 'cfg_ClearTripCountAfter', 86400, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=False),
|
|
|
|
|
'cfggfgroundfaultinhibittime': Channel('cfggfgroundfaultinhibittime', 'cfg_GF_GroundFaultInhibitTime', 86400, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=True),
|
|
|
|
|
@@ -247,7 +254,7 @@ class start(threading.Thread, deviceBase):
|
|
|
|
|
'cfgvvoltagemode': Channel('cfgvvoltagemode', 'cfg_V_VoltageMode', 86400, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=True),
|
|
|
|
|
'cfgwrite': Channel('cfgwrite', 'cfg_WRITE', 86400, self.sendtodbJSON, writeable=True, e300_param=False),
|
|
|
|
|
'contactorstatus': Channel('contactorstatus', 'Contactor_Status', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
'devicestatus': Channel('devicestatus', 'Device_Status_INT', 3600, self.sendtodbJSON, writeable=False, e300_param=False, map_obj=device_status),
|
|
|
|
|
'devicestatus': Channel('devicestatus', 'Device_Status_INT', 3600, self.sendtodb, writeable=False, e300_param=False, map_obj=device_status),
|
|
|
|
|
'dhdownholestatusint': Channel('dhdownholestatusint', 'DH_DownholeStatus_INT', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False),
|
|
|
|
|
'dhfluidlevel': Channel('dhfluidlevel', 'DH_Fluid_Level', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False),
|
|
|
|
|
'dhintakepressure': Channel('dhintakepressure', 'DH_IntakePressure', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False),
|
|
|
|
|
@@ -353,10 +360,10 @@ class start(threading.Thread, deviceBase):
|
|
|
|
|
'tripenablevvoltageunbalance': Channel('tripenablevvoltageunbalance', 'TripEnable_V_VoltageUnbalance', 3600, self.sendtodbJSON, writeable=True, e300_param=False),
|
|
|
|
|
'tripresetcmd': Channel('tripresetcmd', 'TripResetCmd', 3600, self.sendtodbJSON, writeable=True, e300_param=False),
|
|
|
|
|
'tripstatus': Channel('tripstatus', 'TripStatus', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
'tripstatuscontrolint': Channel('tripstatuscontrolint', 'TripStatusControl_INT', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_control),
|
|
|
|
|
'tripstatuscurrentint': Channel('tripstatuscurrentint', 'TripStatusCurrent_INT', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_current),
|
|
|
|
|
'tripstatuspowerint': Channel('tripstatuspowerint', 'TripStatusPower_INT', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_power),
|
|
|
|
|
'tripstatusvoltageint': Channel('tripstatusvoltageint', 'TripStatusVoltage_INT', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_voltage),
|
|
|
|
|
'tripstatuscontrolint': Channel('tripstatuscontrolint', 'TripStatusControl_INT', 3600, self.sendtodb, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_control),
|
|
|
|
|
'tripstatuscurrentint': Channel('tripstatuscurrentint', 'TripStatusCurrent_INT', 3600, self.sendtodb, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_current),
|
|
|
|
|
'tripstatuspowerint': Channel('tripstatuspowerint', 'TripStatusPower_INT', 3600, self.sendtodb, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_power),
|
|
|
|
|
'tripstatusvoltageint': Channel('tripstatusvoltageint', 'TripStatusVoltage_INT', 3600, self.sendtodb, writeable=False, change_threshold=1.0, e300_param=False, map_obj=e300_voltage),
|
|
|
|
|
'valoverloadtripcount': Channel('valoverloadtripcount', 'val_OverloadTripCount', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False),
|
|
|
|
|
'valtripcount': Channel('valtripcount', 'val_TripCount', 3600, self.sendtodbJSON, writeable=False, change_threshold=1.0, e300_param=False),
|
|
|
|
|
'voltageok': Channel('voltageok', 'VoltageOK', 3600, self.sendtodbJSON, writeable=False, e300_param=False),
|
|
|
|
|
@@ -377,10 +384,10 @@ class start(threading.Thread, deviceBase):
|
|
|
|
|
'warningenablevundervoltage': Channel('warningenablevundervoltage', 'WarningEnable_V_Undervoltage', 3600, self.sendtodbJSON, writeable=True, e300_param=False),
|
|
|
|
|
'warningenablevvoltageunbalance': Channel('warningenablevvoltageunbalance', 'WarningEnable_V_VoltageUnbalance', 3600, self.sendtodbJSON, writeable=True, e300_param=False),
|
|
|
|
|
'warningstatus': Channel('warningstatus', 'WarningStatus', 3600, self.sendtodbJSON, writeable=True, e300_param=False),
|
|
|
|
|
'warningstatuscontrolint': Channel('warningstatuscontrolint', 'WarningStatusControl_INT', 3600, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_control),
|
|
|
|
|
'warningstatuscurrentint': Channel('warningstatuscurrentint', 'WarningStatusCurrent_INT', 3600, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_current),
|
|
|
|
|
'warningstatuspowerint': Channel('warningstatuspowerint', 'WarningStatusPower_INT', 3600, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_power),
|
|
|
|
|
'warningstatusvoltageint': Channel('warningstatusvoltageint', 'WarningStatusVoltage_INT', 3600, self.sendtodbJSON, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_voltage),
|
|
|
|
|
'warningstatuscontrolint': Channel('warningstatuscontrolint', 'WarningStatusControl_INT', 3600, self.sendtodb, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_control),
|
|
|
|
|
'warningstatuscurrentint': Channel('warningstatuscurrentint', 'WarningStatusCurrent_INT', 3600, self.sendtodb, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_current),
|
|
|
|
|
'warningstatuspowerint': Channel('warningstatuspowerint', 'WarningStatusPower_INT', 3600, self.sendtodb, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_power),
|
|
|
|
|
'warningstatusvoltageint': Channel('warningstatusvoltageint', 'WarningStatusVoltage_INT', 3600, self.sendtodb, writeable=True, change_threshold=1.0, e300_param=False, map_obj=e300_voltage),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
|
|
|
|
|
@@ -391,9 +398,27 @@ class start(threading.Thread, deviceBase):
|
|
|
|
|
self.daemon = True
|
|
|
|
|
self.version = version
|
|
|
|
|
self.device_address = addr
|
|
|
|
|
if os.path.exists('./plcaddr.json'):
|
|
|
|
|
with open('plcaddr.json', "rb") as addr_file:
|
|
|
|
|
data = json.loads(addr_file.read())
|
|
|
|
|
if data['plc_address']:
|
|
|
|
|
try:
|
|
|
|
|
socket.inet_aton(data['plc_address'])
|
|
|
|
|
addr = data['plc_address']
|
|
|
|
|
self.device_address = addr
|
|
|
|
|
print("USING {} AS PLC IP ADDRESS (FROM JSON)".format(addr))
|
|
|
|
|
except:
|
|
|
|
|
print("plc_address exists in plcaddr.json, but it's not a valid ip address")
|
|
|
|
|
else:
|
|
|
|
|
print("no plc_address in plcaddr.json")
|
|
|
|
|
else:
|
|
|
|
|
print("No stored plcaddr.json file. Let's create one...'")
|
|
|
|
|
with open("plcaddr.json", "wb") as addr_file:
|
|
|
|
|
json.dump({"plc_address": addr}, addr_file)
|
|
|
|
|
|
|
|
|
|
self.finished = threading.Event()
|
|
|
|
|
threading.Thread.start(self)
|
|
|
|
|
self.sendtodbJSON("device_address", self.device_address, 0)
|
|
|
|
|
self.sendtodbJSON("plcipaddress", self.device_address, 0)
|
|
|
|
|
try:
|
|
|
|
|
self.setupChannels()
|
|
|
|
|
except:
|
|
|
|
|
@@ -493,3 +518,21 @@ class start(threading.Thread, deviceBase):
|
|
|
|
|
return channels[name].write(value)
|
|
|
|
|
except Exception, e:
|
|
|
|
|
print("Exception during genericSet: {}".format(e))
|
|
|
|
|
|
|
|
|
|
def ipp_plcipaddress(self, name, value):
|
|
|
|
|
global addr
|
|
|
|
|
value_ascii = value.encode('ascii', 'ignore')
|
|
|
|
|
try:
|
|
|
|
|
socket.inet_aton(value_ascii)
|
|
|
|
|
addr = value_ascii
|
|
|
|
|
self.device_address = addr
|
|
|
|
|
with open("plcaddr.json", "wb") as addr_file:
|
|
|
|
|
json.dump({"plc_address": addr}, addr_file)
|
|
|
|
|
print("Set PLC IP Address to {}".format(addr))
|
|
|
|
|
self.sendtodb("plcipaddress", addr, 0)
|
|
|
|
|
return True
|
|
|
|
|
except Exception, e:
|
|
|
|
|
r = "Unable to set PLC IP address to {}: {}".format(value_ascii, e)
|
|
|
|
|
print(r)
|
|
|
|
|
return r
|
|
|
|
|
|
|
|
|
|
|