Home
COPC DLL VB.Net Code Example PDF Print E-mail
Written by Administrator   
Monday, 23 April 2018 17:34

This is example code of COPC DLL on VB.Net

Imports cpcUnlimited

Public Class Form1
    Public WithEvents copc1 As cpcUnlimited.copcClass
    Public v(0 To 1)

    Private Sub copc1_datChange(tagIndex As Integer) Handles copc1.datChange
        Dim i As Integer

        For i = 0 To 1
            v(i) = copc1.tgVal(i)
        Next

        'Display value

        Try
            Label1.Text = v(0).ToString()
            Label2.Text = v(1).ToString()
        Catch ex As Exception

        End Try

    End Sub

    Private Sub Form1_Leave(sender As Object, e As EventArgs) Handles Me.Leave
        Try
            copc1.disconnec()
        Catch ex As Exception

        End Try
    End Sub


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        copc1 = New copcClass
        copc1.svrName = "KEPware.KEPServerEx.V6"
        copc1.tagAmount = 2
        copc1.setItm(0, "Simulation Examples.Functions.Random1")
        copc1.setItm(1, "Simulation Examples.Functions.K1")
        copc1.UpdateRate = 1000

        Try
            copc1.connectng()
        Catch ex As Exception

        End Try
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
	'Write value to OPC tag
        copc1.opcWrt(1, Double.Parse(TextBox1.Text))
    End Sub

End Class