Jump to content
The simFlight Network Forums

Read Altitude with VB


Recommended Posts

I found some here in the Forum, but am really not happy with the result.

Here is what I found:

Public Function Ground_Altitude() As Single ' meters Altitude MSL of ground under plane.

Dim x As Long

Dim y As Single

Dim dwResult As Long

Call FSUIPC_Read(&H7D4, 4, VarPtr(x), dwResult)

Call FSUIPC_Process(dwResult)

y = x

If y > 32767 Then y = y - 65534

Ground_Altitude = y * 3.28083989501312

Label4.Caption = Ground_Altitude

End Function

But I will get not the same rsult as the FS9 will show me?

Can somebody help?

CHristoph

Link to comment
Share on other sites

here's my code. what aren't you happy with? how much difference is there?

Public Function Ground_Altitude() As Single ' meters Altitude MSL of ground under plane.

Dim x As Long

Dim Y As Single

Dim dwResult As Long

Call FSUIPC_Read(&HB4C, 2, VarPtr(x), dwResult)

Call FSUIPC_Process(dwResult)

Y = x

If Y > 32767 Then Y = Y - 65534

Ground_Altitude = Mtof(Y)

End Function

Link to comment
Share on other sites

Public Function Ground_Altitude() As Single ' meters Altitude MSL of ground under plane.

Dim x As Long

Dim y As Single

Dim dwResult As Long

Call FSUIPC_Read(&H7D4, 4, VarPtr(x), dwResult)

Er7D4 certainly isn't "Ground Altitude", it is the altitude set in the autopilot. Please refer to the Programmer's Guide in the SDK.

Furthermore:

If y > 32767 Then y = y - 65534

Ground_Altitude = y * 3.28083989501312

What is that about? You are reading a 32 bit value which, as it states in the document, is 65536 x the number of metres (entered into the A/P). Comparing it with 32767 doesn't do much (32768 = half a metre). And multiplying it by 3.2 .. etc doesn't give you feet unless you also divide by 65536.

Regards,

Pete

Link to comment
Share on other sites

OK, I did try it:

Call FSUIPC_Read(&HB4C, 2, VarPtr(x), dwResult)

Call FSUIPC_Process(dwResult)

I really do not get the correct height like I see in FS window (STrg + z)

Peter I also tried to read directly the value for x, but it also does not read correct.

I am reading Heading LAT and LON without any trouble, but the height seem not like I want..

Thanks

Christoph

Link to comment
Share on other sites

OK, I did try it:

Call FSUIPC_Read(&HB4C, 2, VarPtr(x), dwResult)

Call FSUIPC_Process(dwResult)

I really do not get the correct height like I see in FS window (STrg + z)

The FS window Shift+Z does NOT show the GROUND altitude, it shows the AIRCRAFT altitude -- of course these will almost never be the same!

Not only that but you are reading a 2 bytes value into a 32-bit (4-byte) variable, I think (forgive me if I'm wrong -- I don't know VB). You need to zero that beforehand to avoid getting rubbish.

I am reading Heading LAT and LON without any trouble, but the height seem not like I want..

Hmm. Please think about things a bit longer and decide whether what "height" it is you want (aircraft, ground, VOR, NDB, Eiffel Tower? ;=)), then go find the correct offset and conversion in the documentation.

Please also use FSInterrogate to investigate these things. It is provided for a reason.

Regards,

Pete

Link to comment
Share on other sites

I need this height displayed in FS.

But I also can not get the results with this:

0020 4 Ground altitude in Metres x 256. (see also offset 0B4C)

Yes, but that also is the GROUND altitude, NOT the height of the aircraft. The ground altitude is NOT displayed in FS!!!

You seem very confused as to what you actually want to read! When you have decided, THEN look it up in the documentation, please.

AND please please PLEASE use FSInterrogate to actually look at all these things, live, and see how they read and convert there. It is supplied as a tool explicitly to help you sort these things out for yourself!

Regards,

Pete

Link to comment
Share on other sites

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.