Jump to content
The simFlight Network Forums

FSUIPC_Write in Visual Basic


Recommended Posts

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

I wasn't aware that I had to get the magnetic variation

You don't have to, it isn't mandatory. It depends what you want to use the heading you are reading for. It is a True heading, not a Magnetic one, which is good for navigation by maps but it won't match your magnetic compass heading.

The magnetic variation gives you the difference between them. It varies all over the world.

Regards,

Pete

Link to comment
Share on other sites

... What does # mean in Visual Basic? ...

Pete,

Not that you'd need to know this knowing as I do that you don't use VB but I thought I'd share this tidbit of information with you concerning the # trailing the numbers in VB such as 360#.

This is straight from the MSDN documentation:

"Double (double-precision floating-point) variables are stored as IEEE 64-bit (8-byte) floating-point numbers ranging in value from -1.79769313486232 E308 to -4.94065645841247 E-324 for negative values and from 4.94065645841247 E-324 to 1.79769313486232 E308 for positive values. The type-declaration character for Double is the number sign (#)."

So essentially the # symbol defines a numeric value as being a double data-type variable. There are several different ways to define a value as being a certain type of variable as I'm sure you are aware. The method I use most often is by explicitly declaring a variable as a specific variable type either in the application globals section, the form globals, or the procedure globals sections.

This is just my two cents (or what ever your local currency is)

Regards,

Joshua Robertson (creator of FS Real Time)

3D Softworks Design Studios

http://www.3dsoftworks.net

Link to comment
Share on other sites

So essentially the # symbol defines a numeric value as being a double data-type variable.

Ah, I see. In C a constant can be forced to be a double by simply adding a decimal part, thus

360.0

The VB "#" method is a bit like having to use "F" for float (the 32-bit version), as in

360.0F, or even 360F.

Thanks,

Pete

Link to comment
Share on other sites

  • 5 weeks later...

:) Gday all

Maby a little late to post ?

but was looking to get heading in Vb6 I found this works Perfect

Dim Vcount as long,MY_Heading as Single

If FSUIPC_Read(&H580&, 4, VarPtr(Vcount), dwResult) Then

If FSUIPC_Process(dwResult) Then

MY_HEADING = CSng(Vcount * 360#) / (65536# * 65536#)

End If

End If

Text1.Text = MY_HEADING

Link to comment
Share on other sites

:) Gday all

Maby a little late to post ?

but was looking to get heading in Vb6 I found this works Perfect

Dim Vcount as long,MY_Heading as Single

If FSUIPC_Read(&H580&, 4, VarPtr(Vcount), dwResult) Then

If FSUIPC_Process(dwResult) Then

MY_HEADING = CSng(Vcount * 360#) / (65536# * 65536#)

End If

End If

Text1.Text = MY_HEADING

That code snippit returns the heading in degrees-true. You would still have to add the magnetic variation to get the heading for degrees-magnetic.

Try also reading the offset &H02A0 for the MagVar value. It's a signed 16-bit value which can be read into a single precision variable within VB.

Regards,

Joshua Robertson (creator of FS Real Time)

3D Softworks Design Studios

http://www.3dsoftworks.net

Link to comment
Share on other sites

  • 1 month later...

I seem to get -65 when the airplane is on a heading of 270(w) degrees.

After the decimal point, I see 8 or so dancing random numbers, so I am ignoring them.

Call FSUIPC_Read(&H580, 4, VarPtr(x), dwResult)
Call FSUIPC_Process(dwResult)
Plane_heading = x / 65536 / 65536 * 360
lbl4.Caption = Plane_heading..

lbl4 is just a text window to show the result.

Kaela

Link to comment
Share on other sites

here is my code snippet

Public Function Plane_heading() As Single ' degrees Plane's magnetic heading.

Dim x As Long

Dim dwResult As Long

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

Call FSUIPC_Process(dwResult)

Plane_heading = norm360((x / 65536 / 65536 * 360) - magvar)

end function

you may have to adjust for the magnetic variation, which is what magvar is (another function, to get the current magnetic variation)

norm360 is a normalize function, which brings all heading to a range of 1-360 degrees

Link to comment
Share on other sites

Function norm360(h As Long) As Long

If h > 360 Then

norm360 = h - 360

ElseIf h = 0 Then

norm360 = 360

ElseIf h < 0 Then

norm360 = h + 360

Else

norm360 = h

End If

End Function

Link to comment
Share on other sites

Hi. many thanks JD.

wile I was at it, I tried my own version and got it all sideways. You just shed a lot of light on the matter there.

Thanks Peter, I will re-read the results I was getting in FS_Interrogate. Could lead to a fruitful evening.

I have seena routine somewhere in my stuff for rotating a graphic in VB, now I have been trying to find that, sigh, as we get older we have more answers, just that they seem cluttered up with a lot more 'other stuff'.

I have to resist the urge to ask too many questions, but I am reading 'Theif of time' as well, so the two may overlap...

One question: I offer this to you with so much more experiance than I, Can any of the existing material used in the Guages folder, be re-used outide of FlightSim, or can they ONLY be interpreted by FlightSim???

In your reply (and it works quite admirabley), h=(x / 65536 / 65536 * 360) - magvar, I think...

Kizzie

Link to comment
Share on other sites

Hi JD.

Thank you for your help above.

I have been exploring the MSDN pages at Microsoft.com, looking for a method I can adapt to rotate images.

0 degrees, 30 degrees, 60 degrees and 90 degrees

I have been trying to find relativly simple VB code to enable me to rotate these images by o - 360 degrees.

example: image.rotate(x)

One method, would be to have three hundred and sixty five images, selecting each in turn to meet the need, but I think there is a more attractive solution. I understand that you may be able to point me in the right direction.

Warmest Regards

Kaela

Link to comment
Share on other sites

  • 1 month later...

Ok here is what I am doing. I am using :

Public Function Plane_heading() As Single
Dim x As Long
Dim dwResult As Long
Call FSUIPC_Read(&amp;H580, 4, VarPtr(x), dwResult)
Call FSUIPC_Process(dwResult)
Plane_heading = x / 65536 / 65536 * 360
End Function

I get a return of .312

If I do this:

Dim Vcount as long,MY_Heading as Single
If FSUIPC_Read(&amp;H580, 4, VarPtr(Vcount), dwResult) Then
If FSUIPC_Process(dwResult) Then
MY_HEADING = CSng(Vcount * 360#) / (65536# * 65536#)
End If
End If
Text1.Text = MY_HEADING

I get .312 my plane gyro compass is reading 340 whiskey is reading 340

But if I get the Auto Pilot heading I am doing this:

    Dim APHeading As Long
    Dim Convert As Single
    Call FSUIPC_Read(&amp;H7CC, 4, VarPtr(APHeading), dwResult)
    Call FSUIPC_Process(dwResult)
    Convert = (APHeading * 360) / 65536
    Me.Caption = Convert

I get a return of 339.9 I can round. Thats not big deal.

Can someone help me with the plane heading.

Link to comment
Share on other sites

Ok here is what I am doing. I am using :

Public Function Plane_heading() As Single
Dim x As Long
Dim dwResult As Long
Call FSUIPC_Read(&amp;H580, 4, VarPtr(x), dwResult)
Call FSUIPC_Process(dwResult)
Plane_heading = x / 65536 / 65536 * 360
End Function

I get a return of .312

I'm not familiar with VB, which I assume this is, but assuming "Single" is a type of floating point I would have thought it advisable to convert "x" to floating point first, before doing the calculations:

Plane_heading = x

Plane_heading = (Plane_heading * 360.0) / (65536.0 * 65536.0)

Note that I always use parentheses () to force the order of computation -- I never trust compilers to get it right! ;-)

Pete

Link to comment
Share on other sites

Is the difference not due to magnetic variation?

0x0580 is a True heading, while the whisky compass, the gyro compass and the Autopilot heading at 0x07CC are all Magnetic headings.

The current Magnetic Variation is at offset 0x02A0. If it's 20 degrees then your 0.312 is probably correct.

Paul

Link to comment
Share on other sites

So your telling me to drop the decimal infront of .312? If that is the case the how come AP is so close with 339.9?

No, he's not telling you that. Please read it again.

The heading provided by the offset you are reading is in degrees TRUE --i.e. it is relative to TRUE North. The one shown on the panel is Degrees MAGNETIC. The difference is the magnetic variation, which is also readable if you want to convert one to the other.

Your ".312" may well be the correct TRUE heading.

Why don't you use FSInterrogate to check your results against? That is why it is provided after all. :-(

Please read again the comments in the documentation about these offsets.

Pete

Link to comment
Share on other sites

Here is what I am doing:

    Dim PHeading As Long
    Dim MagVar As Long
    Dim dwResult As Long
    Call FSUIPC_Read(&amp;H580, 4, VarPtr(PHeading), dwResult)
    Call FSUIPC_Process(dwResult)
    Call FSUIPC_Read(&amp;H2A0, 2, VarPtr(MagVar), dwResult)
    Call FSUIPC_Process(dwResult)
    MagVar = MagVar * 360 / 65536
    Plane_heading = PHeading
    Plane_heading = (Plane_heading / 65536 / 65536 * 360) - MagVar

The Plane Heading is returning .312 while at 340. The MagVar is returning 20.

If I do the final math I get -19.68761

Any ideas?

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.