Author Topic: Array of DataSubscriber2 at runtime  (Read 2127 times)

GraemeTownsend

  • Newbie
  • *
  • Posts: 29
    • View Profile
Array of DataSubscriber2 at runtime
« on: August 08, 2018, 08:51:17 PM »
Hi All,

I have a situation where I want to create multiple DataSubscriber2 at runtime, but the quantity may vary depending on ini file settings.

I can create them no problem, (at least I think I can!), but I am having trouble linking them to an event handler function. Happy for the one routine to handle all as once I get the event details I can branch/react as required.

Any advice? Or am I fooling myself?

Cheers,
Graeme.

(Reason: I have a common app across multiple projects. Each project connects to different quantities of PLC's. I want to keep the application generic)

Phrog30

  • Guest
Re: Array of DataSubscriber2 at runtime
« Reply #1 on: August 08, 2018, 09:29:20 PM »
Question, do you need multiple datasubscriber2, or multiple PLC addresses in a datasubscriber?

GraemeTownsend

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Array of DataSubscriber2 at runtime
« Reply #2 on: August 08, 2018, 09:56:29 PM »
It is multiple datasubscriber2 because it is over multpiple PLC's.

Will be one per PLC.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Array of DataSubscriber2 at runtime
« Reply #3 on: August 08, 2018, 10:27:51 PM »
The DataSubscriber was created to encapsulate the complexity of subscribing through a driver and meant for design time use. If you are doing this during run time, it is just as easy and more efficient to directly subscribe to addresses through the driver.


GraemeTownsend

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Array of DataSubscriber2 at runtime
« Reply #4 on: August 08, 2018, 10:35:03 PM »
The drivers are created at run time too. So I will have the same problem with regard to linking to an event handler.

GraemeTownsend

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Array of DataSubscriber2 at runtime
« Reply #5 on: August 08, 2018, 11:55:59 PM »
Hi again,

So, bit of progress.

Runtime I create my EthernetIPforCLXCom Driver.  (Drv_Test)
Runtime I create my DataSubscriber2.  (DS_Test)

DS_Test.ComComponent = Drv_Test

I can also create the event handler

AddHandler DS_Test.DataChanged, AddressOf DS_Test_DataChanged

Code: [Select]
Private Sub DS_Test_DataChanged(sender As Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs)


        ProcessIncomingData(e)
End Sub


When the data changes the event handler fires.
In parameter 'e' I can see the PLC memory location and the changed data.
What I cannot determine is which Driver triggered it. (i.e. Drv_Test)

I can see the IP address of the triggering driver, which is indeed unique in this instance, but *MAY* not always be.

Any idea's here?
Alternative would be to pre-build many DS_Test_DataChanged() handlers with different names up to the maximum allowed different PLC's as per project scope, but I would far rather just have one and ID the triggering driver.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Array of DataSubscriber2 at runtime
« Reply #6 on: August 09, 2018, 07:26:16 AM »
Something like this:
Code: [Select]
Dim d as EthernetIPforCLXCom
d = DirectCast(sender, EthernetIPforCLXCom)
MsgBox("Driver name=" & d.Name )


Even if you are creating driver instances in code, it is still the same to subscribe directly to the driver and not use a DataSubscriber. Instead of adding an event handler for the DataSubscriber, you would add an event handler for the driver's DataReceived event.

GraemeTownsend

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Array of DataSubscriber2 at runtime
« Reply #7 on: August 09, 2018, 09:39:05 PM »
Thanks Archie,

Went a slightly different route. I create one driver and two DataSubscribers per PLC. Identifying who is talking is critical.

Subscribing directly through the driver and identifying the data subscribed vs identifying the driver with two DS's is similar. So I went the latter.

Not super elegant, but works. Capped at 25 PLC's configurable via the ini file.
I have 25 (x2) simple event handler sub routines pre-configured that I link new DS's to as required, they in turn call a common function to process the data passing on their ID and incoming data. Works fine.

Thanks again.