Author Topic: Any code examples using Datasubscriber with beginread with an ethernet comm?  (Read 4513 times)

usapatriotforlife

  • Newbie
  • *
  • Posts: 39
    • View Profile
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. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Here is an example of the proper way to use subscriptions using code:

Code: [Select]
    '* 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.

usapatriotforlife

  • Newbie
  • *
  • Posts: 39
    • View Profile
Thank you so much for the example.  That goes a long way towards helping me understand how to use subscriptions in code. 


BLFTech

  • Jr. Member
  • **
  • Posts: 56
    • View Profile
    • BLF-Tech LLC Website
Can you subscribe to multiple tags in one subscription?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
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.