DeltaV OPC Data Access Server functional overview > Barcode tutorial

Use the new class

The next step is to use the OPCServer class by declaring a variable of the class and calling its methods. In this application, you will define a global variable, OPCServer of the type OPCServer. You need two groups for this application. The first one holds items for the target ingredient and target amount that need to be added to this recipe. It also holds the actual ingredient and amount and a Done flag to send back to the DeltaV system. The second group contains the step of the MIXTANKS SFC (Sequential Function Chart). The step will pause at "DRY_ADD" waiting for the user to manually add the ingredient. This second group needs to request OnDataChange notifications. The OnDataChange procedure in the application can display the current step and react when the step is "DRY_ADD".

When an application needs to manipulate a group or item, it makes the request with a handle. This handle is returned from the server when the group or item is first created. In addition to adding global variables for each of the values needed, it is also necessary to have a variable to hold the server handles for those variables.

  1. In the code window for the Barcode module (Barcode.bas), set the Object to "General" and the Proc to "Declarations".
  2. Add the following declarations, after the Option Explicit:
    'Variables for OPC
    Global gOpcServer As New COPCServer
    'OPC Server Handles
    Global gTargetIngHandle As Long
    Global gTargetIngStrHandle As Long
    Global gTargetAmtHandle As Long
    Global gActualIngHandle As Long
    Global gActualAmtHandle As Long
    Global gDoneHandle As Long

    The Target Ingredient has two handles. The first is for the numeric value of the target ingredient. The second is for the text value of the target ingredient. In the DeltaV system, the ingredient has been defined by a Named Set (also referred to as an enumeration). This is a value from 0 to 255 that displays an assigned text message. This application needs to display both values to the user. To accomplish this, you will add two items with the only difference being the data type requested (string vs. integer).

  3. In the Sub Main, add the following code before the line frmMain.show:
    'Connect to OPC Server
    If Not gOpcServer.OpenServer Then
        MsgBox "Server didn't open"
        End
    End If
    'Add group for reading and writing to DeltaV System
    If gOpcServer.AddGroup("IngredientInfo", 1000) <= 0 Then
        MsgBox "Unable to add group IngredientInfo"
    End If

    The group IngredientInfo is added with an update rate of 1000 milliseconds or 1 second. This is the fastest update rate possible with OPC. Since this application requires very few data points, maintaining the best possible rate is not a performance issue. For large amounts of data, it would be important to separate items in groups that require different update rates and therefore reduce loading.

    In the Sub Main, add the following code before the line frmMain.Show:

        'Add items to IngredientsInfo group
    gTargetIngHandle = gOpcServer.AddItem("IngredientInfo", _
                        "OPCSAMPLE/TARGET_DRYINGR.CV", VT_I4)
    gTargetIngStrHandle = gOpcServer.AddItem("IngredientInfo", _
                        "OPCSAMPLE/TARGET_DRYINGR.CV", VT_BSTR)
    gTargetAmtHandle = gOpcServer.AddItem("IngredientInfo", _
                        "OPCSAMPLE/TARGET_DRYAMT.CV", VT_R4)
    gActualIngHandle = gOpcServer.AddItem("IngredientInfo", _
                        "OPCSAMPLE/ACTUAL_DRYINGR.CVI", VT_UI4)
    gActualAmtHandle = gOpcServer.AddItem("IngredientInfo", _
                        "OPCSAMPLE/ACTUAL_DRYAMT.CV", VT_R4)
    gDoneHandle = gOpcServer.AddItem("IngredientInfo", _
                        "OPCSAMPLE/DRY_ADDS_DONE.CV", VT_BSTR)

    In the call to AddItem, the ItemID is a string representing the path of the item in the DeltaV system, for example: "OPCSAMPLE/TARGET_DRYINGR.CV". In the sample DeltaV configuration there is a module named OPCSAMPLE. This module has a module level parameter named TARGET_DRYINGR. The ".CV" indicates the field of the parameter. The Current Value (CV) is the default field if none is specified. The defined fields depend on the parameter type.

    Note

    One easy way of determining the path of an existing parameter is to use the Excel add-in in the DeltaV system. The add-in includes a wizard that allows you to browse for the item to the field level. Select the Paste parameter path to left of result check box to see the full parameter path.