Author Topic: Dec to BCD  (Read 3183 times)

billfloyd806

  • Newbie
  • *
  • Posts: 4
    • View Profile
Dec to BCD
« on: April 10, 2013, 12:15:25 PM »
This is my first time using this software. I have a value in the plc that is in BCD, but AdvancedHMI is showing the value as decimal.

For example the plc is showing the temperature as 1303 but the meter on my screen is showing 4866. How do I convert it so Advanced HMI displays the input to the meter as BCD?

billfloyd806

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Dec to BCD
« Reply #1 on: April 10, 2013, 01:50:18 PM »
Figured out my issue. I had to convert it to a BIN value. Working perfect, nice software!

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5262
    • View Profile
    • AdvancedHMI
Re: Dec to BCD
« Reply #2 on: April 10, 2013, 05:11:56 PM »
There is a way to display a value that is stored in BCD format, but it is a little involved. This requires modifying the control to intercept the value from the PLC and convert it.

1) In the Solution Explorer, under the Controls folder, right click DigitalPanelMeter.vb and select View Code.
2) Go to about line 322 and look for this code:
    Private Sub PolledDataReturnedValue(ByVal Values() As String)
        Try
            MyBase.Value = Values(0)
        Catch
            DisplayError("INVALID VALUE RETURNED!" & Values(0))
        End Try
    End Sub

3) Modify the code like this:

    Private Sub PolledDataReturnedValue(ByVal Values() As String)
        Try
            '* Extract the individual bytes from the word
            Dim b() As Byte = System.BitConverter.GetBytes(CInt(Values(0)))
            '* Break out the nibbles and convert to BCD
            Dim BCD As Integer = (b(0) And 15) + ((b(0) >> 4) * 10)
            BCD += ((b(1) And 15) * 100) + ((b(1) >> 4) * 1000)

            MyBase.Value = BCD
        Catch
            DisplayError("INVALID VALUE RETURNED!" & Values(0))
        End Try
    End Sub