Go to the documentation of this file.00001 import sys
00002 import logging
00003
00004 try:
00005 from IPython import embed
00006 except ImportError:
00007 import code
00008
00009 def embed():
00010 vars = globals()
00011 vars.update(locals())
00012 shell = code.InteractiveConsole(vars)
00013 shell.interact()
00014
00015 from opcua import ua, Server
00016
00017
00018 if __name__ == "__main__":
00019 logging.basicConfig(level=logging.WARN)
00020 logger = logging.getLogger("opcua.server.internal_subscription")
00021 logger.setLevel(logging.DEBUG)
00022
00023
00024 server = Server()
00025 server.set_endpoint("opc.tcp://0.0.0.0:4840/freeopcua/server/")
00026
00027
00028 uri = "http://examples.freeopcua.github.io"
00029 idx = server.register_namespace(uri)
00030
00031
00032 objects = server.get_objects_node()
00033
00034
00035 myobj = objects.add_object(idx, "MyObject")
00036
00037
00038
00039 etype = server.create_custom_event_type(2, 'MyFirstEvent', ua.ObjectIds.BaseEventType, [('MyNumericProperty', ua.VariantType.Float), ('MyStringProperty', ua.VariantType.String)])
00040
00041 myevgen = server.get_event_generator(etype, myobj)
00042
00043
00044 custom_etype = server.nodes.base_event_type.add_object_type(2, 'MySecondEvent')
00045 custom_etype.add_property(2, 'MyIntProperty', ua.Variant(None, ua.VariantType.Int32))
00046 custom_etype.add_property(2, 'MyBoolProperty', ua.Variant(None, ua.VariantType.Boolean))
00047
00048 mysecondevgen = server.get_event_generator(custom_etype, myobj)
00049
00050
00051 server.start()
00052
00053 try:
00054
00055 import time
00056 count = 0
00057 while True:
00058 time.sleep(5)
00059 myevgen.event.Message = "MyFirstEvent " + str(count)
00060 myevgen.event.Severity = count
00061 myevgen.event.MyNumericProperty = count
00062 myevgen.event.MyStringProperty = "Property " + str(count)
00063 myevgen.trigger()
00064 mysecondevgen.trigger(message="MySecondEvent " + str(count))
00065 count += 1
00066
00067 embed()
00068 finally:
00069
00070 server.stop()