Adds handshaking
This commit is contained in:
2
tag
2
tag
Submodule tag updated: c610c9fa2c...156e3c4194
18
tagserver.py
18
tagserver.py
@@ -17,6 +17,8 @@ import json
|
||||
web_address = "http://localhost:3000"
|
||||
scan_rate = 30 # seconds
|
||||
save_all = "test" # use True, False, or any string
|
||||
plc_handshake_tag = None
|
||||
last_handshake_time = 0
|
||||
|
||||
tag_store = {}
|
||||
device_types = {}
|
||||
@@ -69,6 +71,17 @@ def main():
|
||||
print("Error getting save-all: {}".format(e))
|
||||
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)
|
||||
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))
|
||||
|
||||
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'):
|
||||
tag_store[t['name']] = Tag(t['name'], t['tag'], t['id'], t['data_type'], t['change_threshold'], t['guarantee_sec'], mapFn=t['map_function'], ip_address=t['deviceID']['address'], device_type=device_types[t['deviceID']['device_type']])
|
||||
@@ -80,6 +93,11 @@ def main():
|
||||
except:
|
||||
print("ERROR EVALUATING {}".format(tag))
|
||||
traceback.print_exc()
|
||||
|
||||
if plc_handshake_tag:
|
||||
if time.time() - last_handshake_time > 30.0:
|
||||
plc_handshake_tag.write(1)
|
||||
last_handshake_time = time.time()
|
||||
time.sleep(scan_rate)
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user