Author Topic: Datasubscriber2 bug? (TwinCAT)  (Read 5790 times)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Datasubscriber2 bug? (TwinCAT)
« Reply #15 on: October 15, 2015, 06:08:45 PM »
I was comparing the code you posted to what I posted and I do not see any difference? Am I missing something?

bobobo

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Datasubscriber2 bug? (TwinCAT)
« Reply #16 on: October 15, 2015, 06:16:47 PM »
Argh. Copy paste error by me.
I changed first IF to check subscriptionlist.count instead of usedsymbols.count
Several copies of each plcaddress were added to the subscriptionlist before usedsymbols got above 0.

(sent from Phone)

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Datasubscriber2 bug? (TwinCAT)
« Reply #17 on: October 15, 2015, 06:27:29 PM »
You are right. I'm not even sure what the purpose of the first IF statement was. I think it can be eliminated all together.

bobobo

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Datasubscriber2 bug? (TwinCAT)
« Reply #18 on: October 16, 2015, 07:19:18 AM »
I found that above changes makes the subscriptionlist in TwincatCom1 to be correct, but the subscriptionlist in subscriptionhandler is still populated with lots of duplicates.

Code: [Select]
   Public Sub SubscribeTo(ByVal PLCAddress As String, ByVal callBack As EventHandler(Of SubscriptionHandlerEventArgs), ByVal propertyName As String)
        '* Check to see if the subscription has already been created
        Dim index As Integer
        While index < m_SubscriptionList.Count AndAlso (m_SubscriptionList(index).CallBack <> callBack Or m_SubscriptionList(index).PropertyNameToSet <> propertyName)
            index += 1
        End While

        '* Already subscribed and PLCAddress was changed, so unsubscribe
        If (index < m_SubscriptionList.Count) AndAlso m_SubscriptionList(index).PLCAddress <> PLCAddress Then
            m_CommComponent.Unsubscribe(m_SubscriptionList(index).NotificationID)
            m_SubscriptionList.RemoveAt(index)
        End If

        '* Is there an address to subscribe to?
        If (PLCAddress IsNot Nothing) AndAlso (String.Compare(PLCAddress, "") <> 0) Then
            Try
                If m_CommComponent IsNot Nothing Then
                    '* If subscription succeedded, save the subscription details
                    Dim temp As New SubscriptionDetail(PLCAddress, callBack)
                    temp.PropertyNameToSet = propertyName
                    If PLCAddress.ToUpper.IndexOf("NOT ") = 0 Then
                        temp.Invert = True
                    End If
                    m_SubscriptionList.Add(temp)
                    InitializeTryTimer(500)
                Else
                    OnDisplayError("CommComponent Property not set")
                End If
            Catch ex As MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException
                '* If subscribe fails, set up for retry
                InitializeSubscribeTry(ex, PLCAddress)
            End Try
        End If
    End Sub


I don't see where this code stops duplicates except for the comment?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Datasubscriber2 bug? (TwinCAT)
« Reply #19 on: October 16, 2015, 07:44:55 AM »
The last If-Then should probably be wrapped in another condition:
Code: [Select]
        '* Make sure subscription doesn't already exist
        If index >= m_SubscriptionList.Count Then
            '* Is there an address to subscribe to?
            If (PLCAddress IsNot Nothing) AndAlso (String.Compare(PLCAddress, "") <> 0) Then

bobobo

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Datasubscriber2 bug? (TwinCAT)
« Reply #20 on: October 16, 2015, 07:56:49 AM »
Now i receive the correct number of datareturned-events in my main application!
112 events per second instead of a couple of thousands...
:)

Thanks for help

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Datasubscriber2 bug? (TwinCAT)
« Reply #21 on: October 16, 2015, 07:59:33 AM »
Thanks for the patience and feedback to help get that corrected.