From 3ae322488040d0d3bdd1b4b88cd9b105dcd34a6a Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Fri, 13 May 2016 10:26:57 -0500 Subject: [PATCH] Closes POCONSOLE-36. PLC Logic for handshaking and corrections to datalogger driver --- PLCHandshakeRungs.L5X | 50 +++++++++++++++++++++++++++++ tagserver.py | 9 +++--- www/assets/js/ng/controller_tags.js | 2 +- 3 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 PLCHandshakeRungs.L5X diff --git a/PLCHandshakeRungs.L5X b/PLCHandshakeRungs.L5X new file mode 100644 index 0000000..9934469 --- /dev/null +++ b/PLCHandshakeRungs.L5X @@ -0,0 +1,50 @@ + + + + + + + +00 + + + + + +00 + + + + + + + + + +5C B9 0E C0 60 EA 00 00 39 18 00 00 + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tagserver.py b/tagserver.py index 6c10d48..c42a697 100644 --- a/tagserver.py +++ b/tagserver.py @@ -25,7 +25,7 @@ device_types = {} def main(): - global web_address, scan_rate, save_all, tag_store, device_types + global web_address, scan_rate, save_all, tag_store, device_types, plc_handshake_tags, last_handshake_time try: # Get tags stored in database get_tag_request_data = {'where': '{"tag_class": 5}'} @@ -78,7 +78,7 @@ def main(): hs_tags = json.loads(get_hs_request.text) if len(hs_tags) > 0: for hs in hs_tags: - plc_handshake_tag[hs['name']] = Tag(hs['name'], hs['tag'], hs['id'], hs['data_type'], hs['change_threshold'], hs['guarantee_sec'], mapFn=hs['map_function'], ip_address=hs['deviceID']['address'], device_type=device_types[hs['deviceID']['device_type']]) + plc_handshake_tags[hs['name']] = Tag(hs['name'], hs['tag'], hs['id'], hs['data_type'], hs['change_threshold'], hs['guarantee_sec'], mapFn=hs['map_function'], ip_address=hs['deviceID']['address'], device_type=device_types[hs['deviceID']['device_type']]) except Exception, e: print("Error getting handshake tags: {}".format(e)) @@ -94,10 +94,11 @@ def main(): print("ERROR EVALUATING {}".format(tag)) traceback.print_exc() - if plc_handshake_tag: + if plc_handshake_tags: if time.time() - last_handshake_time > 30.0: for hs_tag in plc_handshake_tags: - hs_tag.write(1) + plc_handshake_tags[hs_tag].write(1) + print("Handshake with {} - {}".format(plc_handshake_tags[hs_tag].address, hs_tag)) last_handshake_time = time.time() time.sleep(scan_rate) diff --git a/www/assets/js/ng/controller_tags.js b/www/assets/js/ng/controller_tags.js index 42ab2ee..42af837 100644 --- a/www/assets/js/ng/controller_tags.js +++ b/www/assets/js/ng/controller_tags.js @@ -31,7 +31,7 @@ poconsole.controller('tagsCtrl', function($scope, $route, $http, $routeParams, P var getTag = tags.getTag(id); getTag.then(function(data){ $scope.error = false; - $scope.dTag = data.tag; + $scope.dTag = data.tag[0]; $log.info("Thinking about deleting tag with parameters: "+ JSON.stringify($scope.dTag)); }); };