Author Topic: DataSubscriber vs DataSubscriber2  (Read 1269 times)

bmbrown97

  • Newbie
  • *
  • Posts: 7
    • View Profile
DataSubscriber vs DataSubscriber2
« on: November 11, 2018, 04:25:27 PM »
All --

I'm trying to make the right decision on subscribing to a bunch of random data from a single PLC. I wish to get some Floats, Ints, Bits, and other various data from various tags then process them in my application.

That said, since none of the data is sequential, what is the recommendation for gathering up this host of random data?

A) Create a series of _PLCController.Subscribe(...) items and then process each "bit" of data as it comes in?
B) Create a single DataSubscriber2 and then parse the incoming data to determine which function / sub to call based on the incoming address?

I'm using WPF and am doing all the data processing without going through the AHMI controls.

My gut tells me the DataSubscriber2 method is probably preferred, however, if that is the case, I am not 100% certain on how to set it up. When using WinForms, you give it the ComComponent in the properties windows, however, when I try to do this via code in the WPF, I get an error about needing to have System.Windows.Forms referenced, even though it already is.

Any words of wisdom would be greatly appreciated.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: DataSubscriber vs DataSubscriber2
« Reply #1 on: November 11, 2018, 04:51:03 PM »
When subscribing in code, it is better to directly subscribe to the driver. The main purpose of the DataSubscriber is to encapsulate the complexity of subscribing in a non-code component, so if you are not using the WinForm designer, it is not efficient to use the DataSubscriber.

bmbrown97

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: DataSubscriber vs DataSubscriber2
« Reply #2 on: November 11, 2018, 07:17:33 PM »
So then something as simple as:

        _PLCController = New AdvancedHMIDrivers.EthernetIPforCLXCom
        _PLCController.IPAddress = _Settings.PLCIPAddress
        MyTag1SubScribeID = _PLCController.Subscribe("MyTag1", 1, 0, AddressOf ProcessMyTag)
       MyTag2SubScribeID = _PLCController.Subscribe("MyTag2", 1, 0, AddressOf ProcessMyTag)

Even if there is going to be 50+ Subscriptions? If I point them all to "ProcessMyTag" can I then use the e.PLCAddress to get the source of the changed data (MyTag1 or MyTag2)?

And then just so I'm clear, setting a poll rate of 0 will cause it to fire anytime the data is changed, correct?

Godra

  • Hero Member
  • *****
  • Posts: 1447
    • View Profile
Re: DataSubscriber vs DataSubscriber2
« Reply #3 on: November 11, 2018, 11:11:42 PM »
I have not tried this but it seems as if you could just use e.SubscriptionID to identify the source, similar to this:

Code: [Select]
    Private Sub EthernetIPforCLXCom1_SubscriptionDataReceived(sender As Object, e As Drivers.Common.SubscriptionEventArgs) Handles EthernetIPforCLXCom1.SubscriptionDataReceived
        If e.SubscriptionID = MyTag1SubScribeID Then
            'The source is MyTag1
        ElseIf e.SubscriptionID = MyTag2SubScribeID Then
            'The source is MyTag2
        End If
    End Sub

Or just make sure that your ProcessMyTag handles the EthernetIPforCLXCom1.SubscriptionDataReceived event with correct "sender" and "e" types as above.
« Last Edit: November 11, 2018, 11:13:43 PM by Godra »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: DataSubscriber vs DataSubscriber2
« Reply #4 on: November 12, 2018, 07:53:29 AM »
And then just so I'm clear, setting a poll rate of 0 will cause it to fire anytime the data is changed, correct?
This is not correct. By setting PollRateOverride to 0 the driver will poll the PLC as fast as the processor and network will allow. Depending on the PLC and network this could range from 2ms to 100ms per packet. If you do this, keep in mind it may put a heavy load on your network and PLC resources.