// You Need A Structure for the data
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LOCAL_STRUCT
{
//Position
public double Plane_Latitude;
public double Plane_Longitude;
public double Plane_Altitude;
}
public enum DATA_REQUESTS
{
REQUEST_1,
}
// I setup multiple under this enum, here for different data that may want ever second, or only once etc.
public enum DEFINITIONS
{
LOCATION,
}
// Then you create your SimConnect like you are.
// Register your Event handlers like you are
// OnRecvSimobjectData += .... What you have is fine
//
// Here is what you're missing:
smcn.AddToDataDefinition(DEFINITIONS.LOCATION, "Plane Latitude", "degrees latitude", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
smcn.AddToDataDefinition(DEFINITIONS.LOCATION, "Plane Longitude", "degrees longitude", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
smcn.AddToDataDefinition(DEFINITIONS.LOCATION, "Plane Altitude", "feet", SIMCONNECT_DATATYPE.FLOAT64, 0, SimConnect.SIMCONNECT_UNUSED);
// You're also missing this part
smcn.RegisterDataDefineStruct<LOCAL_STRUCT>(DEFINITIONS.LOCATION);
// Then finally this line will do the request and you're event handler should fire:
smcn.RequestDataOnSimObject(DATA_REQUESTS.REQUEST_1, DEFINITIONS.LOCATION, SimConnect.SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD.SECOND, 0, 0, 0, 0);
// Also Since I sometimes request data only at certain times, and some data I want all the time..
// I have a switch case to evaluate the DEFINITION enum against the data.dwDefineID
// to know which data the event handler received and which structure I need to cast it to to read it.
void OnGetDataByte(SimConnect sender, SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE data) {
switch((DEFINITIONS)data.dwDefineID)
{
case DEFENITIONS.LOCATION
{
var location = (LOCAL_STRUCT)data.dwData[0];
}
}
}