-
Notifications
You must be signed in to change notification settings - Fork 368
/
Copy pathclient_to_kepware.py
45 lines (32 loc) · 1.34 KB
/
client_to_kepware.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
import sys
import asyncio
sys.path.insert(0, "..")
import logging
from asyncua import Client
class SubHandler:
"""
Subscription Handler. To receive events from server for a subscription
"""
def datachange_notification(self, node, val, data):
print("Python: New data change event", node, val)
def event_notification(self, event):
print("Python: New event", event)
async def main():
url = "opc.tcp://localhost:53530/OPCUA/SimulationServer/"
# url = "opc.tcp://olivier:olivierpass@localhost:53530/OPCUA/SimulationServer/"
async with Client(url=url) as client:
print("Root children are", await client.nodes.root.get_children())
tag1 = client.get_node("ns=2;s=Channel1.Device1.Tag1")
print(f"tag1 is: {tag1} with value {await tag1.read_value()} ")
tag2 = client.get_node("ns=2;s=Channel1.Device1.Tag2")
print(f"tag2 is: {tag2} with value {await tag2.read_value()} ")
handler = SubHandler()
sub = await client.create_subscription(500, handler)
handle1 = await sub.subscribe_data_change(tag1)
handle2 = await sub.subscribe_data_change(tag2)
# await sub.unsubscribe(handle1)
# await sub.unsubscribe(handle2)
# await sub.delete()
if __name__ == "__main__":
logging.basicConfig(level=logging.WARN)
asyncio.run(main())