I see where the problem is, but not completely sure how to fix it since I do not have a PLC to test the code, so try this code:
If rawData.Count >= (startByte + ResultingValuesIndex * BytesPerElement + BytesPerElement) Then
For i = 0 To BytesPerElement - 1
If address.Address.IndexOf("F4", 0, System.StringComparison.InvariantCultureIgnoreCase) < 0 AndAlso _
address.Address.IndexOf("L4", 0, System.StringComparison.InvariantCultureIgnoreCase) < 0 Then
'* Use Big Endian
Result += CInt(rawData(startByte + ResultingValuesIndex * BytesPerElement + i) * (2 ^ ((BytesPerElement - 1 - i) * 8)))
Else
'* Reverse the data into little endian so the .NET libaries can convert it to float
FloatBytes(i) = rawData(startByte + ResultingValuesIndex * BytesPerElement + i)
End If
Next
If address.Address.IndexOf("F4", 0, System.StringComparison.InvariantCultureIgnoreCase) >= 0 Then
'* F4 address designates it is a floating point type
SwapBytes(FloatBytes, 0)
SwapBytes(FloatBytes, 2)
ResultingValues(ResultingValuesIndex) = CStr(BitConverter.ToSingle(FloatBytes, 0))
ElseIf address.Address.IndexOf("F4", 0, System.StringComparison.InvariantCultureIgnoreCase) >= 0 Then
'* Convert bytes to a long integer
SwapBytes(FloatBytes, 0)
SwapBytes(FloatBytes, 2)
ResultingValues(ResultingValuesIndex) = CStr(BitConverter.ToInt32(FloatBytes, 0))
Else
ResultingValues(ResultingValuesIndex) = CStr(Result)
End If
End If