Completes IPP-157 and adds custom PLC IP Address entry from POCloud, increments version number to 7

This commit is contained in:
Patrick McDonagh
2016-09-20 17:07:59 -05:00
parent 1993c53d21
commit 613ff29fd2
3 changed files with 59 additions and 3 deletions

View File

@@ -0,0 +1,17 @@
<form class='set_channel'>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="ipp_plcipaddress">PLC IP Address</label>
<input class="form-control" data-channelId="<%= channels['ipp.plcipaddress'].channelId %>"
data-techName="<%=channels['ipp.plcipaddress'].techName %>"
data-name="<%= channels['ipp.plcipaddress'].name %>"
data-val="<%=channels['ipp.plcipaddress'].value %>"
type="text"
id="<%= channels['ipp.plcipaddress'].channelId %>"
value="<%=channels['ipp.plcipaddress'].value %>">
</div>
<button class='btn btn-theme btn-block set_channel_btn' value='Save'>APPLY CHANGES</button>
</div>
</div>
</form>

View File

@@ -3,7 +3,7 @@
"driverFileName":"ipp.py",
"deviceName":"ipp",
"driverId":"0090",
"releaseVersion":"6",
"releaseVersion":"7",
"files": {
"file1":"ipp.py",
"file2":"micro800.py"

View File

@@ -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 = {
@@ -395,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:
@@ -497,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