Changes handshaking to be normal tag with class = 6, allows multiple handshake tags

This commit is contained in:
Patrick McDonagh
2016-05-13 09:41:30 -05:00
parent 01c23b142c
commit 548288bd29

View File

@@ -17,7 +17,7 @@ import json
web_address = "http://localhost:3000"
scan_rate = 30 # seconds
save_all = "test" # use True, False, or any string
plc_handshake_tag = None
plc_handshake_tags = {}
last_handshake_time = 0
tag_store = {}
@@ -72,15 +72,15 @@ def main():
print("I'll just use {} as the save-all parameter...".format(save_all))
try:
handshake_req_data = {"where": {"parameter": "plc_handshake_tag"}}
handshake_req = requests.get('{}/config'.format(web_address), params=handshake_req_data)
handshake_try = json.loads(handshake_req.text)
if len(handshake_req_try) > 0:
plc_handshake_tag = handshake_try[0]['val']
plc_handshake_tag = Tag("PLC Handshake", plc_handshake_tag, 0, "BOOL", 0, 0)
# Get tags stored in database
get_hs_request_data = {'where': '{"tag_class": 6}'}
get_hs_request = requests.get('{}/tag'.format(web_address), params=get_hs_request_data)
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']])
except Exception, e:
print("Error getting PLC Handshake Tag: {}".format(e))
print("I'll just use {} as the PLC Handshake Tag parameter...".format(plc_handshake_tag))
print("Error getting handshake tags: {}".format(e))
for t in tags:
# name, tag, db_id, data_type, change_threshold, guarantee_sec, mapFn=None, device_type='CLX', ip_address='192.168.1.10'):
@@ -96,7 +96,8 @@ def main():
if plc_handshake_tag:
if time.time() - last_handshake_time > 30.0:
plc_handshake_tag.write(1)
for hs_tag in plc_handshake_tags:
hs_tag.write(1)
last_handshake_time = time.time()
time.sleep(scan_rate)