How to specify a deadband (VBA, OPC UA)

From OPC Labs Knowledge Base
Jump to navigation Jump to search

Below is a piece of code that shows how to specify an absolute deadband within MonitoringParameters (if you like, you can create different MonitoringParameters objects with different deadband for each item, too). Note that you can also specify UADeadbandType_Percent; we haven’t shown that in our example, because the sample server we are connecting to does not support it, at least not on the nodes used in the example.

Private Sub SubscribeCommandButton_Click()
    ' Create the EasyOPC-UA component
    Set Client = New EasyUAClient
    Dim MonitoringParameters As New UAMonitoringParameters
    MonitoringParameters.SamplingInterval = 1000
    ' Filter numerical data changes using an absolute deadband of 5.0
    Dim DataChangeFilter As New UADataChangeFilter
    DataChangeFilter.DeadbandType = UADeadbandType_Absolute
    DataChangeFilter.DeadbandValue = 5#
    Set MonitoringParameters.DataChangeFilter = DataChangeFilter
    ' Define OPC node IDs
    ' For "states", we use names of cells where the values should be updated
    Dim MonitoredItemArguments1: Set MonitoredItemArguments1 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments")
    MonitoredItemArguments1.EndpointDescriptor.UrlString = ""
    MonitoredItemArguments1.NodeDescriptor.NodeId.ExpandedText = "nsu=;i=10845"
    Set MonitoredItemArguments1.MonitoringParameters = MonitoringParameters
    MonitoredItemArguments1.State = "D2"
    Dim MonitoredItemArguments2: Set MonitoredItemArguments2 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments")
    MonitoredItemArguments2.EndpointDescriptor.UrlString = ""
    MonitoredItemArguments2.NodeDescriptor.NodeId.ExpandedText = "nsu=;i=10853"
    Set MonitoredItemArguments2.MonitoringParameters = MonitoringParameters
    MonitoredItemArguments2.State = "D3"
    Dim MonitoredItemArguments3: Set MonitoredItemArguments3 = CreateObject("OpcLabs.EasyOpc.UA.OperationModel.EasyUAMonitoredItemArguments")
    MonitoredItemArguments3.EndpointDescriptor.UrlString = ""
    MonitoredItemArguments3.NodeDescriptor.NodeId.ExpandedText = "nsu=;i=10855"
    Set MonitoredItemArguments3.MonitoringParameters = MonitoringParameters
    MonitoredItemArguments3.State = "D4"
    Dim arguments(2)
    Set arguments(0) = MonitoredItemArguments1
    Set arguments(1) = MonitoredItemArguments2
    Set arguments(2) = MonitoredItemArguments3
    ' Subscribe to OPC monitored items
    Call Client.SubscribeMultipleMonitoredItems(arguments)
End Sub