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

New Managed Class-Library started: CsSimConnect

Messages
26
Country
netherlands
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:
  • "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.
Current state:
  • 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.
Major refactorings needed:
  • 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.
Data definition works using "Attributes", so you don't call "AddToDataDefinition" yourself, but provide a class looking like this:
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:
string aircraftTitle = DataManager.Instance.RequestData<AircraftData>().Get().Title;
Or even:
DataManager.Instance.RequestData<AircraftData>(ObjectDataPeriod.PerSecond, onlyWhenChanged: true)
.Subscribe((AircraftData data) => log.Info("[stream] Currently selected aircraft is '{0}'.", data.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.

Feel free to use the GitHub Issues tab to suggest priorities, or make changes and send a PR.

Cheers,
Bert Laverman
 
Back
Top