Getting aircraft position

I’m a .Net developer, and a enjoy flight sim. So wouldn’t mind learning if I can get events and data from the sim. I’ve decided as a baby test - if I can get data about the aircraft into a console app. Would I use the SDK to poll (?) for aircraft position, with GPS coordinates, altitude. Maybe speed? Flaps, Gear position? Thinks like that?

Would there be a nugget package or something? Seeking some form of basic tutorial on .Net development with regards flight sim.

Download the MSFS SDK. Look at the SimConnect SDK. If you are using Visual Studio, you will use the SimConnectSDK/lib/managed. Most helpful: see sdk\Samples\SimvarWatcher.

If you are a C# programmer, it has all you need. PS: I wrote GTFP from this example.

If you go to my website, you can download (at the bottom of the page) which contains SimConnectLib.sln, which is a VS/C# solution that can get you started.

Good luck; have fun.

1 Like

That looks really helpful! The solution on your site - is that a demo of how to get things working? I’m not experienced with SDKs. I was hoping there was some nuget package. I’ll look at your demo. Thanks for that!

Trying to include the SimConnect.dll…

But when running, getting an exception:

Message=Could not load file or assembly ‘Microsoft.FlightSimulator.SimConnect.dll’ or one of its dependencies. The specified module could not be found.

I’ve seen other people get it, but the fil;e is in the debug folder, my console app is set to x64 (Tried x32 - same issue). Not sure why I’m seeing this.

I don’t seem to see that sample folder in my SDK folder.

You need two DLL’s:
…\sdk\SimConnect SDK\lib\SimConnect.dll and
…\sdk\SimConnect SDK\lib\managed\Microsoft.FlightSimulator.SimConnect.dll

Both of these should be in the Dependencies folder (if you are building a wpf/.NetCore app, or in the References folder otherwise). You might just as well build the former type of app. rather than the latter, since it seems to be what MS recommends these days.

The solution on my site is just a library, not a complete application. You need to build the code that calls simConnect.requestPosition() . My app calls this in a timer (every .5 sec). Despite advice to the contrary, for my purposes, this is better than triggering an event every time SimConnect has data it wants to be consumed.

Thanks. Yeah, prefer .Net Core. I made a Framework 4.7.2 and managed to get it to build, but no events. I’ll get your solution and try. I did attempt earlier but got an error. Couldn’t build as ‘window’ was unknown. Any idea what might be the issue there? I’ll try again and supply more detail. I simply downloaded, and built.

Presentation Framework seems to have an issue. Not sure what that is.

I put a complete demo app. on my website

Open folder …\simConnectDemo\SimConnectDemo

Run the simConnectDemo.sln solution in VS.
Rebuild the solution.
Start the app.
Startup MSFS;
click the “connectToSim” button in the app.

If you single step the debugger you can see what the logic is doing.

Just did that. Same error… It seems to have an issue with your reference to Presentation.

I downloaded.
Opened SLN file…
Started the demo project.

Fails to build. ‘Window’ is unknown. And I see there is a dependency issue.

I added PresentationFramework nuget package, and it works. Maybe add it as a nuget to your project?

I notice when parked on the ground, speed is retuned as knots. And I am stationary. Is this perhaps airspeed, and showing wind as 5kts into me?

Cannot explain speed when you are parked.

Are you running VS 2019 with latest patches? I don’t have a Nuget reference in my build. Here is my “about” information:

Microsoft Visual Studio Community 2019
Version 16.11.1
Microsoft .NET Framework
Version 4.8.04084
Installed Version: Community
.NET Portability Analyzer 1.1.10808.0
C# Tools 3.11.0-4.21403.6+ae1fff344d46976624e68ae17164e0607ab68b10

In the VS Installer: pick “.NET desktop development”

mmm… I may not have desktop development installed. So maybe the nugget addition for me was OK. I have VS2019 but us Rider as my IDE. I’m about to install VS2022 preview. I’ll see how I got there too.

My plan is to have either a windows service, or a console app reading the data - as your demo app does.

My concern is, I might not have this in a console app.

winSource = PresentationSource.FromVisual(this) as HwndSource;
winSource.AddHook(WndProc);  //message handler for msg from SimConnect
windowHandle = winSource.Handle;

So that means, this would not work:


I assume you need to pass the parent handle to the wrapper, which then passes it to SimConnect (for some reason). Can this be done with a console app - which I am not sure, has any form of windowHandle.