- Messages
- 26
- Country
In a follow-up to my earlier question, I have actually started building a new SimConnect library in C#. The code is available on GitHub under the Apache 2.0 license, which makes it free to use also for commercial purposes, but retains the copyright. Because this is 2021 I also claimed the Twitter handle @CsSimConnect and made a Facebook page for it, but more important is that "cssimconnect.org" is claimed and "blog.cssimconnect.org" sends you to "https://cssimconnect.wordpress.com" where I'll post development updates with examples of what I am trying to accomplish. The code compiles with the Prepar3D v4.5 and v5 SDK, as well as the v0.12.0 version of the MSFS SDK. It has three parts:
The library takes care of the rest. Using it looks like:
Feel free to use the GitHub Issues tab to suggest priorities, or make changes and send a PR.
Cheers,
Bert Laverman
- "CsSimConnectInterOp" is a small C++ DLL project that links the static SimConnect library and exposes a DLL interface C# can call.
- "CsSimConnect" is the class-library itself.
- "CsSimConnectUI" is a small demo UI that is used to drive development; I decide for a feature to show in there, then implement what is needed to get it to work.
- It connects to the simulator. Auto-connect (which will try regularly to connect or reconnect) is in the API but not there yet. There are "OnConnect" and "OnDisconnect" event handlers you can hook into.
- You can request and subscribe to the several System States.
- You can define ObjectData blocks containing integers, floats, and fixed-size strings and request the data once or subscribe to it.
- The actual calls to the SimConnect static library need an added layer of thread-safety, because the static library does not provide it. I currently have some locking in C# but intend to move those to the C++ layer.
- I use the "OnDisconnect" event in the library to simply clean out all request/event/definition/send ids, but this may need something a bit less drastic, maybe even auto-reregistration.
public class AircraftData{[DataDefinition("ATC TYPE", Type = DataType.String256)]public string Type { get; set; }[DataDefinition("ATC MODEL", Type = DataType.String256)]public string Model { get; set; }[DataDefinition("ATC ID", Type = DataType.String256)]public string Id { get; set; }[DataDefinition("ATC AIRLINE", Type = DataType.String256)]public string Airline { get; set; }[DataDefinition("ATC FLIGHT NUMBER", Type = DataType.String256)]public string FlightNumber { get; set; }[DataDefinition("TITLE", Type = DataType.String256)]public string Title { get; set; }[DataDefinition("NUMBER OF ENGINES", Units = "Number", Type = DataType.Int32)]public int NumberOfEngines { get; set; }[DataDefinition("ENGINE TYPE", Units = "Number", Type = DataType.Int32)]public int EngineType { get; set; }}
The library takes care of the rest. Using it looks like:
Or even:string aircraftTitle = DataManager.Instance.RequestData<AircraftData>().Get().Title;
Note the data stream version will also get a "Subscribe()" (no parameters) and a "GetEnumerator()" that will return an "IEnumerator", so you can use "foreach" on it, and probably even LINQ-style streaming.DataManager.Instance.RequestData<AircraftData>(ObjectDataPeriod.PerSecond, onlyWhenChanged: true)
.Subscribe((AircraftData data) => log.Info("[stream] Currently selected aircraft is '{0}'.", data.Title));
Feel free to use the GitHub Issues tab to suggest priorities, or make changes and send a PR.
Cheers,
Bert Laverman