added ReadArray function for reading arrays of points

This commit is contained in:
Patrick McDonagh
2016-05-26 10:16:34 -05:00
parent 81bb6e5471
commit a882061d05

View File

@@ -10,7 +10,7 @@ from pycomm.ab_comm.clx import Driver as ClxDriver
from collections import deque
data_source = "PLC"
plc_ip = '192.168.1.20'
plc_ip = '192.168.1.10'
def readTag(addr, tag):
@@ -28,6 +28,30 @@ def readTag(addr, tag):
c.close()
def readArray(addr, tag, start, end):
c = ClxDriver()
if c.open(addr):
arr_vals = []
try:
for i in range(start, end):
tag_w_index = tag + "[{}]".format(i)
v = c.read_tag(tag_w_index)
# print('{} - {}'.format(tag_w_index, v))
arr_vals.append(round(v[0], 4))
# print(v)
if len(arr_vals) > 0:
return arr_vals
else:
return False
print("No length for {}".format(addr))
except Exception:
err = c.get_status()
c.close()
print err
pass
c.close()
def writeTag(addr, tag, val):
c = ClxDriver()
if c.open(addr):
@@ -164,15 +188,23 @@ class Card():
self.card_id = readTag(plc_ip, "Card_Past[1].ID")[0]
self.num_points = int(readTag(plc_ip, "Card_Past[1].Num_Points")[0])
print("reading {} from card ID {}".format(self.num_points, self.card_id))
for i in range(0, self.num_points):
surf_pos = round(float(readTag(plc_ip, 'Card_Past[1].Surface_Position[{}]'.format(i))[0]), 3)
surf_lod = round(float(readTag(plc_ip, 'Card_Past[1].Surface_Load[{}]'.format(i))[0]), 3)
down_pos = round(float(readTag(plc_ip, 'Card_Past[1].Downhole_Position[{}]'.format(i))[0]), 3)
down_lod = round(float(readTag(plc_ip, 'Card_Past[1].Downhole_Load[{}]'.format(i))[0]), 3)
if not (surf_pos == 0.0) and not (surf_lod == 0.0):
self.sc.append([surf_pos, surf_lod])
if not (down_pos == 0.0) and not (down_lod == 0.0):
self.dc.append([down_pos, down_lod])
if self.num_points > 1:
surf_pos = readArray(plc_ip, 'Card_Past[1].Surface_Position', 1, self.num_points)
surf_lod = readArray(plc_ip, 'Card_Past[1].Surface_Load', 1, self.num_points)
down_pos = readArray(plc_ip, 'Card_Past[1].Downhole_Position', 1, self.num_points)
down_lod = readArray(plc_ip, 'Card_Past[1].Downhole_Load', 1, self.num_points)
if surf_pos and surf_lod and down_pos and down_lod:
for i in range(0, self.num_points-1):
if not (surf_pos[i] == 0.0) and not (surf_lod[i] == 0.0):
self.sc.append([surf_pos[i], surf_lod[i]])
if not (down_pos[i] == 0.0) and not (down_lod[i] == 0.0):
self.dc.append([down_pos[i], down_lod[i]])
return True
else:
print("couldn't get a full set of position/load pairs")
return False
def stringify(self):
''' returns a list of two strings [surface card, downhole card]'''
@@ -194,7 +226,7 @@ class start(threading.Thread, deviceBase):
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.forceSend = True
self.forceSend = False
self.version = "3"
self.device_address = "http://192.168.1.30/"
# self.device_address = "http://localhost/"
@@ -244,6 +276,8 @@ class start(threading.Thread, deviceBase):
def run(self):
self.runLoopStatus = ""
while True:
if self.forceSend:
print "FORCE SEND: TRUE"
try:
self.statusChanged = False
runLoopStatus = "checkStatus"
@@ -256,7 +290,10 @@ class start(threading.Thread, deviceBase):
self.channelCheck(dt_channels[dt], self.forceSend)
runLoopStatus = "checkGaugeOffData"
if gaugeOffCh.read(self.forceSend):
gaugeOffCh.read(False)
go = (gaugeOffCh.value == 1)
if go:
print("Gauge Off!")
for go in go_channels:
self.channelCheck(go_channels[go], self.forceSend)