diff --git a/POCloud/Direct/poc.py b/POCloud/Direct/poc.py index 6164d78..276c79e 100644 --- a/POCloud/Direct/poc.py +++ b/POCloud/Direct/poc.py @@ -1,7 +1,7 @@ #!/usr/bin/python # import types -# import traceback +import traceback # import binascii import threading import time @@ -30,6 +30,7 @@ plc_ip = '192.168.1.20' def readTag(addr, tag): + time.sleep(0.01) c = ClxDriver() if c.open(addr): try: @@ -182,14 +183,22 @@ class Card(): 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]) + try: + 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) + if not (surf_pos == 0.0) and not (surf_lod == 0.0): + self.sc.append([surf_pos, surf_lod]) + except: + print("Unable to read surface point {}".format(i)) + + try: + 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 (down_pos == 0.0) and not (down_lod == 0.0): + self.dc.append([down_pos, down_lod]) + except: + print("Unable to read downhole point {}".format(i)) + def stringify(self): ''' returns a list of two strings [surface card, downhole card]''' @@ -317,6 +326,7 @@ class start(threading.Thread, deviceBase): except Exception, e: sleep_timer = 20 print "Error during {0} of run loop: {1}\nWill try again in {2} seconds...".format(runLoopStatus, e, sleep_timer) + traceback.print_exc() time.sleep(sleep_timer) def checkStatus(self): @@ -331,7 +341,11 @@ class start(threading.Thread, deviceBase): 1000: 'PLC Error', 9999: 'No Response' } - status = statusMap[int(readTag(plc_ip, "Pump.Run_Status")[0])] + s = int(readTag(plc_ip, "Pump.Run_Status")[0]) + try: + status = statusMap[s] + except: + print("Could not map status for {}".format(s)) if status: date = time.time()