Add on aircraft keep a lot of their state in local variables, the ones that start with L:. Standard simulation variables won't show you a custom autopilot mode or a study level switch. L:vars will.
For a long time you needed a WASM module to get at them. On an updated Microsoft Flight Simulator 2020 you don't. SimConnect accepts the L: name directly, from SDK 0.21.0 on.
A small tool for poking at them
Use the project file from the 2020 SimConnect starter.
using System.Globalization;
using System.Runtime.InteropServices;
using Microsoft.FlightSimulator.SimConnect;
if (args.Length == 0)
{
Console.WriteLine("Usage: lvar L:NAME [new value]");
return;
}
using var ready = new EventWaitHandle(false, EventResetMode.AutoReset);
using var sim = new SimConnect("LVar reader", IntPtr.Zero, 0, ready, 0);
var running = true;
sim.AddToDataDefinition(Id.Value, args[0], "number", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
sim.RegisterDataDefineStruct<Value>(Id.Value);
if (args.Length > 1)
{
var wanted = new Value { Number = double.Parse(args[1], CultureInfo.InvariantCulture) };
sim.SetDataOnSimObject(Id.Value, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_DATA_SET_FLAG.DEFAULT, wanted);
}
sim.OnRecvSimobjectData += (_, data) => Console.WriteLine($"{args[0]} = {((Value)data.dwData[0]).Number}");
sim.OnRecvException += (_, e) => Console.WriteLine($"SimConnect error {(SIMCONNECT_EXCEPTION)e.dwException}");
sim.OnRecvQuit += (_, _) => running = false;
sim.RequestDataOnSimObject(Id.Value, Id.Value, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, SIMCONNECT_DATA_REQUEST_FLAG.CHANGED, 0, 0, 0);
while (running)
{
if (ready.WaitOne(1000))
{
sim.ReceiveMessage();
}
}
enum Id { Value }
[StructLayout(LayoutKind.Sequential, Pack = 1)]
struct Value
{
public double Number;
}
