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

Arvanoss

  • Newbie
  • *
  • Posts: 28
    • 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: 5
    • 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: 28
    • 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 »