AdvancedHMI Software
General Category => Support Questions => Topic started by: usapatriotforlife on August 25, 2013, 02:05:06 AM
-
I would definitely appreciate it if someone would post a short code section showing how to asynchronously read three or four registers on a PLC using a datasubscriber object connected to a one of the ethernet comm drivers. I'm completely confused on how to add the registers, say for a SLCMicro of N17:0, N17:1, B16:0/0 and then how to add the event handlers when data comes back. Thanks in advance.
-
Here is an example of the proper way to use subscriptions using code:
'* Save the ID of the subscription for later unsubscribing
Private SubscriptionID As Integer
'* Subscribe to the Tag
Private Sub MainForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
SubscriptionID = EthernetIPforCLXCom1.Subscribe("MyTag", 1, 250, AddressOf SubscribedDataReturned)
End Sub
'* Show the value when it is returned
Private Sub SubscribedDataReturned(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)
Me.Text = e.Values(0)
End Sub
'* When the form is closed be sure to unsubscribe so the driver doesn't keep trying to read the data
Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
EthernetIPforCLXCom1.UnSubscribe(SubscriptionID)
End Sub
The DataSubscriber is designed to encapsulate this complexity. You simply add a DataSubscriber to the form, put the tag name in PLCAddressValue, then double click he DataSubscriber to get back to the event handler for data that was returned.
-
Thank you so much for the example. That goes a long way towards helping me understand how to use subscriptions in code.
-
Can you subscribe to multiple tags in one subscription?
-
You can only subscribe to one tag per call and the current version of the driver doesn't yet support subscribing to multiple elements of an array.