Author Topic: Solved - BasicLabel: unable to change PLCAddressValue at runtime  (Read 574 times)

StevePLC

  • Newbie
  • *
  • Posts: 2
    • View Profile
Good morning  :)
I am a newbie, this is my first AdvancedHMI project, I am using two Omron PLC with OmronEthernetFINSCom connector and AdvancedHMIV399xPatched3
I have a couple of RadioButton and a label, my objective is as follows:

- If the user press RadioButton "PLC1", the program should connect OmronEthernetFINSCom with PLC1 Address (192.168.1.80) and show the value at PLCAddressValue D4082 using basic label 36.
- If the user press RadioButton "PLC2",  the program should connect OmronEthernetFINSCom with PLC2 Address (192.168.1.81) and show the value at PLCAddressValue D4120 always using basic label 36.

Reading various post on the forum, I'm doing the following:

Code: [Select]
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
            OmronEthernetFINSCom1.BeginInit()
            OmronEthernetFINSCom1.IPAddress = "192.168.1.80"
            OmronEthernetFINSCom1.EndInit()
            Dim value As New Drivers.PLCAddressItem("D4082")
            BasicLabel36.PLCAddressValue = value.PLCAddress
            Label23.Text = BasicLabel36.PLCAddressValue
End sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
        If RadioButton2.Checked Then
            OmronEthernetFINSCom1.BeginInit()
            OmronEthernetFINSCom1.IPAddress = "192.168.1.81"
            OmronEthernetFINSCom1.EndInit()
            Dim value As New Drivers.PLCAddressItem("D4120")
            BasicLabel36.PLCAddressValue = value.PLCAddress
            Label23.Text = BasicLabel36.PLCAddressValue
End sub

Default values at Design time are the same as Button1, and Label23 is there for test purpose, it display the right PLC Address as soon as I press one of the two buttons.
When the programs start, BasicLabel36 correctly displays the value from the first Omron PLC address D4082 (as per Design Time settings), but BasicLabel36 change it's value only the first time Button2 is pressed, then it remains immutable...

Thanks in advance if someone could help, I'm really stuck here...

Steve
« Last Edit: May 27, 2023, 06:45:30 AM by StevePLC »

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: BasicLabel: unable to change PLCAddressValue at runtime
« Reply #1 on: May 24, 2023, 09:07:49 AM »
The very first thing I would do is to use version 3.99y Beta from this forum.

I think you can simplify your code because the BasicLabel uses the string for PLCAddresses and not the new complex address object.
Code: [Select]
Private Sub RadioButton1_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
            OmronEthernetFINSCom1.IPAddress = "192.168.1.80"
            BasicLabel36.PLCAddressValue = "D4082"
            Label23.Text = BasicLabel36.PLCAddressValue
End sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton2.CheckedChanged
        If RadioButton2.Checked Then
            OmronEthernetFINSCom1.IPAddress = "192.168.1.81"
           BasicLabel36.PLCAddressValue = "D4120"
            Label23.Text = BasicLabel36.PLCAddressValue
End sub

This is what I would do to see what is happening.
- View Code on BasicLabel.vb
- Go to line 740 and look for this:
Code: [Select]
    Private Sub SubscribeToComDriver()
        If Not DesignMode And IsHandleCreated Then
            CreateSubscriptionHandler()

            SubScriptions.SubscribeAutoProperties()
        End If
    End Sub
- Set a breakpoint at "SubScriptions.SubscribeAutoProperties()"
- Step through the code using F11
- When it gets to this code, look at the variable values:
Code: [Select]
                            If PA Is Nothing Then
                                SubscribeTo(PLCAddress, 1, Nothing, PropertyToWrite, 1, 0)
                            Else
                                SubscribeTo(PLCAddress, 1, Nothing, PropertyToWrite, PA.ScaleFactor, PA.ScaleOffset)
                            End If

StevePLC

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: BasicLabel: unable to change PLCAddressValue at runtime
« Reply #2 on: May 27, 2023, 06:43:51 AM »
Many thanks Archie  :)
using 3.99y Beta as per your suggestion solved my problems.

Steve