Started a new SimConnect library for C#

Post Reply
bertlaverman
Posts: 13
Joined: Fri Aug 07, 2015 9:10 am

Started a new SimConnect library for C#

Post by bertlaverman »

I haven't announced this here yet, so here goes:

I have started a new Managed library for SimConnect in C#, called CsSimConnect. This library will allow you to connect to Prepar3D or MSFS, using the static SimConnect library as a layer in between. The code is up on GitHub, as Open Source using the Apache 2.0 license. This means it is copyrighted but free to use, even in commercial applications. To build it you'll need the appropriate SDKs installed.

My goal with this library is to use modern programming practices such as C# Attributes and Reactive design patterns. Dispatching of messages is no longer your explicit duty and you'll only get the data you asked for. For example, if I want to define a set of fields to retrieve information on the user's aircraft, I can use:

Code: Select all

public class AircraftData
{
  [DataDefinition("ATC TYPE", Type = DataType.StringV, Size = 30)]
  public string Type { get; set; }

  [DataDefinition("ATC MODEL", Type = DataType.StringV, Size = 10)]
  public string Model { get; set; }

  [DataDefinition("ATC ID", Type = DataType.StringV, Size = 10)]
  public string Id { get; set; }

  [DataDefinition("ATC AIRLINE", Type = DataType.StringV, Size = 10)]
  public string Airline { get; set; }

  [DataDefinition("ATC FLIGHT NUMBER", Type = DataType.StringV, Size = 6)]
  public string FlightNumber { get; set; }

  [DataDefinition("TITLE", Type = DataType.StringV, Size = 256)]
  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; }
}
Then when you want to use it somewhere once, you can use:

Code: Select all

AircraftData data = DataManager.Instance.RequestData<AircraftData>().Get();
log.Info("Currently selected aircraft is '{0}'.", data.Title);
Or, if you want to updates, you could do:

Code: Select all

DataManager.Instance.RequestData<AircraftData>(ObjectDataPeriod.PerSecond, onlyWhenChanged: true)
                    .Subscribe((AircraftData data) => log.Info("[stream] Currently selected aircraft is '{0}'.", data.Title));
You can help me or register issues on GitHub, or read my new Blog site at blog.cssimconnect.org.

NOTE Just in case the "I have started" isn't clear: It is not finished. The demo app included can only connect, show paused/stopped state, and log the chosen aircraft. It will be complete. If you think I'm going to slow, how about giving me a hand, file a PR, or help prioritize work by creating stories.
Bert Laverman
Post Reply