Hi,
If you use VB.NET use the FSUIPC SDK and the .NET example.
Then add the following lines.
I'm sure it's cleaner way's to do it, but this was what I could come up with right now.
/Richard
'****Code *****
'40 byte structure:
_
Structure TCAS_DATA
Dim id As Integer
Dim lat As Single
Dim lon As Single
Dim alt As Single
Dim hdg As Short
Dim gs As Short
Dim vs As Short
_
Dim idATC() As Byte
Dim com1 As Short
End Structure
Sub Test_TCAS_DATA()
Dim dwResult As Integer
Dim Token As Integer
Dim result As Integer
Dim fsByte(4095) As Byte
Dim TCA(0) As TCAS_DATA
Dim T As System.Type
T = TCA(0).GetType
Try
If Connected Then
If FSUIPC_Read(&HF000, 4096, Token, dwResult) Then
If FSUIPC_Process(dwResult) Then
If FSUIPC_Get(Token, 4096, fsByte) Then
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim StrByte(39) As Byte
For i = 128 To 4095
StrByte(j) = fsByte(i)
j += 1
If j = 40 Then
ReDim Preserve TCA(TCA.Length)
TCA(TCA.Length - 1) = UnSafeByteArrayToStructure(StrByte, T)
Erase StrByte
ReDim StrByte(39)
j = 0
k += 1
If k = 96 Then Exit For 'we are finish with the loop
End If
Next
'To Test the name of the 5th record you can convert the byte to string like this
System.Text.Encoding.ASCII.GetString(TCA(5).idATC)
End If
End If
End If
End If
Catch ex As Exception
Debug.WriteLine("Error: " & ex.Message)
End Try
End Sub
'* help methodes for converting Byte to Structure:
Public Function UnSafeByteArrayToStructure(ByVal b() As Byte, ByVal t As Type) As ValueType
Dim p As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(b.Length)
Try
Runtime.InteropServices.Marshal.Copy(b, 0, p, b.Length)
Dim vt As ValueType = Runtime.InteropServices.Marshal.PtrToStructure(p, t)
Return vt
Finally
Runtime.InteropServices.Marshal.FreeHGlobal(p)
End Try
End Function
Public Function UnSafeStructureToByteArray(ByRef s As ValueType) As Byte()
Dim bc As Integer = Runtime.InteropServices.Marshal.SizeOf(s)
Dim p As IntPtr = Runtime.InteropServices.Marshal.AllocHGlobal(bc)
Try
Runtime.InteropServices.Marshal.StructureToPtr(s, p, False)
Dim b(bc - 1) As Byte
Dim i As Integer
For i = 0 To bc - 1
b(i) = Runtime.InteropServices.Marshal.ReadByte(p, i)
Next
Return b
Finally
Runtime.InteropServices.Marshal.FreeHGlobal(p)
End Try
End Function