• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Simconnect AI TRAFFIC STATE returning gibberish

Messages
8
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
 
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
 
Back
Top