Mikock Posted March 29, 2010 Report Posted March 29, 2010 Good day! I am writing a small tool for my Flight Simulator. It should log some flight data. I am using the development language C#Sharp. With the help of FSUIPC I am trying ti get the data from the simulator. Some data works very good like airspeed, heading or lights switching. Today I have tried to read out my actual altitude. In FSUIPC there are some variables to get them (e.g. 0x0020 or 0x0570) But in this case I am only getting very strange values. I am cruising on 38000ft and I am only getting value = 0 When I am climbing to another level, I will get other strange values. It will change every second. Does anybody have an idea? Here are some code of it: [...] //Getting values from FSUIPC Offset agl = new Offset(0x0570); [...] //Transforming in feets double valagl = agl.Value * 3.28084 / (65536 * 65536); //Printing in label this.lblAGL.Text = valagl.ToString("f0"); [...] Thanks!
Pete Dowson Posted March 29, 2010 Report Posted March 29, 2010 In FSUIPC there are some variables to get them (e.g. 0x0020 or 0x0570) 0020 is the ground altitude. Only 0570 contains the aircraft latitude. Here are some code of it:[...]//Getting values from FSUIPCOffset agl = new Offset(0x0570);[...]Well, there's your problem. You are reading a fixed-point 64 bit value into a 64-bit floating point variable and expecting it to look right! Floating point formats are NOT the same as fixed point -- they have an exponent and mantissa. Fixed point values have neither. They are just integers.You should read the 64 bits (8 bytes) into a 64-bit fixed point variable -- an _int64 in Microsoft C, or a "long long" in ANSI C. I don't know what it might be in C#. It's something odd like "currency" in Visual Basic. This is explained in the Offset documentation in the FSUIPC SDK. Aren't you referring to that?Pete
Paul Henty Posted March 30, 2010 Report Posted March 30, 2010 ...I don't know what it might be in C#.Pete It's just 'long' or Int64 in C#. double valagl = agl.Value * 3.28084 / (65536 * 65536); It's good practice to write constants in the variable type you want rather than let the compiler convert them. Here your 65536's are 'int's and your 3.28084 is a single (float). It would be better to write these as doubles and also to cast your agl.value. The compiler may not always do what you'd expect in these situations if you force it to convert these different types. So your code would look something like this... //Getting values from FSUIPC Offset agl = new Offset(0x0570); [...] //Transforming in feets double valagl = (double)agl.Value * 3.28084D / (65536D * 65536D); Paul
Mikock Posted April 1, 2010 Author Report Posted April 1, 2010 Thanks to Paul and Pete, now it works fine!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now