Author Topic: Subscribe Method  (Read 992 times)

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Subscribe Method
« on: May 23, 2017, 08:04:50 AM »
Hi,

I am using the Subscribe on certain tags that a user can define via XML, which is then read in and the subscriptions made.
Code: [Select]
Private Sub QCompositeButtonPLCMessages_ItemActivated(sender As System.Object, e As Qios.DevSuite.Components.QCompositeEventArgs) Handles QCompositeButtonPLCMessages.ItemActivated
        Try
            Dim frmPLCMessages As New frmPLCMessages()
            If frmPLCMessages.ShowDialog(Me) = DialogResult.OK Then
                ApplicationPLCMessages = New PLCMessages().Load
                SubscribePLCMessages()
            End If
            frmPLCMessages = Nothing
        Catch ex As Exception
            Log.ErrorMessage(ex.TargetSite.Name, ex.Message, "1410")
        End Try
    End Sub

    Private Sub UnsubscribePLCMessages()
        For Each i As Integer In SubscriptionIDs
            PLC.UnSubscribe(i)
        Next
        SubscriptionIDs.Clear()
    End Sub

    Private Sub SubscribePLCMessages()
        UnsubscribePLCMessages()

        For Each pm As PLCMessage In ApplicationPLCMessages
            If pm.Message.Length > 0 Then
                SubscriptionIDs.Add(PLC.Subscribe(pm.Tag, 1, AddressOf SubscriptionCallback))
            End If
        Next

    End Sub

Upon initial loading of the main form the method SubscribePLCMessages is ran and the subscription works.
If i open the form frmPLCMessages and then click OK to the form the SubscribePLCMessages is re-ran to ensure any changes made to the XML file take place. However, upon this second call to SubscribePLCMessages my program hangs on the line 'PLC.Subscribe(pm.Tag, 1, AddressOf SubscriptionCallback)'.

Any Ideas?

Thanks.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Subscribe Method
« Reply #1 on: May 23, 2017, 08:57:27 AM »
What driver and what version are you using?

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Subscribe Method
« Reply #2 on: May 26, 2017, 09:35:52 AM »
Hi Archie,

I am using the ClxDriverV111R766.

PJonHar

  • Newbie
  • *
  • Posts: 28
    • View Profile
Re: Subscribe Method
« Reply #3 on: June 13, 2017, 05:48:31 PM »
bump

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Subscribe Method
« Reply #4 on: June 13, 2017, 09:10:24 PM »
There is a SyncLock that prevents subscription changes while they are being updated. One possibility for a call to Subscribe to hang would be this:

On a callback of subscription data returned, if you hold that and at the same time wait for a call to subscribe to finish, you will be in a grid lock situation.

Also the Subscribe method in the driver does not check for duplicate subscriptions. So if you call Subscribe with the same parameters twice, then the driver will process the callback twice for every data update.