AMETEK Lx Series II Programming Manual User Manual
Page 149
Programming Manual
Lx \ Ls Series II
145
Buffer(i) = StringToIEEEFloat(s, gl_bAsciiTransfer)
Next i
End If
End If
End Sub
The required data format conversion from IEEE floating point to single precision floating points is shown in
the next section.
6.9.2 VB6 Sample: Converting IEEE format trace data to floating point
Converting the received IEEE floating point format waveform data to a single precision floating
point value can be accomplished using the following sample routine:
Public Function StringToIEEEFloat(ByVal sData As String, ByVal bAsciiMode As Boolean) As
Single
'=============================================================
'bAsciiMode flag is used if data is received as 8 ascii chars
'representing Hex 0-9,A-F. If bAsciiMode flag is false, then
'data is process as 4 char representing a byte each. Ascii
'mode is needed for DCBS windows
'=============================================================
Dim i As Integer
Dim j As Integer
Dim iChar As Integer
Dim expo As Long
Dim mantisse As Long
Dim expo_val As Variant
Dim mant_f As Single
Dim c(3) As Long 'Must use 32 bit integers to allow for
'intermediate result of 24 bit shift
Dim sign As Boolean
'=============================================================
Const MANT_MAX = &H7FFFFF
Const EXPO_MAX = 2 ^ 126
'=============================================================
On Error GoTo FloatConvError
If bAsciiMode Then
'Retrieve ASC values from eight hex byte input data
sData = UCase(sData)
For i = 0 To 3
c(i) = 0
For j = 0 To 1
iChar = AscB(Mid$(sData, i * 2 + j + 1, 1)) - 48
If iChar > 9 Then iChar = iChar - 7
c(i) = c(i) * 16 * j + iChar
Next j
Next i
Else
'Retrieve ASC values from four byte input data
'Note: Don't use ASCB or ASCW functions as results will differ
'based on character sets, even on non DCBS Windows
'Retrieve ASC values from four byte input data
For i = 0 To 3
c(i) = Asc(Mid$(sData, i + 1, 1))
Next i
End If
'Get sign bit
sign = ((c(0) And &H80) = &H80)
'Get exponent value less sign bit
expo = (c(0) And &H7F) * 2
'Pick up exponent sign
If (c(1) And &H80) = &H80 Then expo = expo Or 1
'get data less exponent sign bit
c(1) = c(1) And &H7F
mantisse = c(1) * &H10000 + c(2) * &H100 + c(3)
mant_f = mantisse / MANT_MAX
'Process exponent
If (expo <> 0) And (expo <> &HFF) Then
expo = expo - 127
mant_f = mant_f + 1
expo_val = 2 ^ Abs(expo)