COPC DLL VB.Net Code Example

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

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s