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

Fuel-air ratio does not set

DragonflightDesign

Resource contributor
Messages
1,355
Country
northernireland
Yet another complete failure on my part. I'm trying to set the fuel-air ratio on a reciprocating engine. Both the FSX and P3D SDK state that this can only be set through a simconnect action. I'm not interested in finding out what it currently is; I just want to set the ratio, so no REQUEST in the enumerations.

Global variables:
Code:
double recip_engine = 0;            // The engine to be set (1 - 4)
double fuelair_ratio = 0;            // The ratio to be set (whatever)
double set_fuelair_ratio = 0;    // Tell simconnect to do the work ( = 1)
Enumeration for the engine:
Code:
    DEFINE_FUELAIR_RATIO_ENG1,
    DEFINE_FUELAIR_RATIO_ENG2,
    DEFINE_FUELAIR_RATIO_ENG3,
    DEFINE_FUELAIR_RATIO_ENG4
Data definitions for the four engines:
Code:
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUELAIR_RATIO_ENG1, "RECIP MIXTURE RATIO:1", "ratio", SIMCONNECT_DATATYPE_FLOAT64);
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUELAIR_RATIO_ENG2, "RECIP MIXTURE RATIO:2", "ratio", SIMCONNECT_DATATYPE_FLOAT64);
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUELAIR_RATIO_ENG3, "RECIP MIXTURE RATIO:3", "ratio", SIMCONNECT_DATATYPE_FLOAT64);
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINE_FUELAIR_RATIO_ENG4, "RECIP MIXTURE RATIO:4", "ratio", SIMCONNECT_DATATYPE_FLOAT64);
The event call:
Code:
    case CLIENT_6HZ:
    {
        // Fuel-air ratio set
        if(set_fuelair_ratio)fuel_air_ratio(hSimConnect, recip_engine, fuelair_ratio);
    }
The function doing the work:
Code:
void fuel_air_ratio(HANDLE hSimConnect, double engine, double ratio)
{
    HRESULT hRes;

    if (engine == 1)hRes = SimConnect_SetDataOnSimObject(hSimConnect, DEFINE_FUELAIR_RATIO_ENG1, SIMCONNECT_SIMOBJECT_TYPE_USER, NULL, NULL, sizeof(double), &ratio);
    if (engine == 2)hRes = SimConnect_SetDataOnSimObject(hSimConnect, DEFINE_FUELAIR_RATIO_ENG2, SIMCONNECT_SIMOBJECT_TYPE_USER, NULL, NULL, sizeof(double), &ratio);
    if (engine == 3)hRes = SimConnect_SetDataOnSimObject(hSimConnect, DEFINE_FUELAIR_RATIO_ENG3, SIMCONNECT_SIMOBJECT_TYPE_USER, NULL, NULL, sizeof(double), &ratio);
    if (engine == 4)hRes = SimConnect_SetDataOnSimObject(hSimConnect, DEFINE_FUELAIR_RATIO_ENG4, SIMCONNECT_SIMOBJECT_TYPE_USER, NULL, NULL, sizeof(double), &ratio);
    // Reset the call variable
    set_fuelair_ratio = 0;
    return;
}
and finally, the call as set by the mixture lever:
Code:
    recip_engine = 1;                // Select the engine
    fuelair_ratio = 0.06;        // Set the F/A ratio to 0.06
    set_fuelair_ratio = 1;    // Tell simconnect to update
hres returns S_OK, but of course, the ratio is never set which is why I'm asking for help to figure out where I went wrong. Following through with the debugger shows the code path is being followed as I expect it.
 
Its another one of those sim vars which the SDK claims is settable but isn't. I mask mixture events from the sim and redirect them into my own code, while I control the mixture lever sim var instead and monitor the fuel air ratio to get it where I want it.
 
Back
Top