Author Topic: Latest version AHMI InterpretValueAsBCD  (Read 2900 times)

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Latest version AHMI InterpretValueAsBCD
« on: March 25, 2020, 05:21:20 AM »
Hi,
i was using old version of AHMI in the past. Now i need to read/write to Omron E area and saw that last version supports that too, thats nice.
But when i use basiclabel and set InterpretValueAsBCD as true, if the value in register of the plc is #0 ,value 0 is not shown on display. In older versions you set Value properties of basic label to for example 0000 and if value in register of the plc was #0, it shows 0000 on display. The problem is that i need to write to register also when value is 0. Soo in newest version i dont know where to click to write to register as value 0 is not shown.

Thank you

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Latest version AHMI InterpretValueAsBCD
« Reply #1 on: March 25, 2020, 09:56:01 AM »
Do you know how to set a breakpoint and step through code? If so, open BasicLabel.vb and go to line 566 and step through this code to see what ResultText is:
Code: [Select]
               '* V3.99v
                If m_InterpretValueAsBCD Then
                    Try
                        Dim b() As Byte = BitConverter.GetBytes(CInt(ResultText))
                        ResultText = ""

                        For index = 3 To 0 Step -1
                            If (b(index) And 240) > 0 Or ResultText.Length > 0 Then
                                ResultText &= CStr((b(index) And 240) >> 4)
                            End If
                            If (b(index) And 15) > 0 Or ResultText.Length > 0 Then
                                ResultText &= CStr((b(index) And 15))
                            End If
                        Next
                    Catch ex As Exception
                        ResultText = "BCD Error"
                    End Try
                End If

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #2 on: March 25, 2020, 11:09:15 AM »
Yea, i found that lines of code in BasicLabel.vb before i ask here. When i insert breakpoint and check, it shows
ResultText "" .

I think must be something with the line of code
Code: [Select]
If (b(index) And 240) > 0 Or ResultText.Length > 0 Then
if i change to that

Code: [Select]
If (b(index) And 240) > 0 Or ResultText.Length >= 0 Then
it shows "00000000"

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Latest version AHMI InterpretValueAsBCD
« Reply #3 on: March 25, 2020, 11:21:30 AM »
It looks like it should be this:
Code: [Select]
               If m_InterpretValueAsBCD Then
                    Try
                        Dim b() As Byte = BitConverter.GetBytes(CInt(ResultText))

                        If (CInt(ResultText)) > 0 Then
                            ResultText = ""
                            For index = 3 To 0 Step -1
                                If (b(index) And 240) > 0 Or ResultText.Length > 0 Then
                                    ResultText &= CStr((b(index) And 240) >> 4)
                                End If
                                If (b(index) And 15) > 0 Or ResultText.Length > 0 Then
                                    ResultText &= CStr((b(index) And 15))
                                End If
                            Next
                        Else
                            ResultText = "0"
                        End If
                    Catch ex As Exception
                        ResultText = "BCD Error"
                    End Try
                End If

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #4 on: March 25, 2020, 01:16:33 PM »
If i try that i got error about Else statment is not correctly form.....

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Latest version AHMI InterpretValueAsBCD
« Reply #5 on: March 25, 2020, 01:20:31 PM »
Here is the code expanded out more so you can see where it should start and end relative the the code around it:
Code: [Select]
                If m_BooleanDisplay = BooleanDisplayOption.AutoManual Then ResultText = "Manual"
            Else
                '* V3.99v
                If m_InterpretValueAsBCD Then
                    Try
                        Dim b() As Byte = BitConverter.GetBytes(CInt(ResultText))

                        If (CInt(ResultText)) > 0 Then
                            ResultText = ""
                            For index = 3 To 0 Step -1
                                If (b(index) And 240) > 0 Or ResultText.Length > 0 Then
                                    ResultText &= CStr((b(index) And 240) >> 4)
                                End If
                                If (b(index) And 15) > 0 Or ResultText.Length > 0 Then
                                    ResultText &= CStr((b(index) And 15))
                                End If
                            Next
                        Else
                            ResultText = "0"
                        End If
                    Catch ex As Exception
                        ResultText = "BCD Error"
                    End Try
                End If

                '******************************************************
                '* Scale Factor and Format only applied to non-Boolean
                '******************************************************
                '* Apply the scale factor
                Try

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #6 on: March 25, 2020, 03:08:35 PM »
This code is working to show correctly 0, when plc register is 0. Now i try to write value 50 to register, but instead of 50 it writes 32 to plc, something with dec/hex goes wrong, but the reading from plc register is correct, if i write directly from PLC Omron software. Is it possible just  to add read/write to E register Omron in driver code because  in old version of AHMI all that works, and already have app working?

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Latest version AHMI InterpretValueAsBCD
« Reply #7 on: March 25, 2020, 03:22:12 PM »
Find this code in the version that you say is working:
Code: [Select]
    Private Sub KeypadPopUp_ButtonClick(ByVal sender As Object, ByVal e As MfgControl.AdvancedHMI.Controls.KeypadEventArgs) Handles KeypadPopUp.ButtonClick
        If e.Key = "Quit" Then
Then look further down for where it writes the value to the PLC
Code: [Select]
                      If KeypadScaleFactor = 1 Or KeypadScaleFactor = 0 Then
                            m_ComComponent.Write(m_PLCAddressKeypad, KeypadPopUp.Value)
                        Else
                            m_ComComponent.Write(m_PLCAddressKeypad, CDbl(KeypadPopUp.Value) / m_KeypadScaleFactor)
                        End If

Do you see any code that does any processing under the BCD condition? The current BasicLabel does not and that is why the write value is different than the read value.

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #8 on: March 25, 2020, 05:30:41 PM »
I was checked that lines of code but its the same as you paste, nothing to do about converting etc.... But i check some FINSBaseCom.vb on latest AHMI and find some differences start at line 551 and below. Thats the code in my older version of AHMI
Code: [Select]
'* Memory Area Read (FINS 1,2)
        '* Reference : Section 5-3-3
        Public Overrides Function BeginWrite(ByVal address As MfgControl.AdvancedHMI.Drivers.Omron.OmronPlcAddress, ByVal dataToWrite() As String) As Integer
            If address Is Nothing Then Throw New ArgumentNullException("WriteData Address parameter cannot be null.")


            '* No data was sent, so exit
            If dataToWrite.Length <= 0 Then Return 0

            Dim CurrentTNS As Byte
            '* Save this
            CurrentTNS = CByte(GetNextTransactionID(255))

            Dim Header As New MfgControl.AdvancedHMI.Drivers.Omron.FINSHeaderFrame(MfgControl.AdvancedHMI.Drivers.Omron.GatewayCountOption.Three, TargetAddress, SourceAddress, CByte(CurrentTNS))

            '* Save this TNS to check if data received was requested by this instance
            'ActiveTNSs.Add(CurrentTNS)

            '* Mark as a write and Save
            address.IsWrite = True
            Requests(CurrentTNS) = address

            '* Attach the instruction data
            Dim dataPacket As New List(Of Byte)
            dataPacket.Add(address.MemoryAreaCode)
            dataPacket.Add(CByte((address.ElementNumber >> 8) And 255))
            dataPacket.Add(CByte((address.ElementNumber) And 255))

            '* 24-SEP-15 A 0xff was going in the bit position if no bit specified. This is so returned data doesn't think a bit was requested
            Dim BitNumberByte As Integer = Requests(CurrentTNS).BitNumber
            If Requests(CurrentTNS).BitNumber < 0 Or Requests(CurrentTNS).BitNumber > 64 Then
                BitNumberByte = 0
            End If
            dataPacket.Add(CByte(BitNumberByte))

            dataPacket.Add(CByte((address.NumberOfElements >> 8) And 255))
            dataPacket.Add(CByte((address.NumberOfElements) And 255))

            If address.BitsPerElement = 16 Then
                Dim x(1) As Byte
                For i As Integer = 0 To dataToWrite.Length - 1
                    If m_TreatDataAsHex Then
                        Dim data As Integer
                        Try
                            data = Convert.ToUInt16(dataToWrite(i), 16)
                        Catch ex As Exception
                            Throw New MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException("Invalid hexadecimal value " & dataToWrite(i))
                        End Try
                        x(0) = CByte(data And 255)
                        x(1) = CByte(data >> 8)
                    Else
                        x = BitConverter.GetBytes(CUShort(dataToWrite(i)))
                        If address.IsBCD Then
                            '* Convert to BCD
                            x(1) = CByte(CUShort(Math.Floor(CDbl(dataToWrite(i)) / 100)))
                            x(0) = MfgControl.AdvancedHMI.Drivers.Common.CalculationsAndConversions.HexToByte(Convert.ToString(CUShort(dataToWrite(i)) - (x(1) * 100)))
                            x(1) = MfgControl.AdvancedHMI.Drivers.Common.CalculationsAndConversions.HexToByte(Convert.ToString(x(1)))
                        End If
                    End If
                    '* Bitconverter uses LittleEndian
                    '* Omron uses BigEndian, so reverse
                    dataPacket.Add(x(1))
                    dataPacket.Add(x(0))
                Next
            Else
                '* Bit level
                For i As Integer = 0 To dataToWrite.Length - 1
                    If Convert.ToInt32(dataToWrite(i)) > 0 Then
                        dataPacket.Add(1)
                    Else
                        dataPacket.Add(0)
                    End If
                Next
            End If[code]


Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Latest version AHMI InterpretValueAsBCD
« Reply #9 on: March 25, 2020, 05:35:34 PM »
I need to check, but I think the BCD is built into the driver by adding an "@B" on the end of the address. In that case you do not need the BCD functionality of the BasicLabel

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #10 on: March 25, 2020, 08:05:13 PM »
Code: [Select]
If address.BitsPerElement = 16 Then
                Dim x(1) As Byte
                For i As Integer = 0 To dataToWrite.Length - 1
                    If m_TreatDataAsHex Then
                        Dim data As Integer
                        Try
                            data = Convert.ToUInt16(dataToWrite(i), 16)
                        Catch ex As Exception
                            Throw New MfgControl.AdvancedHMI.Drivers.Common.PLCDriverException("Invalid hexadecimal value " & dataToWrite(i))
                        End Try
                        x(0) = CByte(data And 255)
                        x(1) = CByte(data >> 8)

that code....

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5317
    • View Profile
    • AdvancedHMI
Re: Latest version AHMI InterpretValueAsBCD
« Reply #11 on: March 25, 2020, 08:46:19 PM »
In the PLCAddressValue property of the BasicLabel try using E0001@B

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #12 on: March 26, 2020, 02:48:19 AM »
Try that but still writes 64 instead of 100 to plc register.

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #13 on: March 26, 2020, 03:39:25 AM »
Latest AHMI, when i set OmronEthernetFINSCom1 TreatDataAsHex = True
and  basicLabel1 InterpretValueAsBCD = true
                         PLCAddressValue = E001
                         PLCAddressKeypad = E001
it writes 64 instead of 100, but read right.

If i set OmronEthernetFINSCom1 TreatDataAsHex = True
and  basicLabel1 InterpretValueAsBCD = true
                         PLCAddressValue = E001@B
                         PLCAddressKeypad = E001@B
it writes 61 instead of 1,looks like byteswap and wrong, but read right.

Soo i think with E001@B at the end is more trouble.

betilly

  • Jr. Member
  • **
  • Posts: 57
    • View Profile
Re: Latest version AHMI InterpretValueAsBCD
« Reply #14 on: March 26, 2020, 06:14:31 AM »
I find the same problem at this topic at the end
https://www.advancedhmi.com/forum/index.php?topic=2058.195