Talk:Subscribing to PLC data via code
Hello. Below is a slightly modified version of the code provided on the "Subscribing to PLC data via code" page. I am attempting use this concept with multiple tags of various data types. I have found that I pretty much have to make multiple calls in order to achieve this but I'm by no means an expert at coding. Is there a better way to achieve this???
Imports MfgControl.AdvancedHMI
Public Class Form1
Private SubscriptionID1 As Integer Private SubscriptionID2 As Boolean
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load SubscriptionID1 = OpcDaCom1.Subscribe("One.TestWord", 1, 500, AddressOf Subscription_DataReceived) SubscriptionID2 = OpcDaCom1.Subscribe("One.ONBOARD_INPUT_BIT0", 1, 500, AddressOf Subscription_DataReceived2) End Sub
Private Sub Subscription_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) If e.ErrorId = 0 AndAlso e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then Label1.Text = e.Values(0) EthernetIPforCLXCom1.Write("Word", e.Values(0)) End If End Sub Private Sub Subscription_DataReceived2(sender As Object, e As Drivers.Common.PlcComEventArgs) If e.ErrorId = 0 AndAlso e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then Label2.Text = e.Values(0) If e.Values(0) = "True" Then EthernetIPforCLXCom1.Write("ZZ", 1) Else EthernetIPforCLXCom1.Write("ZZ", 0) End If End Sub
Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing OpcDaCom1.UnSubscribe(SubscriptionID1) OpcDaCom1.UnSubscribe(SubscriptionID2) End Sub
End Class