public static async Task Run() { using (var sc = new SimConnectWrapper("XTouchMiniBridge")) { sc.SimConnectOpen += Sc_SimConnectOpen; sc.SimConnectClose += Sc_SimConnectClose; if (await sc.TryConnect()) { Console.WriteLine("Close with empty enter ..."); while (Console.ReadLine() != "") { try { double data = await sc.RequestObjectByType <double>(SimDataDefinitions.PlaneHeadingDegreesMagnetic); Console.WriteLine($"[Data Received] {data} {SimDataDefinitions.PlaneHeadingDegreesMagnetic.UnitName}"); } catch (Exception ex) { Console.WriteLine($"[Data Error] {ex}"); } } } else { Console.WriteLine("Couldn't connect to SimConnect!"); } } Console.WriteLine("Close with enter 2 ..."); Console.ReadLine(); }
public static async Task Run() { using (var simConnect = new SimConnectWrapper("MsfsModuleTests")) { Console.WriteLine("Connecting to SimConnect ..."); if (!await simConnect.TryConnect()) { Console.WriteLine("SimConnect connection failed. Exiting ..."); return; } int x = 0; var client = MsfsModuleClient.CreateFor(simConnect); while (Console.ReadLine() != "stop") { if (x++ % 2 == 0) { Console.WriteLine("Reading LVar WT_CJ4_HDG_ON ..."); try { double result = await client.ReadLVar("WT_CJ4_HDG_ON"); Console.WriteLine($"Response: {result}"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } else { Console.WriteLine("Firing HEvent WT_CJ4_AP_HDG_PRESSED ..."); await client.FireHEvent("WT_CJ4_AP_HDG_PRESSED"); } } Console.WriteLine("stop typed, exiting ..."); return; } }