Пример #1
0
async def select_clauses_from_evtype(evtypes):
    clauses = []
    selected_paths = []
    for evtype in evtypes:
        for prop in await get_event_properties_from_type_node(evtype):
            browse_name = await prop.read_browse_name()
            if browse_name not in selected_paths:
                op = ua.SimpleAttributeOperand()
                op.AttributeId = ua.AttributeIds.Value
                op.BrowsePath = [browse_name]
                clauses.append(op)
                selected_paths.append(browse_name)
    return clauses
Пример #2
0
async def append_new_attribute_to_select_clauses(attribute, select_clauses,
                                                 already_selected,
                                                 parent_variable):
    browse_path = []
    if parent_variable:
        browse_path.append(await parent_variable.read_browse_name())
    browse_path.append(await attribute.read_browse_name())
    string_path = '/'.join(map(str, browse_path))
    if string_path not in already_selected:
        already_selected[string_path] = string_path
        op = ua.SimpleAttributeOperand()
        op.AttributeId = ua.AttributeIds.Value
        op.BrowsePath = browse_path
        select_clauses.append(op)
Пример #3
0
async def select_clauses_from_evtype(evtypes):
    clauses = []
    selected_paths = []
    for evtype in evtypes:
        event_props_and_vars = await get_event_properties_from_type_node(evtype)
        event_props_and_vars.extend(await get_event_variables_from_type_node(evtype))
        for node in event_props_and_vars:
            browse_name = await node.read_browse_name()
            if browse_name not in selected_paths:
                op = ua.SimpleAttributeOperand()
                op.AttributeId = ua.AttributeIds.Value
                op.BrowsePath = [browse_name]
                clauses.append(op)
                selected_paths.append(browse_name)
    return clauses
Пример #4
0
def test_where_clause():
    cf = ua.ContentFilter()
    el = ua.ContentFilterElement()
    op = ua.SimpleAttributeOperand()
    op.BrowsePath.append(ua.QualifiedName("property", 2))
    el.FilterOperands.append(op)
    for i in range(10):
        op = ua.LiteralOperand()
        op.Value = ua.Variant(i)
        el.FilterOperands.append(op)
    el.FilterOperator = ua.FilterOperator.InList
    cf.Elements.append(el)
    wce = WhereClauseEvaluator(logging.getLogger(__name__), None, cf)
    ev = BaseEvent()
    ev._freeze = False
    ev.property = 3
    assert wce.eval(ev)
Пример #5
0
    async def subscribe_alarms_and_conditions(
            self,
            sourcenode: Node = ua.ObjectIds.Server,
            evtypes=ua.ObjectIds.ConditionType,
            evfilter=None,
            queuesize=0) -> int:
        """
        Subscribe to alarm and condition events from a node. Default node is Server node.
        In many servers the server node is the only one you can subscribe to.
        If evtypes is not provided, evtype defaults to ConditionType.
        If evtypes is a list or tuple of custom event types, the events will be filtered to the supplied types.
        A handle (integer value) is returned which can be used to modify/cancel the subscription.

        :param sourcenode:
        :param evtypes:
        :param evfilter:
        :param queuesize: 0 for default queue size, 1 for minimum queue size, n for FIFO queue,
        MaxUInt32 for max queue size
        :return: Handle for changing/cancelling of the subscription
        """
        sourcenode = Node(self.server, sourcenode)
        if evfilter is None:
            evfilter = await self._create_eventfilter(evtypes)
        # Add SimpleAttribute for NodeId if missing.
        matches = [
            a for a in evfilter.SelectClauses
            if a.AttributeId == ua.AttributeIds.NodeId
        ]
        if not matches:
            conditionIdOperand = ua.SimpleAttributeOperand()
            conditionIdOperand.TypeDefinitionId = ua.NodeId(
                ua.ObjectIds.ConditionType)
            conditionIdOperand.AttributeId = ua.AttributeIds.NodeId
            evfilter.SelectClauses.append(conditionIdOperand)
        return await self._subscribe(sourcenode,
                                     ua.AttributeIds.EventNotifier,
                                     evfilter,
                                     queuesize=queuesize)
async def main():
    # OPCFoundation/UA-.NETStandard-Samples Quickstart AlarmConditionServer
    url = "opc.tcp://localhost:62544/Quickstarts/AlarmConditionServer"
    async with Client(url=url) as client:
        alarmConditionType = await client.nodes.root.get_child([
            "0:Types", "0:EventTypes", "0:BaseEventType", "0:ConditionType",
            "0:AcknowledgeableConditionType", "0:AlarmConditionType"
        ])

        conditionType = await client.nodes.root.get_child(
            ["0:Types", "0:EventTypes", "0:BaseEventType", "0:ConditionType"])

        # Create Operand for necessary field ConditionId
        # Hint: The ConditionId is not a property of the event, but it's NodeId.
        #       ConditionId is named "NodeId" in event field list.
        conditionIdOperand = ua.SimpleAttributeOperand()
        conditionIdOperand.TypeDefinitionId = ua.NodeId(
            ua.ObjectIds.ConditionType)
        conditionIdOperand.AttributeId = ua.AttributeIds.NodeId

        # Add ConditionId to select filter
        evfilter = await get_filter_from_event_type([alarmConditionType])
        evfilter.SelectClauses.append(conditionIdOperand)

        # Create subscription for AlarmConditionType
        msclt = SubHandler()
        sub = await client.create_subscription(0, msclt)
        handle = await sub.subscribe_events(client.nodes.server,
                                            alarmConditionType, evfilter)

        # Call ConditionRefresh to get the current conditions with retain = true
        # Should also be called after reconnects
        await conditionType.call_method(
            "0:ConditionRefresh",
            ua.Variant(sub.subscription_id, ua.VariantType.UInt32))

        await asyncio.sleep(30)
        await sub.unsubscribe(handle)