OPC Studio User's Guide and Reference
Making a first COM application in VB6
Client and Subscriber Development > Getting Started > Getting Started under COM > Getting Started with OPC Classic under COM > Making a first COM application in VB6
In This Topic

If you are interested in OPC Data Client-COM, your task will most certainly involve reading data from an OPC server. Here are a few steps that illustrate how to achieve that, using Visual Basic 6.0. The steps are similar if you are using other tools or a different programming language.

A Form to Read Value from OPC Data Access Server

We will create a form that will read a float value from the OPC server when loaded, and immediately display the formatted value in the text box on the form.

  1. Install OPC Data Client. Make sure that you have selected an installation choice that includes COM development.

  2. Start Visual Basic 6.0, and create new project, selecting “Standard EXE” project  type.

  3. Reference the components for OPC "Classic" client development: Select Project -> References from the menu, and in the list of available references, look for following items and check the boxes next to them:

    • OPC Labs Base Library
    • OPC Labs Base Library Components
    • OPC Labs EasyOPC “Classic” Core Library
    • OPC Labs EasyOPC “Classic” Library
    • OPC Labs EasyOPC “Classic” Components Library

    Then, press OK.

    Note: If some of the OPC Data Client the type libraries are not shown in the References list, use the Browse… button to locate and select them manually. The type libraries are installed under the SDK\lib subdirectory under the OPC Data Client installation folder. Sometimes, simply restarting the Visual Basic 6.0 helps.

  4. Place a Text Box onto the form’s surface. Keep the name Text1.

  5. Add handler for the Load event of the form: Switch to Code View, and select the Form object and then its Load member. Visual Basic will add the handler’s skeleton as follows:

  6. Write the event handler implementation. Add the following code to the body of Form_Load method:

           
    Copy Code
    ' Create EasyOPC-DA component
    Dim EasyDAClient As New EasyDAClient
       
    ' Read item value and display it
    Me.Text1 = EasyDAClient.ReadItemValue("", "OPCLabs.KitServer.2", "Demo.Single")
    
  7. Build and run the application by selecting Run -> Start from the menu, and observe the results. The text box on the form will be filled with a float value we have read from the OPC server.

Notes

If you are using a tool that does not have a referencing mechanism similar to Visual basic, you may need to create the EasyOPC-DA component directly. To do so, use the tool’s mechanism to create instance of a COM object, passing it a ProgID string “OpcLabs.EasyOpc.DataAccess.EasyDAClient”.

See Also