Page 1 of 1

Managed C#, SIMCONNECT_RECV_CLIENT_DATA data question

Posted: Wed Feb 06, 2019 5:09 am
by ScottB26
I have set up a C# managed program to receive SIMCONNECT_CLIENT_DATA_REQUEST_FLAG.CHANGED data with .RequestClientData. I have a marshaled structure which mirrors the client data structure.

Code: Select all

[StructLayout(LayoutKind.Sequential, Pack = 1)] struct PMDG_747QOTSII_Data { ...};
I set up SimConnect with the following:

Code: Select all

simconnect.MapClientDataNameToID(PMDG_747QOTSII_DATA_NAME, PMDG_747QoTSII.PMDG_747QOTSII_DATA_ID); simconnect.AddToClientDataDefinition(PMDG_747QoTSII.PMDG_747QOTSII_DATA_DEFINITION, 0, (uint) Marshal.SizeOf(typeof(PMDG_747QOTSII_Data)), 0, 0); simconnect.RequestClientData( PMDG_747QoTSII.PMDG_747QOTSII_DATA_ID, DATAREQUEST_ID.DATA_REQUEST, PMDG_747QoTSII.PMDG_747QOTSII_DATA_DEFINITION, SIMCONNECT_CLIENT_DATA_PERIOD.ON_SET, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG.CHANGED, 0, 0, 0); simconnect.OnRecvClientData += new SimConnect.RecvClientDataEventHandler(simconnect_OnRecvClientData);
I can successfully trigger the data event by toggle the aircraft switches thereby invoking the following:

Code: Select all

void simconnect_OnRecvClientData(SimConnect sender, SIMCONNECT_RECV_CLIENT_DATA data) { switch ((DATAREQUEST_ID)data.dwRequestID) { case DATAREQUEST_ID.DATA_REQUEST: // I reach this point ok. // How do I read the data? // I have tried the following but things do not work. PMDG_747QOTSII_Data s1 = (PMDG_747QOTSII_Data)data.dwData[0]; //this does not work!! displayText("LTS_Taxi_Sw_ON: " + s1.LTS_Taxi_Sw_ON); break; default: displayText("Unknown request ID: " + data.dwRequestID); break; } }
Essentially, the basic plumbing works except I cannot cast the 'data' object to my 'PMDG_747QOTSII_Data ' structure type and access the data.

Would some kind soul set me straight?