Difference between revisions of "Subscribing to PLC data via code"

From AdvancedHMI
Jump to: navigation, search
m
m
Line 9: Line 9:
  
 
     Private Sub Subscription_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs)
 
     Private Sub Subscription_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs)
         Label1.Text = e.Values(0)
+
         If e.ErrorId=0 AndAlso e.Values IsNot Nothing AndAlso e.Values.Count>0 Then
 +
            Label1.Text = e.Values(0)
 +
        End If
 
     End Sub
 
     End Sub
  

Revision as of 08:15, 25 May 2017

The AdvancedHMI drivers support a subscription that will automatically poll data and return the values. The DataSubscriber provides a non-code method of using this service. However, there are times when it is desired or more efficient to subscribe using code. This is an example on how to do this:


   Private SubscriptionID1 As Integer
   Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
       SubscriptionID1 = EthernetIPforCLXCom1.Subscribe("MyTag", 1, 500, AddressOf Subscription_DataReceived)
   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)
       End If
   End Sub
   Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
       EthernetIPforCLXCom1.UnSubscribe(SubscriptionID1)
   End Sub


The rate at which data is polled is determined by the value of the PollRateOverride property.

Each driver is highly optimized for communications using subscriptions. All of the visual controls (e.g. Gauge) use the subscription mechanism to receive their data.