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

Loading fuel tanks via SimConnect

Messages
158
Country
us-northcarolina
Greetings fellow developers!

In my DLL application one of the things I need to do is load fuel tank quantities for the player's aircraft, and SimConnect ought to be able to to that easily. I can load all the payload stations just fine.

And indeed I can load any fuel tank quantity...but only one! Any attempt to load another tank fails to set the quantity. It doesn't seem to matter which one; the first one I set works and subsequent attempts to set others fail until...until I open up the fuel dialog box! Then, I can use SimConnect to set another tank.

It does not appear to be a timing issue. I can wait minutes between sets and it doesn't work on the 2nd one.

Does anyone know of any special thing that needs to be done between writes to fuel tanks so that they can be loaded?

Here's the code. Two test functions to load separate tanks, and I can call these from buttons on a gauge:

If 'TestFuelLoad1' gets called first, the center tank will have 100 gallons in it. A call to 'TestFuelLoad2' will not, however, put 200 gallons in the left main tank, it will stay zero UNTIL I manually bring up the fuel dialog box and observe the 100 gallons in the center tank. After this, the next call to 'TestFuelLoad2' will put the 200 gallons in the left main tank and leave the 100 in the center tank. Reverse the other of the calls and the opposite occurs, left main gets loaded and center won't -- it has nothing to do with which tank.

I realize that in this test I could set both of these with one call -- but the nature of the application is such that I need to be able to set tanks individually at different points without the user having to do anything.

Many thanks,
Dutch


void TestFuelLoad1()
{
double Value = 100;
HRESULT hr;

static enum DATA_DEFINE_ID21 {
FUELQTY1
};

hr = SimConnect_AddToDataDefinition(hSimConnect, FUELQTY1, "FUEL TANK CENTER QUANTITY", "gallons");
hr = SimConnect_SetDataOnSimObject(hSimConnect, FUELQTY1, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(double), &Value);

}

void TestFuelLoad2()
{
double Value = 200;
HRESULT hr;

static enum DATA_DEFINE_ID22 {
FUELQTY2
};

hr = SimConnect_AddToDataDefinition(hSimConnect, FUELQTY2, "FUEL TANK LEFT MAIN QUANTITY", "gallons");
hr = SimConnect_SetDataOnSimObject(hSimConnect, FUELQTY2, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(double), &Value);
}
 
Hey Dutch!

I think that you could try by defining the FUELQTY1 along with the FUELQTY2 in the same enumeration, i think that when you define the FUELQTY1 in a separated enumeration from the FUELQTY2, the program itself maybe assigning the same value (number) and as a result, when you call "SimConnect_AddToDataDefinition" and "SimConnect_SetDataOnSimObject" functions for each tank it's overwritting the same definition, because both (FUELQTY1 and FUELQTY2) have the same value (number).

Note that when im refering to *VALUE* (number) im not refering to the gallons (100 neither 200), im refering to the number assigned by the program which usually begins with 0 like an index number (because it's a enumeration) thats why maybe the second tank that you want to refuel isnt working.

When you define both IDs under the same enumeration statement, you will see that each ID has a different number:


Code:
static enum DATA_DEFINE_ID21 {
FUELQTY1, // number: 0
FUELQTY2, // number: 1
};


If you separate them, in different enumeration statements, i think you will get this:


Code:
static enum DATA_DEFINE_ID21 {
FUELQTY1, // number: 0
};

static enum DATA_DEFINE_ID22 {
FUELQTY2, // number: 0
};


Note that both have the *SAME* number, if you call the "SimConnect_AddToDataDefinition" and "SimConnect_SetDataOnSimObject" functions as it was in your original code, it will overwrite the same definition, giving as a result that you cannt set the fuel on the second tank. Remmember that you cann't use the same ID in two different definitions, as stated in the SDK.


I suggest you to try like this:


Code:
// Here i included both IDs in the same enumeration
static enum DATA_DEFINE_ID21 {
FUELQTY1,
FUELQTY2,
};


void TestFuelLoad1()
{
double Value = 100;
HRESULT hr;

hr = SimConnect_AddToDataDefinition(hSimConnect, FUELQTY1, "FUEL TANK CENTER QUANTITY", "gallons");
hr = SimConnect_SetDataOnSimObject(hSimConnect, FUELQTY1, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(double), &Value);

}


void TestFuelLoad2()
{
double Value = 200;
HRESULT hr;

hr = SimConnect_AddToDataDefinition(hSimConnect, FUELQTY2, "FUEL TANK LEFT MAIN QUANTITY", "gallons");
hr = SimConnect_SetDataOnSimObject(hSimConnect, FUELQTY2, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(double), &Value);
}


Try with it and let me know your results :) ...


Best Regards,


Manuel
 
Last edited:
Thanks for your quick and detailed response, Manual.

Your suggestion has indeed fixed the problem!

I still need to wrap my head around how those enums work...sigh.

Dutch
 
Thanks for your quick and detailed response, Manual.

Your suggestion has indeed fixed the problem!


Thanks!, it's good to heard that it worked. :)


I still need to wrap my head around how those enums work...sigh.


Yeah, also it happened to me time ago. It took me a little while, but finally i got it (how enumerations work).


Best Regards,


Manuel
 
Last edited:
Hi,

The other way to do it is to clear the definition after you've used it. What you're doing now is:

- Add tank1 to definition
- Set value 1 (== tank1)
- Add tank2 to definition (so you now have tank1 *and* tank2)
- Set value 1 (== tank1)

Try using SimConnect_ClearDataDefinition before adding your values. Of course, it's probably better to just use two definitions and only set them up once each, as described above.

Cheers,
Jim
 
Back
Top