Author Topic: AlarmSubscriber, getting info from Item Collection  (Read 1993 times)

t.pal

  • Newbie
  • *
  • Posts: 4
    • View Profile
AlarmSubscriber, getting info from Item Collection
« on: February 06, 2016, 05:24:03 PM »
First Off, Amazing software. I'm newISH to vb.net so forgive my ignorance.

What I've done is modified a DataSubscriber to function as an alarming tool. It performs certain actions (email, SMS, log alarms to text file, record camera etc) on change of various bit values. What I am having trouble with is being able to send a description of the bit that has alarmed without hard coding a description for each address.

So far I have added a plcAddressDesc property to the PLCaddressValueItems collection in the "AlarmSubscriber" Component I've created

I'm using some code you posted:
Code: [Select]
Private Sub AlarmSubscriber1_DataChanged_1(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles Me.DataChanged
        '* Make sure Data came back
        If e.Values IsNot Nothing AndAlso e.Values.Count > 0 Then
            '* Did it come back as True or 1?
            If String.Compare(e.Values(0), "TRUE", True) = 0 Or e.Values(0) = "1" Then

                MsgBox(e.PlcAddress)

            End If
        End If
    End Sub

What I was hoping to do was be able to use "e.PlcAddressDesc" to get the alarm description.  Maybe this is the wrong way of going about it? To do this I think I need to add it to PlcComEventArgs. I don't see the ability to edit this.Maybe there is another way like matching the PlcAddress? Even If I could get the item (memeber) number from the collection to the get the Description property.

I've played around with a few different things.... e.values.item.... etc. Can't seem to find an identifier.

Any help would be greatly appreciated.

Thanks


Update:
I should also note, I am going to store additional info in the item properties, to control which notifications/alarms to trigger. So having access to these properties would be important.
« Last Edit: February 06, 2016, 05:34:22 PM by t.pal »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
Re: AlarmSubscriber, getting info from Item Collection
« Reply #1 on: February 06, 2016, 05:50:38 PM »
Start by adding a new class to the AdvancedHMIControls project and name it PLCAddressItemEx.vb
Code: [Select]
Public Class PLCAddressItemEx
    Inherits MfgControl.AdvancedHMI.Drivers.PLCAddressItem

    Private m_Description As String
    Public Property Description As String
        Get
            Return m_Description
        End Get
        Set(value As String)
            m_Description = value
        End Set
    End Property

End Class

Next got to line 180 in DataSubscriber2.vb and change the type in 2 places like this:
Code: [Select]
    Private m_PLCAddressValueItems As New System.Collections.ObjectModel.ObservableCollection(Of PLCAddressItemEx)
    <System.ComponentModel.Category("PLC Properties")> _
    <System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)> _
    Public ReadOnly Property PLCAddressValueItems() As System.Collections.ObjectModel.ObservableCollection(Of PLCAddressItemEx)

Be sure all designers are closed, then Rebuild the Solution. This will now give you a description field for each PLC address added to the DataSubscriber2

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
Re: AlarmSubscriber, getting info from Item Collection
« Reply #2 on: February 06, 2016, 05:52:32 PM »
In the OnDataReturned Event handler within DataSubscriber2.vb, you can compare e.PLCAddress to each item in the m_PLCAddressValueItems collection to find the match and then retrieve the Description field.

t.pal

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: AlarmSubscriber, getting info from Item Collection
« Reply #3 on: February 06, 2016, 06:33:41 PM »
Thanks for the Super Quick reply. I have the property added, just working on matching to PlcAddress. Halfway there.

t.pal

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: AlarmSubscriber, getting info from Item Collection
« Reply #4 on: February 06, 2016, 06:36:44 PM »
Got it. Thanks!

Code: [Select]
For i = 0 To Me.PLCAddressValueItems.Count
                    If Me.PLCAddressValueItems.Item(i).PLCAddress = e.PlcAddress Then
                        MsgBox(Me.PLCAddressValueItems.Item(i).PLCAddressDesc)
                        Exit For
                    End If
                Next i

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5324
    • View Profile
    • AdvancedHMI
Re: AlarmSubscriber, getting info from Item Collection
« Reply #5 on: February 06, 2016, 06:42:48 PM »
Be sure to use a -1
Code: [Select]
For i = 0 To Me.PLCAddressValueItems.Count-1

t.pal

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: AlarmSubscriber, getting info from Item Collection
« Reply #6 on: February 06, 2016, 08:17:10 PM »
Right, thanks!