• 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.

MSFS20 Issue requesting runway data using facility methods

Messages
10
Country
chile
Hi!

I've been able to get information from the airport with my C# program using AddTofacilityDefinition with no problems, but i'm now trying to get runway data and i'm having some issues. I'm just trying to get the runway heading for testing.


I'm using the following definitions to get the data:

C#:
_simConnection.AddToFacilityDefinition(DefineID, "OPEN AIRPORT");_simConnection.AddToFacilityDefinition(DefineID, "OPEN RUNWAY");


_simConnection.AddToFacilityDefinition(DefineID, "HEADING");


_simConnection.AddToFacilityDefinition(DefineID, "CLOSE RUNWAY");
_simConnection.AddToFacilityDefinition(DefineID, "CLOSE AIRPORT");


_simConnection.RegisterFacilityDataDefineStruct<runway>(SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY);
_simConnection.RequestFacilityData(DefineID, RequestID, "SCEL", "");
Then to get the data i use:

C#:
private void simconnect_Facility_OnRecvFacilityData(SimConnect sender, SIMCONNECT_RECV_FACILITY_DATA data)
{
    try
    {
       runway a = (runway)data.Data[0];
    }
    catch (Exception ex)
    {
       VoiceAttackPlugin.LogErrorOutput("OnRecvFacilityData problem with RUNWAY type. " + ex, "red");
    }
}

The struct for runway data is the following:

C#:
struct runway
    {
        public System.Single heading1;    //(using "float" instead results in the same problem)
    }

This exact same method worked flawlessly when trying to get airport data, but with runway data it throws a cast exception ocurring inside OnRecvFacilityData before spitting out two correct heading values (in an airport that has 4 runways).

I'm not sure what am i doing wrong, it sounds to me like there's something wrong with the formatting of the output data. I've tried lots of stuff without better results.

Any ideas?

Thanks!
 
I would check that data.Type == SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY before casting to runway.
Otherwise, it looks ok.
Regards,
Javier.
 
In the case of requesting airport data i have to use SIMCONNECT_FACILITY_DATA_TYPE.AIRPORT, but if i use that one when requesting runway airport it throws a cast exception and spits out some nonsense values. At least using SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY it spits out some correct numbers, but a cast exception nontheless.
I'm not sure what else to check about it since it is just an enum...

1688755907761.png
 
As this is MSFS, you may wish to consider the probability that SimConnect is still not yet fully implemented within the sim despite what the SDK documentation says (they'll get round to it one day...). Can you trap the cast exception and simply ignore it?
 
As this is MSFS, you may wish to consider the probability that SimConnect is still not yet fully implemented within the sim despite what the SDK documentation says (they'll get round to it one day...). Can you trap the cast exception and simply ignore it?
It wouldn't bother me if not because it is not giving me the whole data. The airport has 4 runways and it is giving me only two headings.
You are possibly right, I just wanted to make sure that this is as best as it gets before assuming it is just because SimConnect unfinished development.
 
The airport has 4 runways and it is giving me only two headings.
Right. The other two are +180º mod 360º as in any other airport.
Anyway, with your AddToFacilityDefinition, your OnRecvFacilityData will be called also with data.Type SIMCONNECT_FACILITY_DATA_TYPE.AIRPORT, so check that data.Type before casting to prevent cast exceptions.
Regards,
Javier.
 
Right. The other two are +180º mod 360º as in any other airport.
Anyway, with your AddToFacilityDefinition, your OnRecvFacilityData will be called also with data.Type SIMCONNECT_FACILITY_DATA_TYPE.AIRPORT, so check that data.Type before casting to prevent cast exceptions.
Regards,
Javier.
I added
Code:
data.Type = 1;
before
Code:
runway a = (runway)data.Data[0];
which i believe changes the data type to the runway data type. As you told me, i'm sure that was something necessary. The problem is that i'm still getting a cast error. Could it be about the member type or number in my "runway" struct? i tried with more than 1 member without success...
According to the documentation:
DataBuffer of data. Have to cast it to a struct which matches the definition.
But what's the definition? doesn't tell.

Cheers!
 
I added
Code:
data.Type = 1;
before
Code:
runway a = (runway)data.Data[0];
which i believe changes the data type to the runway data type.
As far as I know, you cannot change the data.Type you are getting ;)
Instead of, try something like:

C#:
            SIMCONNECT_FACILITY_DATA_TYPE t = (SIMCONNECT_FACILITY_DATA_TYPE)data.Type;
            switch (t)
            {
                case SIMCONNECT_FACILITY_DATA_TYPE.AIRPORT:
// Nothing to do here
                    break;
                case SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY:
// Your cast runway a = (runway)data.Data[0];
                    break;
            }

According to the documentation:
DataBuffer of data. Have to cast it to a struct which matches the definition.
But what's the definition? doesn't tell.
Well, because it is your own definition (see your code in your first message)...
By the way, I have heading as float in my Runway struct and it works flawlessly.
Regards,
Javier.
 
As far as I know, you cannot change the data.Type you are getting ;)
Instead of, try something like:

C#:
            SIMCONNECT_FACILITY_DATA_TYPE t = (SIMCONNECT_FACILITY_DATA_TYPE)data.Type;
            switch (t)
            {
                case SIMCONNECT_FACILITY_DATA_TYPE.AIRPORT:
// Nothing to do here
                    break;
                case SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY:
// Your cast runway a = (runway)data.Data[0];
                    break;
            }


Well, because it is your own definition (see your code in your first message)...
By the way, I have heading as float in my Runway struct and it works flawlessly.
Regards,
Javier.
Thank you for your suggestion.
I tried this but with try/catch inside each case and the exception now shows up as related to the AIRPORT type instead RUNWAY. Just after that happening, the code spits out RUNWAY values too.
Not sure how to interpret this. At the OnRecvOpen function i request the data exclusively in a RUNWAY format using this:
C#:
_simConnection.RegisterFacilityDataDefineStruct<runway>(SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY);
I don't get why there would be airport data trying to get output even though i exclusively asked for runway data, not both.
 
Just after that happening, the code spits out RUNWAY values too.
That's correct. RUNWAY is a child of AIRPORT.

At the OnRecvOpen function i request the data exclusively in a RUNWAY format using this:
C#:
_simConnection.RegisterFacilityDataDefineStruct<runway>(SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY);
I don't get why there would be airport data trying to get output even though i exclusively asked for runway data, not both.
Actually, you are requesting the data with RequestFacilityData.
With RegisterFacilityDataDefineStruct you are binding a type to an id. So if you receive that id, the object you received can be casted to the type you gave.

I don't get why there would be airport data trying to get output even though i exclusively asked for runway data, not both.
Because AIRPORT is the parent of RUNWAY.
Look at the example here:
https://docs.flightsimulator.com/ht...lities/SimConnect_AddToFacilityDefinition.htm
Regards,
Javier.
 
Ok thank you, now i tried exactly like this with nothing in the airport case and there's no cast exception anymore

C#:
SIMCONNECT_FACILITY_DATA_TYPE t = (SIMCONNECT_FACILITY_DATA_TYPE)data.Type;
            switch (t)
            {
                case SIMCONNECT_FACILITY_DATA_TYPE.AIRPORT:
// Nothing to do here
                    break;
                case SIMCONNECT_FACILITY_DATA_TYPE.RUNWAY:
// Your cast runway a = (runway)data.Data[0];
                    break;
            }

Now i see it is necessary to give the code the way to cast "nothing" in the parent type while also casting in the type you need the data from.

My only question now is: why is it giving me only two runways in a 4 runway airport? The documentation says it should receive one message per runway.
I can manage myself to calculate data from the other 2 missing runways, but it would make it more easy to have that info directly...

Would it be a SimConnect issue, or an issue in my coding?
 
My only question now is: why is it giving me only two runways in a 4 runway airport? The documentation says it should receive one message per runway.
I can manage myself to calculate data from the other 2 missing runways, but it would make it more easy to have that info directly...
Because you have a different definition of "runway" :)
Actually, the RUNWAY struct has data for both ends of the runway.
Regards,
Javier.
 
Back
Top