P3D v4 Simconnect Data Requests.

#1
Hi, ive been trying to get altitude from the simulator using data requests. I've been following the SDK example and SDK documentation but ran into a problem. My results are not the same in WPF as it is in a WinForms example. Here is my data request code:

The problem i'm having it that my result from the datarequest is : 7.8359836439297E-67
while the result should be around: 1000 feet...

C#:
            simconnect.AddToDataDefinition(DEFINITIONS.Struct1, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0,SimConnect.SIMCONNECT_UNUSED);

            // IMPORTANT: register it with the simconnect managed wrapper marshaller
            // if you skip this step, you will only receive a uint in the .dwData field.
            simconnect.RegisterDataDefineStruct<Struct1>(DEFINITIONS.Struct1);

            // catch a simobject data request
            simconnect.OnRecvSimobjectDataBytype += new SimConnect.RecvSimobjectDataBytypeEventHandler(simconnect_OnRecvSimobjectDataBytype);

C#:
 switch ((DATA_REQUESTS)data.dwRequestID)
            {
                case DATA_REQUESTS.REQUEST_1:
                    Struct1 s1 = (Struct1)data.dwData[0];


                    uint u = Convert.ToUInt32(s1.altitude);
                    AltitudeTXT.Text = s1.altitude.ToString();

                    break;

                default:
                   
                    break;
            }
 
#2
Hi Sniperfull,

Are you sure you're requesting the data at some point using "simconnect.RequestDataOnSimObjectType(...)"?
Also, is there any specific reason to cast it to an Unsigned int there? I didn't see you using 'u' later. Remember that you are converting a double (64-bit) to an unsigned Int 32-bit. You might loose some data I guess.
Moreover, make sure your struct has the same configuration as the data definitions you are registering. For instance, if you have more than the altitude there, you should register them too and in the same order, to be able to receive the same struct back from SimConnect.

7.8359836439297E-67 is actually almost zero.

Cheers,

Jorge.
 
#3
Hi Sniperfull,

Are you sure you're requesting the data at some point using "simconnect.RequestDataOnSimObjectType(...)"?
Also, is there any specific reason to cast it to an Unsigned int there? I didn't see you using 'u' later. Remember that you are converting a double (64-bit) to an unsigned Int 32-bit. You might loose some data I guess.
Moreover, make sure your struct has the same configuration as the data definitions you are registering. For instance, if you have more than the altitude there, you should register them too and in the same order, to be able to receive the same struct back from SimConnect.

7.8359836439297E-67 is actually almost zero.

Cheers,

Jorge.

Hi Amengol,
the 'u' convertion was something i was just playing around with... that should be ignored. And yes i am using "simconnect.RequestDataOnSimObjectType(...)" when requesting data. Like i said this is code from the sdk example that i cannot get working in WPF... when trying in a normal WinForms it works perfectly, the issue is when i use it in WPF.
 
Top