1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Simconnect AI TRAFFIC STATE returning gibberish

Discussion in 'Prepar3D' started by Zpelican, 14 Jan 2017.

  1. Zpelican

    Zpelican

    Joined:
    19 Apr 2016
    Messages:
    7
    Country:
    unitedstates
    Hello All,

    I've been trying to get this resolved for hours and can't seem to figure it out. I'm just trying to pull AI TRAFFIC STATE through vb.net. All the other data I retrieve is fine but the TRAFFIC STATE is giving me issues. The doco mentions it's a string var.. here are some snippets of code:
    My struct is defined as:

    'Structure holding AI aircraft data
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
    Structure Struct_AI_data
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    Public Title As String
    Public latitude As Double
    Public longitude As Double
    Public altitude As Double
    Public velocity As Double
    Public hdg_true As Double
    Public hdg_mag As Double
    Public magvar As Double
    Public traffic_state As String
    End Structure
    Public AI_AIRCRAFT As Struct_AI_data

    'Data structure to retrieve AI Aircraft data
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "Title", "", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.STRING256, 0, 0)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "Plane Latitude", "degrees", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 1)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "Plane Longitude", "degrees", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 2)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "Plane Altitude", "feet", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 3)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "Ground Velocity", "knots", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 4)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "PLANE HEADING DEGREES TRUE", "radians", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 5)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "PLANE HEADING DEGREES MAGNETIC", "radians", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 6)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "MAGVAR", "degrees", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.FLOAT64, 0, 7)
    p3d_simconnect.AddToDataDefinition(StructDefinitions.Struct_AI_data, "AI TRAFFIC STATE", "", LockheedMartin.Prepar3D.SimConnect.SIMCONNECT_DATATYPE.STRING32, 0, 8)


    When I step through the code and view the contents of the result, traffic_state contains:

    "ÿ‹È‹ÖèÝW:ÿ‹Ð¹ |UtèÁA:ÿéOfÜÿèïA:ÿÌÌÌO;}ðËgÜÿƒÈÿeô[^_]Â"

    On the next iteration receive.message() I get an AccessViolationError

    If I comment out the AI TRAFFIC STATE everything works fine. I've tried to use datatype String256 as well, same result. I'm not running any traffic addons, just standard p3dv2.5

    I'm guessing I'm not defining it correctly? Another option is that because I'm requesting object=Aircraft , the first one to be passed is the USER aircraft which may be what's causing issues...
    Any help would be greatly appreciated.
    Thanks, Marc

    below is the watch window:

    error.jpg
     
  2. Zpelican

    Zpelican

    Joined:
    19 Apr 2016
    Messages:
    7
    Country:
    unitedstates
    Hello Again,

    Well I figured it out - so I'm posting the fix for anyone that may run into the same problem. The problem lies in the definition of the structure, more specifically I forgot to add the section in bold (since traffic_state is a string):

    'Structure holding AI aircraft data
    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)> _
    Structure Struct_AI_data
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    Public Title As String
    Public latitude As Double
    Public longitude As Double
    Public altitude As Double
    Public velocity As Double
    Public hdg_true As Double
    Public hdg_mag As Double
    Public magvar As Double
    <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=256)> _
    Public traffic_state As String
    End Structure


    Everyone have a great night, I'm going to bed. Now the programming world makes sense again...

    Cheers,
    Marc
     

Share This Page