client_to_kepware.py
Go to the documentation of this file.
00001 import sys
00002 sys.path.insert(0, "..")
00003 import logging
00004 
00005 from opcua import Client
00006 from opcua import uaprotocol as ua
00007 
00008 
00009 class SubHandler(object):
00010 
00011     """
00012     Client to subscription. It will receive events from server
00013     """
00014 
00015     def datachange_notification(self, node, val, data):
00016         print("Python: New data change event", node, val)
00017 
00018     def event_notification(self, event):
00019         print("Python: New event", event)
00020 
00021 
00022 if __name__ == "__main__":
00023     #from IPython import embed
00024     logging.basicConfig(level=logging.WARN)
00025     client = Client("opc.tcp://192.168.56.100:49320/OPCUA/SimulationServer/")
00026     #client = Client("opc.tcp://192.168.56.100:4840/OPCUA/SimulationServer/")
00027     #client = Client("opc.tcp://olivier:olivierpass@localhost:53530/OPCUA/SimulationServer/")
00028     try:
00029         client.connect()
00030         root = client.get_root_node()
00031         print("Root is", root)
00032         print("childs of root are: ", root.get_children())
00033         print("name of root is", root.get_browse_name())
00034         objects = client.get_objects_node()
00035         print("childs og objects are: ", objects.get_children())
00036 
00037 
00038         tag1 = client.get_node("ns=2;s=Channel1.Device1.Tag1")
00039         print("tag1 is: {0} with value {1} ".format(tag1, tag1.get_value()))
00040         tag2 = client.get_node("ns=2;s=Channel1.Device1.Tag2")
00041         print("tag2 is: {0} with value {1} ".format(tag2, tag2.get_value()))
00042 
00043         handler = SubHandler()
00044         sub = client.create_subscription(500, handler)
00045         handle = sub.subscribe_data_change(tag1)
00046         handle = sub.subscribe_data_change(tag2)
00047 
00048         from IPython import embed
00049         embed()
00050 
00051         
00052         sub.unsubscribe(handle)
00053         sub.delete()
00054     finally:
00055         client.disconnect()


ros_opcua_impl_python_opcua
Author(s): Denis Štogl , Daniel Draper
autogenerated on Sat Jun 8 2019 18:26:23