-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
61 lines (43 loc) · 1.55 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# -*- coding: utf-8 -*-
import logging
import numpy as np
from opcua import Client
from subhandler import SubHandler
from time import sleep
from IPython import embed
def main():
logging.basicConfig(level=logging.WARN)
client = Client("opc.tcp://WIN-B3JSS0UOON2:49320")
try:
client.connect()
tag1 = client.get_node("ns=2;s=Channel1.Device1.Tag1")
tag2 = client.get_node("ns=2;s=Simulation Examples.Functions.Ramp3")
tag3 = client.get_node("ns=2;s=Simulation Examples.Functions.Sine1")
tags = [tag1, tag2, tag3]
handler = SubHandler(tags)
sub = client.create_subscription(500, handler)
handles = [sub.subscribe_data_change(tag1),
sub.subscribe_data_change(tag2),
sub.subscribe_data_change(tag3)]
sleep(0.1)
embed()
print("")
print("Tag1 is: ", handler.storage[0])
print("")
print("Tag2 is: ", handler.storage[1])
print("")
print("Tag3 is: ", handler.storage[2])
print("")
algorithm = SubHandler.extreme_value_analysis
flags = list(map(lambda i: algorithm(np.array(i)), handler.storage))
for i in range(len(handles)):
if flags[i] == True:
sub.unsubscribe(handles[i])
print(tags[i], "is broken!")
else:
print(tags[i], "is OK!")
sub.delete()
finally:
client.disconnect()
if __name__ == "__main__":
main()