Author Topic: PLCAddressMaxValue for BarLevel  (Read 3109 times)

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
PLCAddressMaxValue for BarLevel
« on: May 12, 2015, 01:39:39 AM »
Dear Archie,

BarLevel component has PLCAddressValue which displays present value of the address.
In some cases, it is required to dynamically change the Bar's maximum value.
Please advise if possible to implement PLCAddressMaxValue.
Thank you.

Best regards,
Andrew

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: PLCAddressMaxValue for BarLevel
« Reply #1 on: May 12, 2015, 04:31:02 AM »
It is actually quite easy. You can link existing properties to a PLC address by editing BarLevel.vb in the AdvancedHMIControls project and adding a new property like this:

    Public Property PLCAddressMaximum() As String


It must start with PLCAddress and followed by the exact spelling of an existing property.

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: PLCAddressMaxValue for BarLevel
« Reply #2 on: May 12, 2015, 04:55:59 AM »
Dear Archie,

Thanks for the tips, it is working with ScaleFactor 1.
In my case, the ScaleFactor is 0.1, so I need to have another property of MaximumScaleFactor.
Please advise, Thank you.

Code: [Select]
'*****************************************
    '* Property - Address in PLC to Link to
    '*****************************************
    Private m_PLCAddressMaximum As String = ""
    Public Property PLCAddressMaximum() As String
        Get
            Return m_PLCAddressMaximum
        End Get
        Set(ByVal maximum As String)
            If m_PLCAddressMaximum <> maximum Then
                m_PLCAddressMaximum = maximum

                '* When address is changed, re-subscribe to new address
                SubscribeToCommDriver()
            End If
        End Set
    End Property

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: PLCAddressMaxValue for BarLevel
« Reply #3 on: May 12, 2015, 07:44:22 AM »
What about something like this:


    Public Shadows Property Maximum As Single
        Get
            Return MyBase.Maximum / m_ValueScaleFactor
        End Get
        Set(value As Single)
            MyBase.Maximum = value * m_ValueScaleFactor
        End Set
    End Property

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: PLCAddressMaxValue for BarLevel
« Reply #4 on: May 13, 2015, 01:55:54 AM »
Dear Archie,

I got an InvalidCastException error after that.

Here is my additional codes in barlevel.vb:

Code: [Select]
     Public Shadows Property Maximum As Single
        Get
            Return MyBase.Maximum / m_ValueScaleFactor
        End Get
        Set(value As Single)
            MyBase.Maximum = value * m_ValueScaleFactor
        End Set
    End Property

    '*****************************************
    '* Property - Address in PLC to Link to
    '*****************************************
    Private m_PLCAddressMaximum As String = ""
    Public Property PLCAddressMaximum() As String
        Get
            Return m_PLCAddressMaximum
        End Get
        Set(ByVal maximum As String)
            If m_PLCAddressMaximum <> maximum Then
                m_PLCAddressMaximum = maximum

                '* When address is changed, re-subscribe to new address
                SubscribeToCommDriver()
            End If
        End Set
    End Property

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: PLCAddressMaxValue for BarLevel
« Reply #5 on: May 13, 2015, 10:50:17 AM »
Modify the code to this:

            If m_ValueScaleFactor = 1 Then
                MyBase.Text = value
            Else
                Dim v As Double
                If Double.TryParse(value, v) Then
                    MyBase.Text = value * m_ValueScaleFactor
                Else
                    MyBase.Text = value
                End If
            End If

andrew_pj

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: PLCAddressMaxValue for BarLevel
« Reply #6 on: May 14, 2015, 12:36:45 AM »
The InvalidCastException error has gone now.
But with below codes, I get wrong Maximum value (see attachment).
Without below codes, I get correct Maximum value, but no ValueScaleFactor.

Code: [Select]
Public Shadows Property Maximum As Single
        Get
            Return MyBase.Maximum / m_ValueScaleFactor
        End Get
        Set(value As Single)
            MyBase.Maximum = value * m_ValueScaleFactor
        End Set
    End Property

fairshuru

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: PLCAddressMaxValue for BarLevel
« Reply #7 on: December 10, 2015, 06:20:52 AM »
In my case, the ScaleFactor is 0.1, so I need to have another property of MaximumScaleFactor.
Please advise, Thank you.
GuL