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

Problem with 'SimConnect_SetDataOnSimObject'

Well, I never thought I'd be so relieved to see fuel being pumped overboard. Ignoring my code foul-ups along the way, the base of the problem was (to quote Doug) 'the infrequent updates on the fuel vars '. Getting the fuel quantities and capacities into SimConnect made things so much easier. I also elected to go Maryadi's and Doug's suggested ways of reading and writing to single tanks rather than doing all tanks together in a struct. It made debugging slightly easier at the expense of increasing the code count. Many thanks to all for the contributions because I ended up using bits from all of you.

I did find something a bit strange along the way. 'FlightLoaded' really does not like being the first entry in any enumeration. I absolutely could not get the name of the flight through either
Code:
case CLIENT_SIMSTART:
{
    // Flight just loaded
    hr = SimConnect_RequestSystemState(hSimConnect, REQUEST_FLIGHT_LOADED, "FlightLoaded");
}
(...)
void OnRecvSystemState(SIMCONNECT_RECV_SYSTEM_STATE *pData)
{
    if (pData->dwRequestID)
    {
        switch (pData->dwRequestID)
        {
            case REQUEST_FLIGHT_LOADED:
                strncpy_s(CURRENT_FLIGHT, MAX_PATH, pData->szString, sizeof(pData->szString));
            break;
or
Code:
hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_FLIGHT_LOADED, "FlightLoaded");
(...)
void OnRecvEventFilename(SIMCONNECT_RECV_EVENT_FILENAME *pData, DWORD cbData)
{
    switch (pData->uEventID)
    {
        // Name of the flight just loaded
        case EVENT_FLIGHT_LOADED:
            strncpy_s(CURRENT_FLIGHT, MAX_PATH, pData->szFileName, sizeof(pData->szFileName));
        break;
Yet the moment I moved REQUEST_FLIGHT_LOADED and EVENT_FLIGHT_LOADED to the second line (ID=1) in their respected enumerations, both started working! :eek:

Once I'm sure about my flow rate calculations I'll package it up as a resource.
 
Last edited:
// A basic structure for a single item of returned data
struct StructOneDatum { int id; float value; };

StructDatum* pSa = (StructDatum*)&pObjData->dwData;

SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_PDR, SIMCONNECT_OBJECT_ID_USER, 0, sizeof(StructDatum), sizeof(*pSa), pSa);


runtime error in the simconnectinspector I see about: SetDataoOnSimObject exception invalid data size
 
sizeof(StructDatum) would return the size of a pointer. Also (StructDatum*) isn't the same as StructOneDatum that is defined above it.

I strongly recommend you take the time to read and understand what each parameter for this SimConnect function is.
 
// A basic structure for a single item of returned data
struct StructOneDatum {
int id;
bool value;
};

// maxReturnedItems
#define maxReturnedItems 3

// A structure that can be used to receive Tagged data
struct StructDatum {
StructOneDatum datum[maxReturnedItems];
};

So for tagged data I set the flag to 2 and the array count to 2 with the above struct?
 
You used a #define to set the array size, it's value is 3... where are you getting 2 from?

As for flag... set it to SIMCONNECT_DATA_SET_FLAG_TAGGED so that it becomes a readable value, not an ambiguous value that you have to go back to the documentation to see what a 2 means.

Last, but not least... what is your level of C/C++ programming? I ask because it makes it easier to know how in-depth a reply is needed.
 
Self-taught 20 years ago. X-plane sdk is much easier...
I get values in the tagged data example of maybe vertical speed 30 when it should be about 2040 as displayed in game. Do I need some formatting?
Thanks
 
Last edited:
You're showing so little of your code, it's going to be rather unlikely someone can point out the issue. However...
Your post where you are calling SimConnect_SetDataOnSimObject implies that you're trying to SET a data value in the sim, but you keep talking about reading data. I'm just not seeing the connection and what exactly you're trying to do.
 
SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_PDR, DEFINITION_PDR,
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND,
SIMCONNECT_DATA_REQUEST_FLAG_CHANGED | SIMCONNECT_DATA_REQUEST_FLAG_TAGGED);

With that I don't see my custom value. I've tried all kind of settings but always, apart the above, my Vertical speed is not shown. Thanks
 
You are creating a data definition using SimConnect_AddToDataDefinition to add each variable you want a return on? What data type have you defined for it?
You are making this request after the sim is up and running, not before it has completely loaded?
 
SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_PDR, DEFINITION_PDR,
SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_SECOND,
SIMCONNECT_DATA_REQUEST_FLAG_TAGGED);

with this the VS value continuously jumps to 0 and back to value.
yes, my custom variable seems ok. only vs is weird.
 
Well, not going to be able to assist any further with you responding with a single line of code and not actually answering questions being asked. Good luck!
 
Back
Top