I in 485 read the meter back to numerical 68 73 40 B9 (hexadecimal)
Shown on the actual flow meter is 5.794, how do the above the hexadecimal conversion for
Normal use of decimal
The output format is provided by the manufacturer for information to 32 bits floating point number
Is the hexadecimal 32-bit floating point Numbers, converted to decimal to read
To solve the
CodePudding user response:
Give you a simple example, the actual use also need to improve themselves,
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any Source, As Any, ByVal Length As Long)
The Public Function StrToSng (ByVal Data As String) As Single
Dim R (3) As Byte
On Error GoTo hErr
Data=https://bbs.csdn.net/topics/Replace (Data, ""," ")
StrToSng=0
R (0)=CByte (" & amp; H "& amp; Mid (Data, 3, 2))
R (1)=CByte (" & amp; H "& amp; Mid (Data, 1, 2))
R & amp; (2)=CByte (" H "& amp; Mid (Data, 7, 2))
R & amp; (3)=CByte (" H "& amp; Mid (Data, 5, 2))
CopyMemory StrToSng, R (0), LenB (StrToSng)
HErr:
End the Function
Usage:
The Debug. Print StrToSng (" 687340 b9 ")
5.794