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

Client Data area problems

Messages
516
I'm trying to get shared client data areas working and not having a lot of luck.

I can set up the area in one simconnect client, and although another can request it and the callback seems to return the requested definition, it's always empty. (i.e. The dwData pointer is always zero.)

Here's a couple of samples I put together to testClient Data away from my main application. (and these don't work either.)

The data setting client application:

Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include "SimConnect.h"
typedef double FLOAT64;

HANDLE  hSimConnect = NULL;

static enum DATA_DEFINE_ID {
    DEFINITION_1 = 1,
};

static enum DATA_REQUEST_ID {
    REQUEST_1 = 1,
};

void CALLBACK MyDispatchProcTCDS(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
    switch(pData->dwID)
    {
        case SIMCONNECT_RECV_ID_CLIENT_DATA:
        {
            SIMCONNECT_RECV_CLIENT_DATA *pObjData = (SIMCONNECT_RECV_CLIENT_DATA*)pData;
            
            switch(pObjData->dwRequestID)
            {
                case REQUEST_1:
                {
                    break;
                }
            }
            break;
        }
    }
}

FLOAT64 testData = 321;

void testClientDataSet()
{
    HRESULT hr;

    if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Test Client Data - Set", NULL, 0, 0, 0)))
    {
        printf("\nConnected to ESP!");   
        
		hr = SimConnect_MapClientDataNameToID(hSimConnect,"TestClientData",1);
		hr = SimConnect_AddToClientDataDefinition(hSimConnect,DEFINITION_1,SIMCONNECT_CLIENTDATAOFFSET_AUTO,SIMCONNECT_CLIENTDATATYPE_FLOAT64,0,0);
		hr = SimConnect_CreateClientData(hSimConnect,
									1,
									8,
									SIMCONNECT_CREATE_CLIENT_DATA_FLAG_READ_ONLY );
		hr = SimConnect_SetClientData(hSimConnect,
									1,
									DEFINITION_1,
									0,0,
									sizeof(FLOAT64),
									&testData);

        while( 1 )
        {
            hr = SimConnect_CallDispatch(hSimConnect, MyDispatchProcTCDS, NULL);
            Sleep(1);
        } 
        hr = SimConnect_Close(hSimConnect);
    }
}

int __cdecl _tmain(int argc, _TCHAR* argv[])
{
    testClientDataSet();
	return 0;
}

The data retrieval client application:
Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include "SimConnect.h"
typedef double FLOAT64;

HANDLE  hSimConnect = NULL;

static enum DATA_DEFINE_ID {
    DEFINITION_1=222,
};

static enum DATA_REQUEST_ID {
    REQUEST_1 = 123,
};

void CALLBACK MyDispatchProcTCDR(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
    switch(pData->dwID)
    {
        case SIMCONNECT_RECV_ID_CLIENT_DATA:
        {
            SIMCONNECT_RECV_CLIENT_DATA *pObjData = (SIMCONNECT_RECV_CLIENT_DATA*)pData;
            
            switch(pObjData->dwRequestID)
            {
                case REQUEST_1:
                {
                    break;
                }
            }
            break;
        }
    }
}

void testClientDataRequest()
{
    HRESULT hr;

    if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Test Client Data - Get", NULL, 0, 0, 0)))
    {
        printf("\nConnected to ESP!");   
        
		hr = SimConnect_MapClientDataNameToID(hSimConnect,"TestClientData",1);
		hr = SimConnect_AddToClientDataDefinition(hSimConnect,DEFINITION_1,SIMCONNECT_CLIENTDATAOFFSET_AUTO,SIMCONNECT_CLIENTDATATYPE_FLOAT64,0,0);

        while( 1 )
        {
			hr = SimConnect_RequestClientData(hSimConnect, 1, REQUEST_1, DEFINITION_1, SIMCONNECT_CLIENT_DATA_PERIOD_SECOND, 0, 0, 0);
            hr = SimConnect_CallDispatch(hSimConnect, MyDispatchProcTCDR, NULL);
            Sleep(1);
        } 
        hr = SimConnect_Close(hSimConnect);
    }
}

int __cdecl _tmain(int argc, _TCHAR* argv[])
{
    testClientDataRequest();
	return 0;
}

Anybody got any ideas as to what I'm doing wrong? The above example just tries to set a float64 in the shared area and get it back from another client. The definition ids and request ids are different because they should be client dependent, where as the client data id (1) and client name has to be identical in both. (This is how I understand it.

I'm confused. Everything normally works so easily...

Si

EDIT: Note: To check the received data I'm just breaking on the "switch(pObjData->dwRequestID)" line and inspecting the structure.
 
Well.. after further investigation it appears my code is all running perfectly.

My mistake was to assume the SDK documentation is clear and precise.

I was monitoring dwDefineCount in the SIMCONNECT_RECV_CLIENT_DATA structure (which inherits SIMCONNECT_RECV_SIMOBJECT_DATA) to check for the size of my expected structure in multiples of 8 bytes. (My app is a lot more complicated that the sample I threw together above.)

The SDK states that dwDefineCount is "The number of 8-byte elements in the dwData array" and dwData is "A data array containing information on a specified object in 8-byte (double word) elements. The length of the array is dwDefineCount." However, this is *NOT* true!

I am passing a struct containing 8 doubles, the definition knows this (or at least the size in bytes) but the dwDefineCount I get back is 1, when it should be 8.

The dwSize is also misleading. It gives the size of the SIMCONNECT_RECV_SIMOBJECT_DATA structure, but does not include any of my doubles beyond the first contained within the dwData DWORD. So it effectively only contains the size of the header, and NO information is returned in the header to accurately indicate how many bytes are valid. You just have to assume it matches the size in the prior simconnect definition call.

I discovered the answer when I checked the definition of dwDefineCount in the simconnect.h file. It states "data count (number of datums, *not* byte count)", which clearly contradicts the SDK doc.

What fun...

Si
 
Hey Simon,

I'll admit, Client Data support is probably the least tested part of the system. In fact, the managed wrapper doesn't seem to handle receiving client data at all (well, you can get the first DWORD, but that's not real useful :-> ).

What I've found works easiest, is to define a data structure in a header shared between both/all SimConnect clients that will be using that Client Data area, and just do one AddToClientDataDefinition call with sizeof(STRUCT_NAME)for the param size value (make sure an appropriate matching structure packing scheme is in place in all uses, etc).

Also, unless the values are changing quickly, I find it easier to use the SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET value in the RequestClientData call (also, in your sample code you had the RequestClientData call inside of the while (1) loop, since this is a periodic repeating command, you only need to send it once).
 
define a data structure in a header shared between both/all SimConnect clients

Yes, that's the way I ended up implementing it.

in your sample code you had the RequestClientData call inside of the while (1) loop

That was me just trying anything and everything. I originally had it outside the loop, which is where I've got it now.

I've actually got several client data areas, so I can expose only the aspects of the functionality that I want to different client vendors. Some of them update every visual frame, other not. So the requesting rates for the structures will vary accordingly.

I guess the managed wrapper probably suffers from the problem that's apparent in the C structure header, in that the size is not reported correctly and only includes the first data word.

I must admit that I was disappointed not to find a sample in the SDK for Client Data and the internet didn't turn up anything. Hopefully this thread will provide some guidance for those that follow.

Si
 
Hey Simon,

I'll admit, Client Data support is probably the least tested part of the system. In fact, the managed wrapper doesn't seem to handle receiving client data at all (well, you can get the first DWORD, but that's not real useful :-> ).

What I've found works easiest, is to define a data structure in a header shared between both/all SimConnect clients that will be using that Client Data area, and just do one AddToClientDataDefinition call with sizeof(STRUCT_NAME)for the param size value (make sure an appropriate matching structure packing scheme is in place in all uses, etc).

Also, unless the values are changing quickly, I find it easier to use the SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET value in the RequestClientData call (also, in your sample code you had the RequestClientData call inside of the while (1) loop, since this is a periodic repeating command, you only need to send it once).

I'm interested in exactly how you got it working to receive more than one int. Do you have some code or more details to share? I'm trying to SetClientData and ReceiveClientData on a struct, but I can never get more than the first int.

Ideas? Help?
 
Alternative managed wrapper marshaller for Client Data receiving

While updating SDK of my FSX add-on (thanks Simon, thanks Geoff) I encountered RegisterDataDefineStruct SimConnect managed wrapper
marshaller issue: the marshaller does not make it possible to receive Client Data. Later I found that this problem is already known.
To fix this issue I have written a small piece of C# code (see below). It works fine in my case and I hope will help other developers too.

To enable Client Data receiving the following method is used:

Code:
public void RegisterClientDataDefineStruct<T>(Enum dwID)
{
    simconnect.RegisterStruct<SIMCONNECT_RECV_CLIENT_DATA, T>(dwID);
}

simconnect is a SimConnect object.

This method must be called after the last AddToClientDataDefinition managed wrapper API function call:

Code:
simconnect.MapClientDataNameToID(...);
...
simconnect.AddToClientDataDefinition(DEFINITIONS.Struct1, ...);
this.RegisterClientDataDefineStruct<Struct1>(DEFINITIONS.Struct1);
Struct1 and DEFINITIONS.Struct1 are Client Data structure and its definition ID respectively, also in this example it's assumed that
RegisterClientDataDefineStruct method defined in the same class.

All this is needed for Client Data receiving only as for FSX Data receiving the native RegisterDataDefineStruct marshaller can be used
successfully. Also it should be remembered that in some cases specific information (attributes) must be provided with Client Data structure(s)
as described in SimConnect SDK.

Attached is a console sample. It's not ready-to-use managed application and demonstrates only how suggested alternative marshaller works.

Sorry that I cannot visit this forum frequently, in case of need e-mail me: vstsim@yahoo.com
 

Attachments

Last edited:
Back
Top