OPCDA.NET Reference Manual
VB.Net Sample Code
Send comments on this topic.
OPCDA.NET Client Component > Getting Started > VB.Net Sample Code

Glossary Item Box

Using the QuickUse Classes Using the OpcGroup Class

Imports OPC Imports OPCDA Imports OPCDA.NET Public Class Demo Function ServerAccess() As String Dim Srv As OpcServer = New OpcServer() Dim rtc As Int32 = Srv.Connect("Advosol.SimDAServer.1") If HRESULTS.Failed(rtc) Then Return Srv.GetErrorString(rtc, 0) End If Dim srwGroup As SyncIOGroup = New SyncIOGroup(Srv) Dim Rslt As OPCItemState Dim rtc As Int32 rtc = srwGroup.Read(OPCDATASOURCE.OPC_DS_CACHE, "SimulatedData.Step", Rslt) Dim retVal As String If HRESULTS.Failed(rtc) Then retVal = "Read error" Else retVal = "data=" + Rslt.DataValue.ToString() End If srwGroup.Dispose() Srv.Disconnect() Return retVal End Function End Class

Imports System.Runtime.InteropServices Imports Opc Imports OPCDA Imports OPCDA.NET Public Class DemoOpc Inherits System.Windows.Forms.Form Public Function ServerAccess() As String Dim Srv As OpcServer = New OpcServer() Dim rtc As Int32 = Srv.Connect("Advosol.SimDAServer.1") If HRESULTS.Failed(rtc) Then Return Srv.GetErrorString(rtc, 0) End If Dim oGrp As OpcGroup
Dim deadBand As Single = 0.0F Try oGrp = Srv.AddGroup("Grp1", True, 500, deadBand, 0, 0) Catch Return "Group could not be added" End Try Dim items As OPCItemDef() = {Nothing} items(0) = New OPCItemDef("SimulatedData.Step", True, 0, VarEnum.VT_BSTR) Dim addRslt As OPCItemResult() Dim rtc As Int16 rtc = oGrp.AddItems(items, addRslt) If HRESULTS.Failed(rtc) Then Srv.Disconnect() Return "Error at AddItem" End If Dim iHnd As Int32() = {0} iHnd(0) = addRslt(0).HandleServer Dim rslt As OPCItemState() rtc = oGrp.Read(OPCDATASOURCE.OPC_DS_CACHE, iHnd, rslt) Dim retVal As String If HRESULTS.Failed(rtc) Then retVal = "Read error" Else If HRESULTS.Failed(rslt(0).Error) Then retVal = "Item Read error" Else retVal = "data=" + rslt(0).DataValue.ToString() End If End If oGrp.Remove(True) Srv.Disconnect() Return retVal End Function End Class

 

See the Controls chapter for sample application code based on the DAServer/DAGroup Visual Studio controls.

A number of sample client applications including the Visual Studio project are in the OPCDA.NET installation sub-folder VB Sample Clients.

If you don't find this folder then probably the sample installation option was not selected when OPCDA.NET was installed.

 

The Visual Studio project wizard creates a Windows Form application with sample code according the selections in the wizard dialog. It may be quicker to create a new project with the required features than search for a matching sample application.

If you don't find the OPCDA.NET client template in the Visual Studio Add New Project template selection then probably the VB wizard installation option was not selected when OPCDA.NET was installed.

 

Copyright © 2002-2018 Advosol Inc. All Rights Reserved.