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

MSFS MSFS SimConnect_AddToDataDefinition - Cannot use RPN to set LVar - SOLVED see last post

Messages
8
Country
ca-quebec
The SDK documentation states:

It is possible to get and/or set an RPN “L” variable through SimConnect using the SimConnect_AddToDataDefinition function, for example:
SimConnect_AddToDataDefinition(hSimConnect, DataDefinitionID, “L:VARIABLE_NAME”, “number”, SIMCONNECT_DATATYPE_FLOAT64);
Yet their example just presents what appears to be a default statement. If there’s RPN notation in there, I don’t see it.

I’m trying to set L:XMLVAR_ADF_Mode in the default Cessna 152 to a value (range is 0 to 3):

SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, “L:XMLVAR_ADF_Mode”, “number”, SIMCONNECT_DATATYPE_FLOAT64);

I can’t figure it out by reading the “explanations” on the RPN page how exactly I'm supposed to use reverse Polish notation.

This is initiated from a GUI radio button so I can understand what minimum commands are required to SET an Lvar. I'm not comparing values, I'm just setting a value.

I can set and toggle Events and SimVars just fine using SimConnect. Am I missing another statement to do the actual "set"?

Robert

C++ VS2022 solution uploaded here:
 
I have mostly completed a C# app .. missing things like the LVARs , I have pieced together and built and merged into the app a WASM module but don't have them talking yet. I need to figure out that piece.
I think it will work but moving to a new PC has slowed me down as I move everything over .. are there any examples C# working though the WASM module? IF I can get that working I'll have an app ready for beta soon.

I have worked out some "mysterious" ways to turn move the buttons and switches in various aircraft, mostly the A320 and C172 G1000. (and worked out a temporary system for controlling the camera.) thanks for the responses.

The first time I can "press" the LS button (from my app) will be a highlight of my life ... I can control the APPR AP1 A/THR etc. (in c#) but the LS eludes me
 
Last edited:
are there any examples C# working though the WASM module?
I think it will be useful for you to study these open source projects to implement everything you need.
 
The same author of that SimConnect WASM information just told me this !!!!!

Just to update this topic, for completeness, since SU12 SDK it’s now possible to use SimConnect to set or query L var values. Some details here:
https://docs.flightsimulator.com/html/Programming_Tools/SimConnect/API_Reference/Events_And_Data/SimConnect_AddToDataDefinition.htm#lvars 1

my life is complete! Tomorrow I'll try to program with it.... THANKS all

p.s. In gratitude I will post the source code for a C# app with explanations of every step for beginning MSFS programmers. (next week)
 
I confirm that since about a year, you can read and write LVars directly with SimConnect. Just add a "L:" in front of the Lvar name..
I did it for almost all LVars of FBW320 and it works like a charm.
However, what still requires a WASM bridge is if you want to send H: events. And this, I have not yet been able to make it work.
 
I confirm that since about a year, you can read and write LVars directly with SimConnect. Just add a "L:" in front of the Lvar name..
I did it for almost all LVars of FBW320 and it works like a charm.
However, what still requires a WASM bridge is if you want to send H: events. And this, I have not yet been able to make it work.
@jppa320 , would you mind sharing how to "read and write LVars directly with SimConnect"?

I have a User Interface InGamePanel set up that has 2 buttons which increment or decrement a "L:VARIABLE_NAME1":

1713556680971.png


"Counter Up" increases the var, and "Counter Dn" decreases it. This works fine - and here is the JS code for it:

Code:
this.m_MyValue = document.getElementById("MyValue");
        this.m_MyButtonUp = document.getElementById("MyButtonUp");
        this.m_MyButtonUp.onclick = () => {
            let MyCounter = SimVar.GetSimVarValue("L:VARIABLE_NAME1", "number");
            MyCounter = MyCounter + 1;
            SimVar.SetSimVarValue("L:VARIABLE_NAME1", "number", MyCounter);
            this.m_MyValue.innerHTML = `${MyCounter.toFixed(0)}`;
        };
        this.m_MyButtonDn = document.getElementById("MyButtonDn");
        this.m_MyButtonDn.onclick = () => {
            let MyCounter = SimVar.GetSimVarValue("L:VARIABLE_NAME1", "number");
            MyCounter = MyCounter - 1;
            SimVar.SetSimVarValue("L:VARIABLE_NAME1", "number", MyCounter);
            this.m_MyValue.innerHTML = `${MyCounter.toFixed(0)}`;
        };

Now, I would EXPECT that this LVAR is global, as SDK says, and, as per SDK, we'd be able to get to it via "SimConnect_AddToDataDefinition" call. So, I set everything up - as far as I can see - as per SDK documentation. Here is my code:
Code:
struct Def_LVAR
{
    double  LVAR = 0.f;
};

....
 // AS PER SDK:
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_LVAR, "L:VARIABLE_NAME1", "number", SIMCONNECT_DATATYPE_FLOAT64);

....
// REQUEST TO GET DATA ON SIMOBJECT SENT OUT EVERY FRAME:
                case EVENT_FRAME:
                    HRESULT hr;
                    hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_LVAR, DEF_LVAR, SIMCONNECT_SIMOBJECT_TYPE_USER, SIMCONNECT_PERIOD_ONCE);

....
// RECEIVING OBJECT DATA
        case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
        {
            SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;

            switch (pObjData->dwRequestID)
            {   
                case REQUEST_LVAR:
                {
                    Def_LVAR *LVAR = (Def_LVAR*)&pObjData->dwData; // <= pObjData is invalid!!!
                    break;
                }
However, when I debug and break into my SimConnect client code, my pObjData returns invalid. Am I doing this right? What am I missing? :confused:
 
@Misho Ha! I think I've found it:

 
@Misho Ha! I think I've found it:

Aha - thanks! However, this is almost verbatim like my code above, and I still can't get it to work. This is not my first rodeo, I've written hundreds of Add-Request-Set blocks without any problem. The L:VAR part just refuses to work.
 
Ok - an update - I got it to work. The code I posted above is essentially correct, but I bundled LVAR into a structure I used before and I KNOW it worked. So basically, instead of having a one-element struct:
Code:
struct Def_LVAR
{
    double  LVAR = 0.f;
};

I bundled it in:

Code:
struct Def_SimObject
{
    double  Latitude;
    double  Longitude;
    double  Altitude;
    double  Pitch;
    double  Bank;
    double  Heading;
    double WorldVelX;
    double WorldVelY;
    double WorldVelZ;
    double WorldAccX;
    double WorldAccY;
    double WorldAccZ;

    double  LVAR = 0.f; // <= LVAR!!
};
and, of course:
Code:
hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE LATITUDE",                "degrees");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE LONGITUDE",                "degrees");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE ALTITUDE",                "meters");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE PITCH DEGREES",            "degrees");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE BANK DEGREES",            "degrees");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "PLANE HEADING DEGREES TRUE",    "degrees");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "VELOCITY WORLD X",            "meter per second");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "VELOCITY WORLD Y",            "meter per second");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "VELOCITY WORLD Z",            "meter per second");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "ACCELERATION WORLD X",        "meter per second squared");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "ACCELERATION WORLD Y",        "meter per second squared");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "ACCELERATION WORLD Z",        "meter per second squared");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEF_SIMOBJECT, "L:VARIABLE_NAME1", "number", SIMCONNECT_DATATYPE_FLOAT64); <= LVAR!!

And now, as I change the simvar in JS on my in-game menu, this LVAR reflects the same change. Not sure what the problem was with the single-member struct approach I had before. I tried it with 2 LVAR members as well, and it didn't work either. Maybe I missed something, I'll revisit it later.

So basically, since these LVARS can only be SIMCONNECT_DATATYPE_FLOAT64 type, they have a limited use, but at least this takes care of the SimConnect menu functionality that was deprecated for MSFS2020, and allows us to build in-game panels that can control SimConnect client functionality, instead of relying on keyboard keys to trigger things.
 
Interesting. I've had problems in the past when assigning a value to a struct member, so much so that I simply don't do it any longer. I know it's supposed to be okay but tell that to Visual Studio when it throws its toys out of the document well.
 
Back
Top