Fixes direct driver

This commit is contained in:
Patrick McDonagh
2016-05-23 11:27:16 -05:00
parent 80a86f76f1
commit 81bb6e5471

View File

@@ -1,30 +1,13 @@
#!/usr/bin/python
# import types
# import traceback
# import binascii
import threading
import time
# import thread
# import os
# import struct
# import sys
# import serial
# import minimalmodbus
import pickle
from device_base import deviceBase
# from datetime import datetime
from pycomm.ab_comm.clx import Driver as ClxDriver
import logging
from collections import deque
import traceback
import requests
try:
import json
except:
import simplejson as json
import calendar
from pycomm.ab_comm.clx import Driver as ClxDriver
from collections import deque
data_source = "PLC"
plc_ip = '192.168.1.20'
@@ -32,7 +15,6 @@ plc_ip = '192.168.1.20'
def readTag(addr, tag):
c = ClxDriver()
if c.open(addr):
try:
v = c.read_tag(tag)
@@ -47,13 +29,7 @@ def readTag(addr, tag):
def writeTag(addr, tag, val):
logging.basicConfig(
filename="ClxDriver.log",
format="%(levelname)-10s %(asctime)s %(message)s",
level=logging.DEBUG
)
c = ClxDriver()
if c.open(addr):
try:
# typ = getTagType(addr, tag)
@@ -122,7 +98,7 @@ go_channels = {
}
statusCh = Channel('status', 'Pump.Run_Status', 'str', 0, 0)
gaugeOffCh = Channel('go','Gauge_Off_Command', 'boolean', 0, 0)
gaugeOffCh = Channel('go', 'Gauge_Off_Command', 'boolean', 0, 0)
channels = {
'downhole_adjusted_gross_stroke': Channel('downhole_adjusted_gross_stroke', 'Card_Past[1].Downhole_AdjustedGrossStroke', 'float', 5.0, 3600),
@@ -196,16 +172,17 @@ class Card():
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([, ])
self.dc.append([down_pos, down_lod])
def stringify(self):
''' returns a list of two strings [surface card, downhole card]'''
sc_str = "["
dc_str = "["
for i in range(0, self.num_points):
for i in range(0, len(self.sc)):
sc_str = sc_str + "[{},{}],".format(self.sc[i][0], self.sc[i][1])
dc_str = dc_str + "[{},{}],".format(self.dc[i][0], self.dc[i][1])
sc_str = sc_str + "[{},{}]]".format(self.sc[0][0], self.sc[0][1])
for j in range(0, len(self.dc)):
dc_str = dc_str + "[{},{}],".format(self.dc[j][0], self.dc[j][1])
dc_str = dc_str + "[{},{}]]".format(self.dc[0][0], self.dc[0][1])
return[sc_str, dc_str]
@@ -283,7 +260,6 @@ class start(threading.Thread, deviceBase):
for go in go_channels:
self.channelCheck(go_channels[go], self.forceSend)
runLoopStatus = "Stroke Parameter Data"
for ch in channels:
self.channelCheck(channels[ch], self.forceSend)
@@ -298,6 +274,7 @@ class start(threading.Thread, deviceBase):
cards = current_card.stringify()
self.sendtodbJSON("sc", cards[0], current_time)
self.sendtodbJSON("dc", cards[1], current_time)
self.last_card_sent_time = time.time()
current_card.sent = True
self.card_storage.appendleft(current_card)
while len(self.card_storage) > self.card_storage_limit:
@@ -308,6 +285,7 @@ class start(threading.Thread, deviceBase):
cstr = c.stringify()
self.sendtodbJSON("sc", cstr[0], c.read_time)
self.sendtodbJSON("dc", cstr[1], c.read_time)
self.last_card_sent_time = time.time()
else:
current_time = time.time()
current_card = Card(current_time)
@@ -316,6 +294,7 @@ class start(threading.Thread, deviceBase):
cards = current_card.stringify()
self.sendtodbJSON("sc", cards[0], current_time)
self.sendtodbJSON("dc", cards[1], current_time)
self.last_card_sent_time = time.time()
current_card.sent = True
self.card_storage.appendleft(current_card)
runLoopStatus = "Complete"
@@ -356,20 +335,6 @@ class start(threading.Thread, deviceBase):
statusCh.last_value = status
return status
def checkEvents(self):
data = json.loads(requests.get(self.device_address + "/json/event_list").text)
events = data["events"]
for event in events:
if int(event["id"]) not in self.eventIds:
timestamp = calendar.timegm(time.strptime(event["datetime"], '%Y-%m-%dT%H:%M:%S.%fZ'))
# we have a new event
self.sendtodbJSON("events", json.dumps(event), timestamp)
self.eventIds.append(int(event["id"]))
if len(self.eventIds) > 50:
del self.eventIds[0]
with open('eventIds.p', 'wb') as handle:
pickle.dump(self.eventIds, handle)
def poc_sync(self, name, value):
self.sendtodb("connected", "true", 0)
return True