DragonflightDesign
Resource contributor
- Messages
- 1,355
- Country

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:
Enumeration for the engine:
Data definitions for the four engines:
The event call:
The function doing the work:
and finally, the call as set by the mixture lever:
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.
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)
Code:
DEFINE_FUELAIR_RATIO_ENG1,
DEFINE_FUELAIR_RATIO_ENG2,
DEFINE_FUELAIR_RATIO_ENG3,
DEFINE_FUELAIR_RATIO_ENG4
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);
Code:
case CLIENT_6HZ:
{
// Fuel-air ratio set
if(set_fuelair_ratio)fuel_air_ratio(hSimConnect, recip_engine, fuelair_ratio);
}
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;
}
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
