Managed C#, SIMCONNECT_RECV_CLIENT_DATA data question

ScottB26
Posts: 1
Joined: Wed Feb 06, 2019 4:29 am

Managed C#, SIMCONNECT_RECV_CLIENT_DATA data question

Postby ScottB26 » Wed Feb 06, 2019 5:09 am

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?

Cheers,
Scott434/ScottB26

Return to “SimConnect Interface Questions”

Who is online

Users browsing this forum: No registered users and 9 guests