Author Topic: Grabbing the Member "Name" from a DataSubscriber2  (Read 5053 times)

Arvanoss

  • Newbie
  • *
  • Posts: 30
    • View Profile
Grabbing the Member "Name" from a DataSubscriber2
« on: August 02, 2024, 09:54:50 AM »
Hello All,

I have a Program that I am working on that has 9 Datasubscriber2s running.
When one of the tags is triggered the Datasubscriber2 fires and I collect the data...all works fine.

What I am trying to do is consolidate my code so that I am not running 9 Identical DataChanged routines with different tags.
What I would like to do is Grab the Name of the Member that fired and use a If..Then..Else or a Select Case to process the data.

In debug mode in Visual Studio I can see the name that I need to grab but the code for it eludes me.

I have tried

        Data = sender.PlcAddressValueItems.Items(0).Name
        Data = Sender.Datachangedevent.method.name

Is there a way to Grab the Member Name?

Thanks

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Grabbing the Member "Name" from a DataSubscriber2
« Reply #1 on: August 02, 2024, 08:20:52 PM »
I just tried it out, and this worked over here:

Sender.PLCAddressValueItems.Item(0).Name

Edit: note Item, not Items.
« Last Edit: August 02, 2024, 08:25:24 PM by bobbh95 »

Arvanoss

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Grabbing the Member "Name" from a DataSubscriber2
« Reply #2 on: August 06, 2024, 06:56:00 AM »
Thank you bobbh95,

I was able to get the name finally.

So now it's on to the processing.
....

Here is the code I use...

    Private Sub Sta1Error_DataChanged(sender As Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs) Handles _
        Sta1Error.DataChanged, Sta2Error.DataChanged, Sta3Error.DataChanged, Sta4Error.DataChanged, Sta5Error.DataChanged _
        , Sta6Error.DataChanged, Sta7Error.DataChanged, Sta8Error.DataChanged

        Count = 0
        Data = sender.PLCAddressValueItems.Item(0).Name
        StaData = Mid(Data, 1, 4)

        Select Case StaData
            Case = "Sta1"
                i = 103
                q = 105
            Case = "Sta2"
                i = 121
                q = 123
            Case = "Sta3"
                i = 139
                q = 141
            Case = "Sta4"
                i = 157
                q = 160
            Case = "Sta5"
                i = 175
                q = 178
            Case = "Sta6"
                i = 193
                q = 196
            Case = "Sta7"
                i = 211
                q = 214
            Case = "Sta8"
                i = 229
                q = 232
        End Select

        Try
            Using EP As New ExcelPackage(New FileInfo(Local & TackStationXl))
                Dim WS As ExcelWorksheet = EP.Workbook.Worksheets("Alarms")
                FirstBlankRow = WS.Dimension.Rows + 1

                For x = i To q
                    If TackStation.Read("MP3300:I.Data[" & x & "]") <> 0 Then

There is more but it is repeat code.

The Problem that I am seeing is that the Datasubsriber2 only fires for Sta1Error.DataChanged and Sta2Error.DataChanged.  I do not ever see the other stations fire when one of the defined bits are triggered in the PLC.

Anyone know why the other Datasubscriber2's do not get captured?  Is there a limit to the number of Handles I can have on a sub?

Any Help would be great.
Thanks



« Last Edit: August 06, 2024, 10:48:39 AM by Arvanoss »

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Grabbing the Member "Name" from a DataSubscriber2
« Reply #3 on: October 09, 2024, 05:39:39 PM »
Sorry for the super late response (and I hope you found an answer before this) but you'll probably want to use the DataUpdated event instead of DataChanged.

Quote
    Private Sub Sta1Error_DataUpdated(sender As Object, e As MfgControl.AdvancedHMI.Drivers.Common.PlcComEventArgs) Handles _
        Sta1Error.DataUpdated, Sta2Error.DataUpdated, Sta3Error.DataUpdated, Sta4Error.DataUpdated, Sta5Error.DataUpdated _
        , Sta6Error.DataUpdated, Sta7Error.DataUpdated, Sta8Error.DataUpdated



DataChanged event only fires when the first item in DataSubscriber2 updates; DataUpdated event fires if ANY of them update.

Arvanoss

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Grabbing the Member "Name" from a DataSubscriber2
« Reply #4 on: October 10, 2024, 06:23:25 AM »
Thanks for the reply bobbh95,

I tried changing the DataChanged to DataUpdated and I get this error...

BC30590: Event 'DataUpdated' cannot be found.

When I look at the DataSubscriber2 Properties there are only 4 options, "ComError", "DataChanged", "DataReturned", and "SuccessfulSubscription"

Thanks

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Grabbing the Member "Name" from a DataSubscriber2
« Reply #5 on: October 11, 2024, 06:32:13 PM »
My apologies!! I was remembering incorrectly - I didn't have Visual Studio open in front of me at the time. The event we're looking for is going to be the DataReturned event!


That's 100% my bad.


Edit: Darn, I just went back and re-read, and it seems I lost the plot somewhere.

Does each DataSubscriber2 have multiple tags that it is looking at? Or is does each DataSubscriber2's PLCAddressValueItems only contain a single PLCAddressValueItem inside of it? If there's only a single PLCAddressValueItem, then you'll probably be better served with a DataSubscriber as it is a bit simpler to use, and only works on a single tag in a PLC.

Another possibility for why the DataSubscriber2 events aren't all firing off might be: Are all of these looking at the same PLC? Even if it's (for example) a rack with an A-B L83ES and several L83 PLCs sharing a single IP Address, you'll need a separate EthernetIPforCLXCom object for each separate PLC, and you'd set the Chassis Slot accordingly.
« Last Edit: October 11, 2024, 06:59:18 PM by bobbh95 »

bobbh95

  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Grabbing the Member "Name" from a DataSubscriber2
« Reply #6 on: October 11, 2024, 07:23:50 PM »
If your PLCAddressValueItems collection looks something like this picture (if made via the GUI) then you'll likely either want to consolidate everything to a singular DataSubscriber2 instance, and get the values from each PLCAddressValueItem with code to the effect of:

Code: [Select]
Private Sub DataSubHandler(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles StaErrors.DataReturned

     ' Insert your code here


     Select Case e.PLCAddress
          Case "Sta1Error.PLCAddress"
               i = 103
               q = 105
          Case "Sta2Error.PLCAddress"
               i = 121
               q = 123
          ' ... and so on from here on out
     End Select

     ' Insert your code here too!

End Sub

If your DataSubscriber2 isn't made with the GUI, but instead purely through code

  • You probably already know (roughly) how many PLCAddressValueItems are in the object without needing to look at the GUI
  • If not, you can disconnect from the network that you're communicating to the PLC on, add a button with a .Click event with Debug.WriteLine(DataSub2.PLCAddressValueItems.Count()), launch the program in debug mode, and hit the button you made. It will tell you how -  in the Output pane of Visual Studio - many items are contained in the Collection of PLCAddressValueItems at the time you clicked the button

Otherwise, if you want to keep it as a bunch of separate objects, you'd change them to DataSubscribers instead of DataSubscriber2s, and keep the rest of your code more or less the same.


« Last Edit: October 11, 2024, 07:58:03 PM by bobbh95 »

Arvanoss

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Grabbing the Member "Name" from a DataSubscriber2
« Reply #7 on: October 14, 2024, 08:37:44 AM »
Thanks for the reply bobbh95

  Each of the DataSubscriber2's have 12 items in the collection, they are all built off the GUI.

  I was able to get the "Name" property of the item as they got fired and am now working to process the data.

Thanks