Hey everyone. I've been building a large simconnect application, and this is my first time working with prepar3d so it's been quite a learning experience.
The issue that I'm currently facing is that I can't seem to find the correct way to grab the altitude in feet when I pull position data from the sim. It appears that the title, latitude, and longitude return back to the simconnect correctly, but the altitude is always a small decimal value with an exponent.
If there's anything that immediately appears wrong, please let me know. I've looked through hundreds of forum posts online already.
In my InitDataRequest method:
A defined struct to map the data
Requesting the data
Handling the data request
From what I've seen online, there's only been 1 other person who's come across this issue while attempting to write the c# simconnect application. I'm not sure what I can do to fix this, so I'm reaching out to potentially any more experienced developers with prepar3d. Would it be the data type I'm requesting the data into that I have to change? Or do I have to process this value somehow? From what I've seen online, and from the way I've requested other integer values onto my application, it shouldn't take more than just requesting the data and mapping it to the value in the structure. Altitude has been the only value causing me issues, and unforurtunately it's necessary for me to complete this application that I have that value ready.
Any tips or feedback would be greatly appreciated! Thanks.
The issue that I'm currently facing is that I can't seem to find the correct way to grab the altitude in feet when I pull position data from the sim. It appears that the title, latitude, and longitude return back to the simconnect correctly, but the altitude is always a small decimal value with an exponent.
If there's anything that immediately appears wrong, please let me know. I've looked through hundreds of forum posts online already.
In my InitDataRequest method:
C#:
simConnect.AddToDataDefinition(DEFINITIONS.PositionStruct, "title", null, SIMCONNECT_DATATYPE.STRING256,
0.0f, SimConnect.SIMCONNECT_UNUSED);
simConnect.AddToDataDefinition(DEFINITIONS.PositionStruct, "Plane Latitude", "degrees",
SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simConnect.AddToDataDefinition(DEFINITIONS.PositionStruct, "Plane Longitude", "degrees",
SIMCONNECT_DATATYPE.FLOAT32, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simConnect.AddToDataDefinition(DEFINITIONS.PositionStruct, "Plane Altitude", "feet",
SIMCONNECT_DATATYPE.FLOAT64, 0.0f, SimConnect.SIMCONNECT_UNUSED);
simConnect.RegisterDataDefineStruct<PositionStruct>(DEFINITIONS.PositionStruct);
A defined struct to map the data
C#:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi, Pack = 1)]
struct PositionStruct
{
// fixed size string
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string title;
public double latitude;
public double longitude;
public double altitude;
};
Requesting the data
C#:
simConnect.RequestDataOnSimObjectType(DATA_REQUESTS.REQUEST_1, DEFINITIONS.PositionStruct, 0,
SIMCONNECT_SIMOBJECT_TYPE.USER);
Handling the data request
C#:
case DATA_REQUESTS.REQUEST_1:
PositionStruct s1 = (PositionStruct) data.dwData[0];
titleLabel.Text = "Title: " + s1.title;
latitudeLabel.Text = "Latitude: " + s1.latitude;
longitudeLabel.Text = "Longitude: " + s1.longitude;
currentAltitude = (int) (s1.altitude);
altitudeTextBox.Text = $"{s1.altitude:N0}";
break;
From what I've seen online, there's only been 1 other person who's come across this issue while attempting to write the c# simconnect application. I'm not sure what I can do to fix this, so I'm reaching out to potentially any more experienced developers with prepar3d. Would it be the data type I'm requesting the data into that I have to change? Or do I have to process this value somehow? From what I've seen online, and from the way I've requested other integer values onto my application, it shouldn't take more than just requesting the data and mapping it to the value in the structure. Altitude has been the only value causing me issues, and unforurtunately it's necessary for me to complete this application that I have that value ready.
Any tips or feedback would be greatly appreciated! Thanks.


