本文整理汇总了Python中opcua.Server.create_custom_event_type方法的典型用法代码示例。如果您正苦于以下问题:Python Server.create_custom_event_type方法的具体用法?Python Server.create_custom_event_type怎么用?Python Server.create_custom_event_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类opcua.Server
的用法示例。
在下文中一共展示了Server.create_custom_event_type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parent
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import create_custom_event_type [as 别名]
# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
# get Objects node, this is where we should put our custom stuff
objects = server.get_objects_node()
# populating our address space
myobj = objects.add_object(idx, "MyObject")
myvar = myobj.add_variable(idx, "MyVariable", ua.Variant(0, ua.VariantType.Double))
myvar.set_writable() # Set MyVariable to be writable by clients
# Creating a custom event: Approach 1
# The custom event object automatically will have members from its parent (BaseEventType)
etype = server.create_custom_event_type(2, 'MyFirstEvent', ua.ObjectIds.BaseEventType,
[('MyNumericProperty', ua.VariantType.Float),
('MyStringProperty', ua.VariantType.String)])
# create second event
etype2 = server.create_custom_event_type(2, 'MySecondEvent', ua.ObjectIds.BaseEventType,
[('MyOtherProperty', ua.VariantType.Float)])
myevgen = server.get_event_generator(etype, myobj)
myevgen.event.Severity = 500
myevgen.event.MyStringProperty = ua.Variant("hello world")
myevgen2 = server.get_event_generator(etype2, myobj)
myevgen2.event.Severity = 123
myevgen2.event.MyOtherProperty = ua.Variant(1.337)
serverevgen = server.get_event_generator()
serverevgen.event.Severity = 111
示例2: parent
# 需要导入模块: from opcua import Server [as 别名]
# 或者: from opcua.Server import create_custom_event_type [as 别名]
# setup our own namespace, not really necessary but should as spec
uri = "http://examples.freeopcua.github.io"
idx = server.register_namespace(uri)
# get Objects node, this is where we should put our custom stuff
objects = server.get_objects_node()
# populating our address space
myobj = objects.add_object(idx, "MyObject")
# Creating a custom event: Approach 1
# The custom event object automatically will have members from its parent (BaseEventType)
etype = server.create_custom_event_type(
2,
"MyFirstEvent",
ua.ObjectIds.BaseEventType,
[("MyNumericProperty", ua.VariantType.Float), ("MyStringProperty", ua.VariantType.String)],
)
myevgen = server.get_event_generator(etype, myobj)
myevgen.event.Severity = 500
# Creating a custom event: Approach 2
base_etype = server.get_node(ua.ObjectIds.BaseEventType)
custom_etype = base_etype.add_subtype(2, "MySecondEvent")
custom_etype.add_property(2, "MyIntProperty", ua.Variant(None, ua.VariantType.Int32))
custom_etype.add_property(2, "MyBoolProperty", ua.Variant(None, ua.VariantType.Boolean))
mysecondevgen = server.get_event_generator(custom_etype, myobj)
# starting!