The SDK samples and documentation aren’t really geared towards teaching novice developers how to use the SimConnect DLL/SDK, rather they provide basics for understanding how it could be used and then leave the developer to investigate their own requirements further, using resources such as other examples of code and forums like this.
This thread is trying to shine some light on how you can use the SimConnect SDK to actually submit requests and receive/process responses. The output is a SimConnectHelper that you can use to submit SimVar requests to MSFS 2020 and request the results for you to use in your own applications.
The sample code provided is written in C#, feel free to port this to other languages.
This tutorial is designed to be read/used when referring to the code of the SimConnectHelper project, so we’re not simply copying/pasting huge swathes of code from GitHub into this forum. Snippets of code are provided throughout this tutorial, to provide some reference to the areas of code we’re talking about, to help you find/read the right section as we proceed.
The SimConnect DLL is a very simple interface; it expects your code to tell it exactly what you want it to do and how you want it done.
If you make a typo in your code, or FS isn’t running, or make any other mistake, SimConnect isn’t very forgiving, it simply fails. Nor is it very helpful in pointing you towards the cause of the failure, so you’re likely to spend a lot of time making mistakes and then refining and tweaking your code to fix it, via trial and error.
With the above in mind, I have created a simple helper project, to demonstrate how you could write your own code using SimConnect, or you can simply embed the SimConnectHelper into your own project to use what’s written.
At the time of writing, the project on GitHub allows you to:
- Connect to MSFS 2020 locally
- Connect to MSFS 2020 running on a remote PC
- Disconnect from MSFS 2020
- Submit a SimVar request
- Request an updated value
- Auto-receive latest values using a pre-defined schedule
- Submit a SimVar value to MSFS 2020
- Remove/cancel a previous request
- Disable AI Updates to prevent MSFS 2020 from changing the values you submit
** VERY IMPORTANT** the SimConnect.dll is 64-bit! If you’re planning on creating projects yourself, make sure your project is also configured to compile in 64-bit, otherwise, you will likely receive all manner of errors, not all of which are helpful. Also, if your project intends to use the SimConnect.dll directly, make sure you reference the SimConnect.dll in the right way. If you’re using a development IDE such as Visual Studio, the SimConnect.dll may not automatically copy to your compiled output folder, you may have to force it or do that manually.
The sample code also contains a small test project to demonstrate how the helper is used.
The main class
SimConnectHelper provides the actual code you can use in your own projects. It is littered with comments to help you understand what each part of the code is doing, which is particularly helpful for anyone wanting to port the code to another language or to provide guidance via IntelliSense when using it in your own projects.
I have also started creating another project to demonstrate how you can embed the helper into a form.
I plan to add more features to the helper in the future, but hopefully, this will help the budding developers out there get a head start in their coding.