Author Topic: Omron Ethernet Fins Float value read  (Read 3545 times)

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Omron Ethernet Fins Float value read
« on: November 30, 2016, 08:37:45 AM »
Hi,

please guide me as to how Omron Ethernet Fins of V3.99r can read Float values

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: Omron Ethernet Fins Float value read
« Reply #1 on: November 30, 2016, 09:35:08 AM »
The Omron data tables do not natively support 32 bit values and the driver does not have any conversion functionality, so you would have to use code to combine and convert 2 integer values into a float. This is a code snippet of how you might go about it:
Code: [Select]
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim MyFloat As Single = IntsToFloat(OmronEthernetFINSCom1.Read("D0", 2))
    End Sub

    Private Function IntsToFloat(ByVal v() As String) As Single
        If v Is Nothing OrElse v.Count < 2 Then
            Return 0
        End If

        '* Convert to integers
        '* Strip off bits above 16 bit because they would be invalid
        Dim vi(1) As UInt16
        vi(0) = CInt(v(0)) And 65535
        vi(1) = CInt(v(1)) And 65535


        '* Extract the bytes
        Dim b(3) As Byte
        BitConverter.GetBytes(vi(0)).CopyTo(b, 0)
        BitConverter.GetBytes(vi(1)).CopyTo(b, 2)

        '* Convert the bytes to a single precision
        Dim Result As Single
        Result = BitConverter.ToSingle(b, 0)

        Return Result
    End Function

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Omron Ethernet Fins Float value read
« Reply #2 on: November 30, 2016, 09:47:17 AM »
Hey Archie,

Thank it started Polling Float Data. Could i put this into BasicLabel to read Float Data. Will you help me do that if that is possible. Also the comm events like CommError and DataReceived are Unresponsive. If u may please help me with that too..

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: Omron Ethernet Fins Float value read
« Reply #3 on: December 01, 2016, 12:45:53 PM »
I just tested the DataReceived using the FINS Ethernet driver and it worked as expected. I'm now looking into the ComError

Code: [Select]
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        OmronEthernetFINSCom1.BeginRead("D0")
    End Sub

    Private Sub OmronEthernetFINSCom1_DataReceived(sender As Object, e As Drivers.Common.PlcComEventArgs) Handles OmronEthernetFINSCom1.DataReceived
        If e.ErrorId = 0 Then
            MsgBox(e.PlcAddress & " = " & e.Values(0))
        End If
    End Sub

aquilmustafa

  • Full Member
  • ***
  • Posts: 121
    • View Profile
Re: Omron Ethernet Fins Float value read
« Reply #4 on: December 01, 2016, 10:11:21 PM »
The Omron data tables do not natively support 32 bit values and the driver does not have any conversion functionality, so you would have to use code to combine and convert 2 integer values into a float. This is a code snippet of how you might go about it:
Code: [Select]
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim MyFloat As Single = IntsToFloat(OmronEthernetFINSCom1.Read("D0", 2))
    End Sub

    Private Function IntsToFloat(ByVal v() As String) As Single
        If v Is Nothing OrElse v.Count < 2 Then
            Return 0
        End If

        '* Convert to integers
        '* Strip off bits above 16 bit because they would be invalid
        Dim vi(1) As UInt16
        vi(0) = CInt(v(0)) And 65535
        vi(1) = CInt(v(1)) And 65535


        '* Extract the bytes
        Dim b(3) As Byte
        BitConverter.GetBytes(vi(0)).CopyTo(b, 0)
        BitConverter.GetBytes(vi(1)).CopyTo(b, 2)

        '* Convert the bytes to a single precision
        Dim Result As Single
        Result = BitConverter.ToSingle(b, 0)

        Return Result
    End Function

Can this logic be used with ModbusTCP protocol which is not a part of AHMI to read Floating Variables

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5320
    • View Profile
    • AdvancedHMI
Re: Omron Ethernet Fins Float value read
« Reply #5 on: December 01, 2016, 10:53:29 PM »
Can this logic be used with ModbusTCP protocol which is not a part of AHMI to read Floating Variables
ModbusTCP is a driver in AdvancedHMI and you can precede Modbus addresses with an F for floating point, such as F40001