DeltaV OPC Data Access Server functional overview > Barcode tutorial

Add a group

For this application we only need two groups. One for monitoring data and the other for data that is set in our application and sent to the DeltaV system. The way the data is divided into groups is up to the discretion of the programmer. There are a few settings that are changed at the group level. They are:

Name - Name of the group. The name must be a unique group name, with respect to the naming of other groups created by this client.

UpdateRate - The rate, in milliseconds, at which group data is updated with the values in the DeltaV system.

Deadband - The amount that the data must change before it is reported as changed. The amount is given as a percentage of the engineering units of the individual data values. In other words, if the PercentDeadband is 5% then a data value that ranges from 0 to 200 GPM must change at least 10 GPM before it is reported.

TimeBias - A Time Zone offset in minutes.

LocaleID - Identifies a locale for national language support. The LCID for US-English is 409 hexadecimal.

ClientHandle - This value is any unsigned 32-bit integer. The DeltaV OPC Data Access Server will provide this handle when returning data in an asynchronous connection. This allows the client application to identify the group to which the data belongs.

IsActive - Controls the active state of the group. A group that is active acquires data. An inactive group typically does not continue data acquisition except as required for read/writes.

IsSubscribed - Controls asynchronous notifications to the group. A group that is subscribed receives data changes from the server.

The client application can change the active state of a group at any time. If the active state of the group is false, the DeltaV OPC Data Access Server will not keep the values of its items up to date. The client application will not be notified of changes. Read requests to cache will return successfully however, the data values will be stale and the quality statuses will be "bad" (for a detailed description of statuses, refer to Appendix B). Read requests to "device" are sent directly to the DeltaV controller and always return the current values if no errors are encountered.

  1. In the declarations section of the OPCServer class, add the following code:
    Dim WithEvents MyGroups As OPCGroups

    OPCGroups is a collection of OPCGroup objects, and the methods that create, remove, and manage them.

    This object also has properties for OPCGroup defaults. When OPCGroups are added, the DefaultGroupXXXX properties set its initial state. The defaults can be changed to add OPCGroups with different initial states. Changing the defaults does not affect groups that have already been created. Once an OPCGroup is added, its properties can be modified. This reduces the number of parameters required to call the Add method.

    The OPC Groups provide a way for clients to organize data. For example, the group might represent items in a particular operator display or report. Data can be read and written. Exception based connections can also be created between the client and the items in the group and can be enabled and disabled as needed. An OPC client can configure the rate that a DeltaV OPC Data Access Server should provide the data changes to the OPC client.

  2. Add a function to the OPCServer class called AddGroup. It should be a public function and should return an integer.
  3. Add the following parameters to the function AddGroup:
    Public Function AddGroup(GroupName As String, RequestedUpdateRate As Long) 
    As Long
  4. In the function AddGroup, add the following code:
    Dim OneGroup As OPCGroup
    AddGroup = False
        On Error GoTo ErrorHandler
    'Test to be sure the server object is valid
        If TypeName(AnOpcServer) = TypeName(Nothing) Then
            MsgBox "Error - No Server Connection"
            Exit Function 'no server
    End If
    'Add group to our Collection
        Set OneGroup = MyGroups.Add(GroupName)
        'In theory, we don't need this part....  There's a default.
    OneGroup.UpdateRate = RequestedUpdateRate
    OneGroup.IsActive = True
    AddGroup = OneGroup.ServerHandle
    Exit Function
    ErrorHandler:
        MsgBox "AddGroup: Error!" & vbCrLf _
            & "Err.Number = " & Err.Number & vbCrLf _
            & "Err.Description = " & Err.Description & vbCrLf _
            & "Err.Source = " & Err.Source & vbCrLf
    End Function

    The OPCServer will return the actual update rate for the group and the server handle. One reason the actual update rate may differ is if the requested rate is less than one second. The Server Handle will be used in calls from the client to the OPCServer that request changes to the group.

  5. Add a function to the OPCServer class called RemoveGroup. It should be a public function and should return an integer.
  6. Add the following parameters to the function RemoveGroup:
    Public Function RemoveGroup(GroupName As String) As Integer
  7. In the function RemoveGroup, add the following code:
    Dim OneGroup As OPCGroup
    RemoveGroup = False
        On Error GoTo ErrorHandler
        MyGroups.Remove (GroupName)
        RemoveGroup = True
        Exit Function
    ErrorHandler:
        MsgBox "RemoveGroup: Error!" & vbCrLf _
            & "Err.Number = " & Err.Number & vbCrLf _
            & "Err.Description = " & Err.Description & vbCrLf _
            & "Err.Source = " & Err.Source & vbCrLf
    End Function
  8. Add a support function for looking up the group handle from the name. The function should be called "LookUpGroup". It is a public function with the following declaration:
    Private Function LookUpGroup(GroupName As String) As Integer
  9. In the LookUpGroup function, add the following code:
    Dim Done As Integer
    Dim Count As Integer
    
    LookUpGroup = -1
    
    Done = False
    Count = 0
    While Not Done
        If Count > GroupCount Then
            Done = True
        ElseIf GroupName = Groups(Count).Name Then
            LookUpGroup = Count
            Done = True
        Else
            Count = Count + 1
        End If
    Wend
    
    Exit Function
    errHandler:
        MsgBox Err.Description
        Exit Function
    End Function
  10. Save the project and run with full compile to highlight errors.