DeltaV OPC Data Access Server functional overview > Barcode tutorial

Implement exception reporting

When a group is added, the application can request to be notified when items in that group change value or quality. This request is made by simply setting an attribute in the an OPCGroup object and creating an event handler to process the data change. It is possible to handle these events on two levels, the OPCGroups or OPCGroup level. For this example, we will process data change notifications on the OPCGroups (OPCGroup collection) level.

  1. Make sure events are enabled by double-checking that our definition of MyGroups contains the "WithEvents" declaration. In the declaration section of the COPCServer class module, MyGroups declaration should be:
    Dim WithEvents MyGroups As OPCGroups
  2. Create a public function that turns on data change notification for a specific group.
     Public Function Subscribe(GroupName As String, Optional Status As Boolean = 
     True) As Integer
        Dim TargetStatus As Boolean
        Dim anOPCGroupHandle As Long
        
        Subscribe = False
        On Error GoTo ErrorHandler
        
        'Look up group
        anOPCGroupHandle = LookUpGroup(GroupName)
        If anOPCGroupHandle <= 0 Then
            MsgBox "Error - Group Not Found"
            Exit Function
        End If
        'Set the group's subscribe status appropriately.  Default to "True".
        MyGroups(GroupName).IsSubscribed = Status
        
        Subscribe = True
        Exit Function
        
    ErrorHandler:
        MsgBox "Subscribe: Error!" & vbCrLf _
               & "Err.Number = " & Err.Number & vbCrLf _
               & "Err.Description = " & Err.Description & vbCrLf _
               & "Err.Source = " & Err.Source & vbCrLf
    End Function
  3. Create a private subroutine in the COPCServer class module.
    Private Sub MyGroups_GlobalDataChange(ByVal TransactionID As Long, 
    ByVal GroupHandle As Long, ByVal NumItems As Long, ClientHandles() 
    As Long, ItemValues() As Variant, Qualities() As Long, 
    TimeStamps() As Date)
        
        Dim i As Integer
        
        'Step through items in DataChange array
        For i = 1 To NumItems
            If Qualities(i) > 0 Then
                If GroupHandle = gStepHandle Then
                    'Put current step in Status Bar
                    gStatusBar.Panels(1).Text = "Current Step: " & ItemValues(i)
                    gStep = ItemValues(i)
                    'Check to see if its time to print the label
                    If ItemValues(i) = DRYADD_STEP Then
                        gDryAddTime = DateAdd("h", -6, TimeStamps(i))
                    End If
                End If
            End If
        Next i
    End Sub

The GlobalDataChange procedure steps through the given array of items. If the Quality is good and the item is the Step of the SFC then the value is written to the status bar to let the user know the current step. In the case that the step is "DRY_ADD" the application needs to do more work. It is not allowed to call a DeltaV OPC Data Access Server function within the OnDataChange. It is also good practice to limit the length of time the OnDataChange executes. To accomplish these requirements, a timer object was added to the Main form. The timer function reads the target information and pops up a message asking the user to add the ingredient (refer to the Visual Basic Help - Timer object). You have already added the code to read the target values when the timer fires. Now add the code to check if its time to add the dry ingredient.