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

If you are interested in OPC Data Client-UA, your task will most certainly involve reading data from an OPC UA 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 Unified Architecture Server

We will create a form that will read a float value from the OPC UA 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 UA 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-UA Library
    • OPC Labs EasyOPC-UA 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-UA component
    Dim Client As New EasyUAClient
       
    ' Read node value and display it
    Me.Text1 = Client.ReadValue("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", "nsu=http://test.org/UA/Data/;i=10853")
    
  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 UA 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-UA component directly. To do so, use the tool’s mechanism to create instance of a COM object, passing it a ProgID string “OpcLabs.EasyOpc.UA.EasyUAClient”.

See Also