AdvancedHMI Software

General Category => Open Discussion => Topic started by: aquilmustafa on November 30, 2016, 08:37:45 AM

Title: Omron Ethernet Fins Float value read
Post by: aquilmustafa 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
Title: Re: Omron Ethernet Fins Float value read
Post by: Archie 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
Title: Re: Omron Ethernet Fins Float value read
Post by: aquilmustafa 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..
Title: Re: Omron Ethernet Fins Float value read
Post by: Archie 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
Title: Re: Omron Ethernet Fins Float value read
Post by: aquilmustafa 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
Title: Re: Omron Ethernet Fins Float value read
Post by: Archie 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