Jump to content
The simFlight Network Forums

Recommended Posts

Posted

how on earth do i get the altitude out of FS?

currently its outputting: 908591104

where in fact when i press CTRL+Z in FS it shows: 269.7?

i can't for the life of me workout how to get it to output the correct altitude

Posted
how on earth do i get the altitude out of FS?

currently its outputting: 908591104

where in fact when i press CTRL+Z in FS it shows: 269.7?

What are you using to "get the altitude out of FS"?

Incidentally, don't you mean "Shift+Z" not "Ctrl+Z"?

Take a little look at what you posted. Don't you see that more information is needed here? How do you expect any useful answer? Why are you even posting in this particular forum? Are you referring to something in FSUIPC, or in some gauge or cockpit or what?

Pete

Posted

sorry im using C# to get the alitude using FSUIPC:

the code:

                // Get altitude
                result = fsuipc.FSUIPC_Read(0x0570, 8, ref token, ref dwResult);
                result = fsuipc.FSUIPC_Process(ref dwResult);
                result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
                double acalt = dwResult/ (65536 / 65536);
                altit.Text = Convert.ToString(acalt);

Posted
sorry im using C# to get the alitude using FSUIPC:

the code:

                // Get altitude
                result = fsuipc.FSUIPC_Read(0x0570, 8, ref token, ref dwResult);
                result = fsuipc.FSUIPC_Process(ref dwResult);
                result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
                double acalt = dwResult/ (65536 / 65536);
                altit.Text = Convert.ToString(acalt);

With Offset 3324 you can read ft or m, depends of FS setting.

3324, 4
This is the altimeter reading in feet (or metres, if the user is running with the preference for altitudes in metres), as a 32-bit signed integer. Please check offset 0C18 to determine when metres are used (0C18 contains ‘2’).

The same value can be calculated from the actual altitude and the difference between the QNH and the altimeter “Kollsman” pressure setting, but this value ensures agreement.

Posted

                // Get altitude
                result = fsuipc.FSUIPC_Read(0x0570, 8, ref token, ref dwResult);
                result = fsuipc.FSUIPC_Process(ref dwResult);
                result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
                double acalt = dwResult/ (65536 / 65536);
                altit.Text = Convert.ToString(acalt);

Okay. I'm a bit lost with C#. Is that "dwResult" a 64-bit integer? You are correctly reading 8 bytes (which is 64 bits), but it looks like you maybe are only using the first 32-bits, which would be the fraction of a metre in 1/(65536*65536) ths.

Also, in the line

double acalt = dwResult/ (65536 / 65536);

Does your compiler convert the "dResult" to floating point first, before the division? It would need to, but it doesn't seem likely.

Finally, you are dividing by 65536 / 65536 which even I can compute in my head as being equal to 1. Why divide by 1?

Three possible errors already, in not as many lines? I don't know C# I'm afraid. Maybe it is all good code, but it doesn't look like it!

Why not try using FSInterrogate to see what you are really supposed to get?

Regards

Pete

Posted

                // Get altitude
                result = fsuipc.FSUIPC_Read(0x0570, 8, ref token, ref dwResult);
                result = fsuipc.FSUIPC_Process(ref dwResult);
                result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
                double acalt = dwResult/ (65536 / 65536);
                altit.Text = Convert.ToString(acalt);

Okay. I'm a bit lost with C#. Is that "dwResult" a 64-bit integer? You are correctly reading 8 bytes (which is 64 bits), but it looks like you maybe are only using the first 32-bits, which would be the fraction of a metre in 1/(65536*65536) ths.

your right dwResult is set as a 32 it integer, i have changed it to a "Long" a 64 bit integer but thats kicked up loads or errors

Also, in the line

double acalt = dwResult/ (65536 / 65536);

Does your compiler convert the "dResult" to floating point first, before the division? It would need to, but it doesn't seem likely.

im not 100% sure im just learning c# myself

Finally, you are dividing by 65536 / 65536 which even I can compute in my head as being equal to 1. Why divide by 1?

Three possible errors already, in not as many lines? I don't know C# I'm afraid. Maybe it is all good code, but it doesn't look like it!

Why not try using FSInterrogate to see what you are really supposed to get?

Regards

Pete

how that got in there im not sure, as for using FSInterrogate, its showing the correct altitude in the factored column?

Posted

your right dwResult is set as a 32 it integer

Well, if your dwResult is where the stuff you are reading is supposed to end up, that will certainly give strange results.

However, are you sure "dwResult" is not simply an error code, returned when the function fails for some reason? At least, it is certainly like that in the C/C++ version of the interface. As I said, I don't know C# at all.

There is no "token" or "FSUIPC_Get" in the C/C++ interface, so I assume that's something to get around the problems with pointers in a Managed environment. Are you sure the result isn't returned somewhere else than the dwResult you are using?

i have changed it to a "Long" a 64 bit integer but thats kicked up loads or errors

Well, that would certainly happen if my suppositions above are correct.

If I were you I'd either change to C or C++, or see if you can find some examples or documentation for C#. Isn't there an example in the FSUIPC SDK? I'm sure someone contributed something on that.

There's also an improved C# interface in the client DLL offered in the sticky entitled "FSUIPC Client DLL for .NET - Release Version 1.3", above. Why don't you look at that?

Regards

Pete

Posted
If I were you I'd either change to C or C++, or see if you can find some examples or documentation for C#. Isn't there an example in the FSUIPC SDK? I'm sure someone contributed something on that.

i took one look at c++ and ran miles, i find C# increadibly easy compared to C++ due to its similarities to PHP which i have been using for about 2 years

There's also an improved C# interface in the client DLL offered in the sticky entitled "FSUIPC Client DLL for .NET - Release Version 1.3", above. Why don't you look at that?

Regards

Pete

yeah i have a look at it, couldnt make much sense of the installation :S

any i have had an idea on how to change dwResult to a 64-bit variable so im going to give that a shot.

Posted

i took one look at c++ and ran miles, i find C# increadibly easy compared to C++ due to its similarities to PHP which i have been using for about 2 years

Well, if such an experienced C# / PHP prograsmmer cannot see what is wrong here, I'm afraid I have no chance as I know so little about it.

Surely there's an example in the C# part of the SDK. Did you look at all? Do I have to look for you? ...

... Well, what do you know?! In the "C Sharp" ZIP in the SDK there's a file called "TestConsoleForm.cs", and what do think I found starting at line 497? Code to read and compute the Latitude and Longitude! I'm sure it can't be such a big step for you to convert that to getting and computing the altitude. All three values are 64-bit (long long) values.

Regards

Pete

Posted

ahh finnaly im getting somewhere after reading the SDK in depth i have found FSUIPC.cs had a ready made function to return 64 bit results, only problem is its outputting a very long number still, all be it a different number!!

long Result = 0;
                // Get altitude
                result = fsuipc.FSUIPC_Read(0x0570, 8, ref token, ref dwResult);
                result = fsuipc.FSUIPC_Process(ref dwResult);
                result = fsuipc.FSUIPC_Get(ref token, ref Result);
                long acalt = Result;
                altit.Text = Convert.ToString(acalt);

ouputs: 566534471680

in FS: 432.8?

is there somekind of mathematical calculation i need to perform to convert a to b?

Posted

ouputs: 566534471680

in FS: 432.8?

is there somekind of mathematical calculation i need to perform to convert a to b?

Yes. didn't you even refer to the documentation I supply in the SDK, describing what units the altitude at 0570 are in?

566534471680 is the altitude in metres * 65536 * 65536 -- because the top 32 bits represent the integer part and the lower 32-bits represent the FRACTION! That "big number" is actually 131.9065856934 metres. There are 3.28084 feet per metre. You work it out.

Why didn't you look at the examples in the SDK in the first place? It would be much more efficient, much less time-wasting for both of us if you actually try to use the resources already provided for you!

Even just looking at what FSInterrogate was doing (it even shows the raw and computed values and the formula used) would have shown you.

Please, next time, just look at what is already there in front of you!

:-(

Pete

Posted

it wasent that i was not reading the SDK some of it just was not making much sense to me.

but after reading it over and over and reading your comments, i worked it out!

one of the problems i was having was the large number being output would not equal that of FS-Interrogate after performing the same math calculations that are used by FS-Interogate, but finnaly i managed to get it to work!

            // Get altitude
            long Result = 0;
            result = fsuipc.FSUIPC_Read(0x0570, 8, ref token, ref dwResult);
            result = fsuipc.FSUIPC_Process(ref dwResult);
            result = fsuipc.FSUIPC_Get(ref token, ref Result);
            double lowalt = Result * 3.28084 / 65536 / 65536;

            double tlowalt = Math.Round(lowalt, 0);
            altit.Text = Convert.ToString(tlowalt);

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.