Bucher100

EM3000

Sep 4th, 2021 (edited)
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.34 KB | None | 0 0
  1. Option Explicit On
  2. Option Strict On
  3.  
  4. Module EM3000
  5.     Sub Main()
  6.         Dim SingleStatus As sSimRad
  7.         Dim DataOK As Boolean = SingleStatus.ParseData(New Byte() {1, 2, 3, 4, 5, 6, 7, 8, 9, 0})
  8.     End Sub
  9.  
  10. End Module
  11.  
  12. Public Structure sSimRad
  13.     Public Enum eStatus As Byte
  14.         Normal = &H90
  15.         Reduced = &H91
  16.         Invalid = &HA0
  17.     End Enum
  18.     Public Status As eStatus
  19.     Public Header As Byte
  20.     Public Roll As Single
  21.     Public Pitch As Single
  22.     Public Heave As Int16
  23.     Public Heading As Single
  24.     ''' <summary>
  25.     ''' Extraxts values from binary motion data
  26.     ''' </summary>
  27.     ''' <param name="Data">EM3000 Binary data 10 bytes</param>
  28.     ''' <returns>True or False</returns>
  29.     Public Function ParseData(ByVal Data() As Byte) As Boolean
  30.         If Data.Length <> 10 Then
  31.             Return False
  32.         Else
  33.             Status = CType(Data(0), eStatus)
  34.             Header = Data(1)
  35.             Roll = CSng(BitConverter.ToInt16(New Byte() {Data(2), Data(3)}, 0) / 100)
  36.             Pitch = CSng(BitConverter.ToInt16(New Byte() {Data(4), Data(5)}, 0) / 100)
  37.             Heave = BitConverter.ToInt16(New Byte() {Data(6), Data(7)}, 0)
  38.             Heading = CSng(BitConverter.ToUInt16(New Byte() {Data(8), Data(9)}, 0) / 100)
  39.             Return True
  40.         End If
  41.     End Function
  42. End Structure
Add Comment
Please, Sign In to add comment