SimConnect and WASM LVAR C++ example

Hello pilots,

I’d like to write a C++ app that can read some LVARs using SimConnect (and WASM). I need to find a simple project shown how to to do this in C++.

A C++ sample showing how to access and read/write different types of LVARs would be greatly appreciated!

Thanks a lot,
Mathis

Hi Mathis,

More specifically, what are you wanting to do? Are you writing a WASM module (runs in the sim) or an external application? I’m asking because a) one doesn’t need SimConnect to read/write L vars from a WASM module (there are native API functions for that), and b) one can read/write L vars with an external SimConnect client (not running as WASM module). While you could do both (use SimConnect inside WASM) that wouldn’t really make sense for just working with variables.

Cheers,
-Max

Hello,

I want to make a C++ application can access to LVAR (read and write).

Cheers
Mathis

The samples you are looking for are here:

Read Variables:
\MSFS 2024 SDK\Samples\VisualStudio\SimConnectSamples\RequestData

Write Variables:
\MSFS 2024 SDK\Samples\VisualStudio\SimConnectSamples\SetData

LVars are not different, just prefix L: to their name:

hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "Plane Altitude", "feet");
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_2, "L:MyVariable", "number");

First one doesn’t need an A: in front, because in Simconnect A: is default, and refers to the SimObject own simulation variables.

The second line defines an L: Variable, so L: is required here and refers to L: variables, which are instead Global.

1 Like

Thanks for your reply.
I’ve read it is not possible to read LVAR from EXE. It is not real ?

It used to be not possible, but the ability to do so has been added in MSFS 2020 Sim Update 12, released in March 2023.

1 Like

The sample RequestData does not compile at all. The gauge include is missing. But when I activate the gauge include, it requests a file named « alltypes.h ». And I’ve no successes to compil :hushed_face:

Can you compil it ?

Thanks for your help !!!

I haven’t tried the samples in a while, so I cannot confirm if they still work, but that might be a problem of the sample themselves.

But I can assure you IT IS possible to read and write LVars through Simconnect by simply adding an L: in front of their name, that’s it. The method itself is not any different than reading/writing a standard SimVar so, if you are able use them in your Simconnect app, just adding an L: to the data definition for an LVar will work same as before.

Thanks, just to be sure, can I read Fenix A320 LVAR from an EXE without using a WASM module to “speak” with my EXE and Fenix LVAR? Did you confirm?

Yes, yes, yes! As I’ve said in my previous post:

  • It used to be not possible to read/write LVars from Simconnect (.EXE or .WASM doesn’t matter). To do this before SU12, you had to call the legacy Gauges API (not Simconnect), which was ONLY accessible in a WASM model.

  • MSFS 2020 SU12 added the ability to specify an LVar by simply adding “L:” to its name in a normal Simconnect data Definition, same as normal A: SimVars (A: don’t use the A: prefix, L: do.

  • Once you can use the variable with Simconnect, WASM or EXE doesn’t matter anymore.

In theory, all those WASM modules that don’t do anything other than being servers for other .EXE using the Simconnect Client data areas and commands to call into the Gauges API and give access to LVars, are technically useless now because, before SU12, you had to do this:

Before SU12

Your .EXE → Simconnect Client data areas → WASM module → Gauges API → MSFS

After SU12

Your .EXE → Simconnect L: vars → MSFS

Does it mean WASM modules that acts are bridge for LVars are completely useless today ? Not entirely. While they are no longer required to read/write LVars, they are still required for one crucial function in the Gauges API, which is:

execute_calculator_code()

Which executes an RPN expression like this:

“(L:MyVariable, number)”

If you want to execute RPN code programmatically, you STILL need a WASM module.

Note that, using RPN “just” to set or read LVariable is less efficient than using Simconnect, because the expression needs to be parsed or eventually cached, so if you “just” want to read/write a variable, executing RPN is not the best solution.

Also, with Simconnect you can read and write more than one variable at once with a SINGLE call, so if you need to do that, it’s way more efficient through Simconnect.

But of course, if your application is data driven, as in “user configurable”, meaning users might need to supply a custom XML expression to do something (like user-configurable custom hardware support, for example), execute_calculator_code is still very useful, and might be the only reason to keep having a WASM module.

1 Like

Hello everyone, I’d like to express my gratitude. After enduring a long and challenging set of tests, I’ve successfully read LVAR from a simple EXE without using a gauge. It’s working very well, although I’ll need some time to fully understand it.

I have one more question: how can I determine when:

  • FS starts a new flight

  • FS is in pause

  • FS quits a flight?

Apart from the challenge, I’ll also need to find the GSX Pro LVAR and have the documentation. :thinking:

Cheers and large thanks,

Mathis

Am i correct in understanding that using the WASM Gauges API is the only way to handle any SimVar with two indexes?

With the basic SimConnect_AddToDataDefinition as far as i can tell, there is no way to add the second ID for something like “WEAR AND TEAR LEVEL:39” , where that would return the first engine, but a second component ID is needed to get Engine 2,3,4 etc.

OT, but this didn’t work after all?
https://devsupport.flightsimulator.com/t/simconnect-with-simvar-component-id-component-index/13777/4

it ended up being a false positive - I had one instance of it working (or so I thought), circled back to it a few weeks later to implement it and no luck. Tried a ton of combinations of formatting, C++ and C# .. no luck. The documentation only gives a RPN example .