- Messages
- 8
- Country
Hi,
I'm desperately trying to get airport information from MSFS using the relatively new SimConnect_AddToFacilityDefinition function.
Sending the request and receiving some kind of data is working fine. However, I'm not able to get more than a single int.
I've made a bare-minimum example for VS2022 in .NET 6 for you to test it yourself easily: https://github.com/Clamb94/SimconnectAirportDataTest
It's obviously very simple. It opens the SimConnect connection and checks every 500ms for a new message.
Once it get's the OSimConnect_OnRecvOpen message, it request the latitude and number of runways in Frankfurt.
Shortly thereafter, I'll receive a response on OSimConnect_OnRecvFacilityData(SimConnect sender, SIMCONNECT_RECV_FACILITY_DATA data).
Now comes the problem: I can't make anything useful out of the data member.
When I'm only requesting a single INT32, like "N_RUNWAYS", the data.Data[0] variable holds a value of 4, which is correct for Frankfurt.
When I'm only requesting a single FLOAT64, like "LATITUDE", the data.Data[0] variable holds an UInt32 with value 1550843904, which doesn't make any sense to me.
I tried casting it to an double, but this throws an exception:
Obviously, I'm also not able to request more than one value at a time and get a useful response.
I tried casting it to a struct like this, but this also throws a System.InvalidCastExcpetion.
(That's the version on GitHub)
There is an example C++ included in the SDK samples called FacilityDataDefinition, they also cast the reply in a struct.
But I can't seem to replicate the C++ code in C#.
Any ideas how to solve this?
Thanks
Best regards
Axel
I'm desperately trying to get airport information from MSFS using the relatively new SimConnect_AddToFacilityDefinition function.
Sending the request and receiving some kind of data is working fine. However, I'm not able to get more than a single int.
I've made a bare-minimum example for VS2022 in .NET 6 for you to test it yourself easily: https://github.com/Clamb94/SimconnectAirportDataTest
It's obviously very simple. It opens the SimConnect connection and checks every 500ms for a new message.
Once it get's the OSimConnect_OnRecvOpen message, it request the latitude and number of runways in Frankfurt.
C#:
OSimConnect.AddToFacilityDefinition(sd, "OPEN AIRPORT");
OSimConnect.AddToFacilityDefinition(sd, "LATITUDE");
OSimConnect.AddToFacilityDefinition(sd, "N_RUNWAYS");
OSimConnect.AddToFacilityDefinition(sd, "CLOSE AIRPORT");
OSimConnect.RequestFacilityData(sd, rd, "EDDF", "");
Shortly thereafter, I'll receive a response on OSimConnect_OnRecvFacilityData(SimConnect sender, SIMCONNECT_RECV_FACILITY_DATA data).
Now comes the problem: I can't make anything useful out of the data member.
When I'm only requesting a single INT32, like "N_RUNWAYS", the data.Data[0] variable holds a value of 4, which is correct for Frankfurt.
When I'm only requesting a single FLOAT64, like "LATITUDE", the data.Data[0] variable holds an UInt32 with value 1550843904, which doesn't make any sense to me.
I tried casting it to an double, but this throws an exception:
Code:
double lat = (double)data.Data[0];
throws:
{"Unable to cast object of type 'System.UInt32' to type 'System.Double'."} System.Exception {System.InvalidCastException}
Obviously, I'm also not able to request more than one value at a time and get a useful response.
I tried casting it to a struct like this, but this also throws a System.InvalidCastExcpetion.
(That's the version on GitHub)
C#:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct airport
{
public double latitude;
public int nRunways;
};
airport a = (airport)data.Data[0];
Console.WriteLine($"Lat: {a.latitude}; Rwys: {a.nRunways}");
There is an example C++ included in the SDK samples called FacilityDataDefinition, they also cast the reply in a struct.
But I can't seem to replicate the C++ code in C#.
Any ideas how to solve this?
Thanks
Best regards
Axel