Author Topic: BarLevel dynamically changing PLC Address  (Read 1502 times)

shawn_75

  • Newbie
  • *
  • Posts: 8
    • View Profile
BarLevel dynamically changing PLC Address
« on: February 14, 2019, 01:42:04 PM »
I'm attempting to dynamically change the PLCAddressMaximum and PLCAddressValue properties on the bar level component based on the user's selection of a drop down box.  The problem is that the values in those fields seem to update, but the bar level does not work.  It is still getting its data from the first selected addresses.  I believe this has something to do with the subscription manager in the background.  I have tried BarLevel.Update() and BarLevel.Refresh() after making the address changes to no avail.  How do I go about passing the new PLC addresses to the BarLevel component when I want to change the PLC addresses?  BarLevel.ComComponent.Subcribe looks like it may be what I need, but I need some direction.

Thank you,
Shawn

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BarLevel dynamically changing PLC Address
« Reply #1 on: February 14, 2019, 01:53:48 PM »
In the AdvancedHMIControls project, open SubscriptionHandler.vb
Go to this code:
Code: [Select]
   Public Sub SubscribeTo(ByVal plcAddress As String, ByVal numberOfElements As Integer, ByVal callBack As EventHandler(Of SubscriptionHandlerEventArgs),
                           ByVal propertyName As String, ByVal ScaleFactor As Double, ByVal ScaleOffset As Double)
        '* 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_ComComponent.Unsubscribe(m_SubscriptionList(index).NotificationID)
            m_SubscriptionList.RemoveAt(index)
            '* V3.99y - the address changed and old subscription removed, so force the next condition check to re-subscribe
            index = m_SubscriptionList.Count
        End If
This is where it checks to see if you changed the PLCAddress.

shawn_75

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: BarLevel dynamically changing PLC Address
« Reply #2 on: February 14, 2019, 04:18:07 PM »
Thank you Archie,

I don't understand how to call that code.  Do I add that snippet to my existing code that changes the values for PLCAddressMaximum and PLCAddressValue?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BarLevel dynamically changing PLC Address
« Reply #3 on: February 14, 2019, 04:36:47 PM »
That code is already called when you change the PLCAddress property. You can add a breakpoint and see why it does not remove the old subscription and make a new one.

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BarLevel dynamically changing PLC Address
« Reply #4 on: February 14, 2019, 05:50:11 PM »
I tried this and it worked as expected in my test. I added 2 buttons to the form that would change the address:
Code: [Select]
   Private Sub Button1_Click_4(sender As Object, e As EventArgs) Handles Button1.Click
        BarLevel1.PLCAddressMaximum = "40002"
    End Sub

    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        BarLevel1.PLCAddressMaximum = "40001"

    End Sub

When I click each button, the Maximum changes to the correct values from my Modbus simulator.

shawn_75

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: BarLevel dynamically changing PLC Address
« Reply #5 on: February 15, 2019, 08:45:42 AM »
I'm getting some strange behavior.  The breakpoints I inserted in SubscriptionHandler.vb show that the values are being updated.  I am pointing the bar level to different timers in the PLC when the dropdown selection is made.  When I change the selection, it hits the breakpoint 4 times.

First - InitializeSubscribeTry PLCAddress = T4:12/ACC (The old timer I was monitoring)
Second - InitializeSubscribeTry PLCAddress = T4:6/PRE (T4:12 is the new timer I want to monitor)
Third - InitializeSubscribeTry PLCAddress = T4:6/ACC
Fourth - InitializeSubscribeTry PLCAddress = T4:6/PRE

If I change the seleted timer again, I get the same 4 breakpoint hits

First - InitializeSubscribeTry PLCAddress = T4:6/ACC (The old timer I was monitoring)
Second - InitializeSubscribeTry PLCAddress = T4:12/PRE (T4:12 is the new timer I want to monitor)
Third - InitializeSubscribeTry PLCAddress = T4:12/ACC
Fourth - InitializeSubscribeTry PLCAddress = T4:12/PRE

On initial loading of the form, the BarLevel control hits the breakpoint 3 times.  It hits on the ACC value twice and the PRE value once.



Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BarLevel dynamically changing PLC Address
« Reply #6 on: February 15, 2019, 09:31:42 AM »
That is normal because any time a PLCAddress* property is changed, the SubscriptionHandler re-scans all of the auto-properties.

So that does verify the subscriptions are being updated to the new addresses. I will have to setup my MicroLogix and try this to see if I can the same behavior.

shawn_75

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: BarLevel dynamically changing PLC Address
« Reply #7 on: February 15, 2019, 09:40:06 AM »
It subscribes to the initial PLC address just fine when the form loads.  Then it subscribes just fine to the PLC address on the FIRST change of the dropdown selection.  If I try and change it again, it goes through all the motions and the control shows that all of the properties have changed to what they should be.  It just no longer shows any data for this second selection.  If I change the dropdown a third time, back to the original, it shows data again.  My dropdown has 3 choices, but only two of them utilize the bar level.  I'm only switching the Maximum and Value properties between two selections. 

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BarLevel dynamically changing PLC Address
« Reply #8 on: February 15, 2019, 09:58:25 AM »
I tried this with a MicroLogix using two buttons and this code:
Code: [Select]
    Private Sub Button1_Click_4(sender As Object, e As EventArgs) Handles Button1.Click
        BarLevel1.PLCAddressMaximum = "T4:1/PRE"
        BarLevel1.PLCAddressValue = "T4:1/ACC"
    End Sub

    Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
        BarLevel1.PLCAddressMaximum = "T4:0/PRE"
        BarLevel1.PLCAddressValue = "T4:0/ACC"
    End Sub
And it still worked normal for me. What version of AdvancedHMI are you using? I tested on 3.99y Beta 19

shawn_75

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: BarLevel dynamically changing PLC Address
« Reply #9 on: February 15, 2019, 04:46:40 PM »
I'm using 3.99w

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: BarLevel dynamically changing PLC Address
« Reply #10 on: February 15, 2019, 05:26:01 PM »
3.99w is fairly old now. I would definitely recommend at least 3.99x if you want stable, or 3.99y if you are ok with a beta version that is nearing complete.