Jump to content
Sign in to follow this  
Guest

FSUIPC help...

Recommended Posts

Guest

I'm trying to grab the bank angle value from FS2k2 via FSUIPC.My problem is that the equation to convert the read value from the internal FS format to degrees is blowing out vb.The code is like this: If FSUIPC_Read(fs2kBANK, 4, VarPtr(BankAngleRaw), dwResult) Then retval = FSUIPC_Process(dwResult) If retval Then BankAngle = BankAngleRaw * 360 / (65536 * 65536) Label6.Caption = "-> " & BankAngle End IfBoth BankAngle and BankAngleRaw are declared Long. The equation is generating an overflow error. Ideas?Thanks!-- http://www.f15sim.com - The only one of its kind.

Share this post


Link to post
Share on other sites
Guest bartels

I have very limited ideas of VB and its possibilities, butI would use BankAngle as floating point number. Arne Bartels

Share this post


Link to post
Share on other sites
Guest

Not sure how VB treats your divisor (65536 * 65536) but i guess it converts it internally into a 32-Bit integer. The result of this conversion is actually 0 since your number is 1 bigger than the max value that a 32-bit integer can hold. So what actually happens i guess is a division by 0 which always results in an exception.Question: Are you sure your formula is correct???I don't have FSUIPC nor did i read the docs about creating gauges and FS variables yet, so can't tell you what would be correct here.Best RegardsDoc

Share this post


Link to post
Share on other sites
Guest

The formula that I'm using is the same as what is listed for that parameter in the FSUIPC programmer documentation. I'm totally at wits' end here. Thanks!g.-- http://www.f15sim.com - The only one of its kind.

Share this post


Link to post
Share on other sites
Guest jase439

I don't think this is a div-by-zero situation - there's a separate exception for that. This is most certainly an overflow condition since your long integer is limited to 2^31-1 (1 bit for the sign) and while your operands will be silently converted to long, your divisor (65536*65536) will still end up evalulating to 2^32 - which will clearly overflow by an order of magnitude. Use singles for both operands and the result and then truncate the result to a long int. Alternatively, you could divide once by 65536...and then divide that result again by 65536 in a separate statement.J

Share this post


Link to post
Share on other sites
Guest

It's not a divide by zero problem, you're right.Let me illustrate what's going on:I have an input value of 143233209 that's read straight from FS2k2 via FSUIPC. I then (per the documentation) have to apply this formula to the number: (# is my input value) # * 360 / (65536 * 65536) Now the result I get doing this with a calculator is this:The result of 65536 * 65536 is 4294967296.I do the first half (143233209 * 360) and get this:51563955240I take this number and divide it by the result I got from the huge multiplication in the second half and get this:12.00566...Which is exactly correct as the aircraft is in a 12 degree left bank.Now I've tried this using all single types and it _Still_ doesn't work even when I perform the 65536 division twice as suggested.Help!g.-- http://www.f15sim.com - The only one of its kind.

Share this post


Link to post
Share on other sites
Guest

May be you should considerer reading the bank at the alternate FSUIPC position &H2F78 which is a double and do not nead any further manipulation..Dim BankAngle as doubleIf FSUIPC_Read(&H2F78, 8, VarPtr(BankAngle), dwResult) Thenretval = FSUIPC_Process(dwResult)If retval ThenBankAngle = - BankAngle 'to make left negativeEnd IfLabel6.Caption = "-> ";Format(BankAngle,"#0.0") 'or any other formatHope this will helpHerv

Share this post


Link to post
Share on other sites
Guest jase439

Somewhere in your code VB is creating a temporary of type int or type long int which is overflowing. If you break your forumla down into a series of 2 operand statements, you should be able to identify which expression(s) overflow.However, I suggest you go for Herve's suggestion and save yourself the trouble :)

Share this post


Link to post
Share on other sites
Guest

Ok, I went ahead and started using the ADI bank indicator. Here's the code I'm using:Private Sub Timer_Timer()Dim dwResult As LongDim retval As BooleanDim BankAngleRaw As Double If Connected Then If FSUIPC_Read(&H2F78, 8, VarPtr(BankAngleRaw), dwResult) Then retval = FSUIPC_Process(dwResult) If retval Then Label6.Caption = "-> " & Format(BankAngleRaw, "#000.0") End If End If End IfEnd SubWhat I get is a number that never increases beyond 0. I get 0.82345622 or so when I've got the airplane in nearly a 90 degree left bank. I get the negative version of that when doing the same to the right. This is too simple for me to be screwing it up _that_ badly. What silly little thing am I missing?Thanks!g.-- http://www.f15sim.com - The only one of its kind.

Share this post


Link to post
Share on other sites
Guest JeanLuc_

0.8234... ? looks like it is a value in the range -1 0 1 instead of -90 0 90 ?

Share this post


Link to post
Share on other sites
Guest bartels

Or -Pi 0 Pi? Radians instead of Degrees?Arne Bartels

Share this post


Link to post
Share on other sites
Guest

Well no conversion requirements are listed in the documentation. It just says the location uses 8 bytes, is a floating point number and is expressed in degrees. I'm at a total loss. :)Thanks!g.-- http://www.f15sim.com - The only one of its kind.

Share this post


Link to post
Share on other sites
Guest JeanLuc_

8 bytes floating point = double (FLOAT64 in FS2k2)4 bytes floating point = float

Share this post


Link to post
Share on other sites
Guest

... and if you look at the code example I put up there, you can see that I'm using a double to hold the raw value.g.-- http://www.f15sim.com - The only one of its kind.

Share this post


Link to post
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
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...