In this article, I will show how to use OPC Data event to control something. For example, doing some operation if value of specified OPC Tag changed.
In COPCDLL, it is “datChange” event can be used to detect if specified OPC tags data changed or not.
The VS C# example below shows if data of OPC tag which has index number 1 is changed, the code will write data value 111 to OPC tag has index number 2.
Private Sub copc1_datChange(tagIndex As Integer) Handles copc1.datChange Try Select Case tagIndex Case 0 Case 1 copc1.opcWrt(2, 111) Case 2 End Select Catch ex As Exception End Try End Sub
In COPC32, it is event ‘datChngX’ can do the same operation.
The VB.net example below shows id (index numner) of OPC tag that it’s data is changed.
Private Sub Axcopc1_datChngX(sender As Object, e As AxCOPC32.__copc_datChngXEvent) Handles Axcopc1.datChngX Label1.Text = e.id End Sub
Advertisements