AdvancedHMI Software
General Category => Open Discussion => Topic started 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
-
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:
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
-
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..
-
I just tested the DataReceived using the FINS Ethernet driver and it worked as expected. I'm now looking into the ComError
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
-
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:
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
-
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