Jump to content
The simFlight Network Forums

FSUIPC_Write in Visual Basic


Recommended Posts

Hi,

I searched for some time here in the forum for information, how to use FSUIPC_Read. I found something and it works fine.

Thanks for all who help here!!!

But know I want to Write severel THings to FS9, but really are not very successful....

I want to go to a special Koordinate, Altitude and Heading.

But Most of the time my calculation does not work...

Does somebody have the correkt variables and calculations to send to FSUIPC?

Thanks for your help

Christoph Rieger

Link to comment
Share on other sites

  • Replies 57
  • Created
  • Last Reply

Top Posters In This Topic

I want to go to a special Koordinate, Altitude and Heading.

But Most of the time my calculation does not work...

Does somebody have the correkt variables and calculations to send to FSUIPC?

All the details for these things are in the Programmer's Guide in the FSUIPC SDK (http://www.schiratti.com/dowson) -- look through the table inside that document.

Regards

Pete

Link to comment
Share on other sites

Yes I did, and I now which variables I need, but I have problems calculating the correct value. Sorry, maybe I did not asked coorect, but I am not very good in comunicating in english

Here is one example I tried:

Call FSUIPC_Write(&H580, 4, VarPtr(Heading), dwResult)

Call FSUIPC_Process(dwResult)

I tried giving it directly and trying to recalculate:

heading * (65536# * 65536#) * 360#

Both did not st the plane in FS correct.

I think that VB is not really the easiest way to do these operations?

Link to comment
Share on other sites

Call FSUIPC_Write(&H580, 4, VarPtr(Heading), dwResult)

Call FSUIPC_Process(dwResult)

I tried giving it directly and trying to recalculate:

heading * (65536# * 65536#) * 360#

Both did not st the plane in FS correct.

Where is this * (65536# * 65536#) * 360# from? What does # mean in Visual Basic? In FSInterrogate # is used to mark "the value". But I din't know what you mean by it.

Please check the documentation again. It says that the heading at 0580 is multiplied by 360 and DIVIDED by (65536*65536) to get degrees TRUE. You seem to have three multiplications. I don't understand where you are getting your incorrect information from? Or is it just a simple typo?

Regards,

Pete

Link to comment
Share on other sites

  • 7 months later...
Does anyone have code to return the heading of an aircraft. I have been digging threw this forum with no luck at all.

Well, this probably isn't the right place to find code, though some folks do post examples in different languages. You actually need the FSUIPC SDK, from http://www.schiratti.com/dowson. Check the programming document, there's a table in there listing what are known as "offsets". The heading is provided in offset 0580. Just read it into a 32 bit integer and convert it to degrees as documented. If the result is negative, just add 360.

There are examples for assorted languages in the SDK. You should be able to use one of them, change it to read and convert the heading.

Regards,

Pete

Link to comment
Share on other sites

I am looking at the documentation. I am reading in the correct offset.

Dim Heading As Long

Call FSUIPC_Read(&H580, 4, VarPtr(Heading), dwResult)
Call FSUIPC_Process(dwResult)
Heading = Heading *360 / (65536*65536)
Form1.Caption = Heading

When I do this all I get are overflow errors. I have also tried declearing Heading as Currency which doesn't work either.

Link to comment
Share on other sites

Public Function Plane_heading() As Single

Dim x As Long

Dim dwResult As Long

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

Call FSUIPC_Process(dwResult)

Plane_heading = x / 65536 / 65536 * 360

End Function

Link to comment
Share on other sites

Heading = Heading *360 / (65536*65536)

...

When I do this all I get are overflow errors.

I don't know VB, but in C you would get overflow errors too this way, if your "Long" is only 32 bit.

In C, I use

double dHeading = (Heading * 360.0) / (65536.0 * 65536.0);

The use of the forms with ".0" on the right-hand side forces the calculations to be performed in floating point, so there is no overflow. I then store it in a floating point variable to retain accuracy -- however, if I only needed it to the nearest degree I'd use:

Heading = (long) (((Heading * 360.0) / (65536.0 * 65536.0)) + 0.5);

Note the "+ 0.5" part to round it to the nearest whole degree.

If VB cannot mix floating point and fixed point (I'd be surprised!) you might get away with converting it in fixed point in a different order, to avoid the overflow. i.e.

Heading = ((Heading / 65536) * 360.0) / 65536

By dividing first by one of the 65536's you "make enough room" in the 32 bits to multiply by 360 without overflow. The cost is a little loss in accuracy, but not much -- the result will still be to 1/65536ths of 360 degrees, or about 20 arc seconds. ;-)

This is more about understanding arithmetic than it is about programming, you know! You need to be able to apply a little logic too. ;-)

Regards,

Pete

Link to comment
Share on other sites

Public Function Plane_heading() As Single

Dim x As Long

Dim dwResult As Long

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

Call FSUIPC_Process(dwResult)

Plane_heading = x / 65536 / 65536 * 360

End Function

Hi John,

Doesn't this:

Plane_heading = x / 65536 / 65536 * 360

give you zero or -1 every time? It would in C, as dividing a 32-bit number by 65536 effectively shifts it right 16 bits. Doing this twice shifts all 32 bits out resulting in zero (or -1 if it were negative to start with, due to sign bit propagation).

If you are using VB.NET then the "Long" would be 64-bit, I think, so it wouldn't matter which order you did it in (but you'd need to set Plane_heading to zero first to make sure the top 32-bits didn't contain rubbish).

Regards,

Pete

Link to comment
Share on other sites

it's vb6, and the code has worked that way from v3.x through v4.x without a problem.

Hmmm. Odd. The VB generated code must convert everything to floating point no matter how you couch the arithmetic then, and convert back after. Strange then that it gives an overflow when you do the multiplations first. It seems very inconsistent doesn't it?

I shall never understand VB, it is too illogical. Microsoft seem to have made a lot of very odd design decisions in that language, with many inconsistencies (like extending an unwanted sign bit when you want hex 8000 or more ;-) )

Best

Pete

Link to comment
Share on other sites

If I do this:

Dim Heading As Double
Call FSUIPC_Read(&H580, 4, VarPtr(Heading), dwResult)
Call FSUIPC_Process(dwResult)
Heading = ((Heading / 65536) * 360#) / 65536
Form1.Caption = Heading

It returns 0

If I do this:

Dim x As Long
Dim dwResult As Long
Call FSUIPC_Read(&H580, 4, VarPtr(x), dwResult)
Call FSUIPC_Process(dwResult)
Plane_heading = x / 65536 / 65536 * 360 

It returns 0

I've have been writing in VB for 5 years now, so this type of math is not new to me. But I just can not figure out what I am doing wrong.

Link to comment
Share on other sites

If I do this:

Dim Heading As Double
Call FSUIPC_Read(&H580, 4, VarPtr(Heading), dwResult)
Call FSUIPC_Process(dwResult)
Heading = ((Heading / 65536) * 360#) / 65536
Form1.Caption = Heading

It returns 0

I'm not surprised. You can't read a fixed point value into a floating point variable (Double) and expect to make any sense of it. apart from the fact that a Double is 8 bytes long (64-bit) and you are reading only 4 bytes, the format is entirely incompatible.

What does the # do in 360# ??

If I do this:

Dim x As Long
Dim dwResult As Long
Call FSUIPC_Read(&H580, 4, VarPtr(x), dwResult)
Call FSUIPC_Process(dwResult)
Plane_heading = x / 65536 / 65536 * 360 

It returns 0

I would expect that too, as it would happen in C too. Dividing by 65536 is like shofting right by 16 bits. Do it twice and all 32 bits you read have gone already. (JD says it doesn't happen in his VB6, which mystifies me).

I've have been writing in VB for 5 years now, so this type of math is not new to me.

Why did you change to "Double" then, in the first example? Surely you know by now that is a different sort of number, and you must know after 5 years that 64 bits is more than 32 bits?

Regards,

Pete

Link to comment
Share on other sites

i don't know what to say. this is the function i have used in radar contact since v3. it works, because i'm constantly checking the plane heading..

Public Function Plane_heading() As Single

Dim x As Long

Dim dwResult As Long

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

Call FSUIPC_Process(dwResult)

Plane_heading = x / 65536 / 65536 * 360

End Function

Link to comment
Share on other sites

Now if I go with your example

Heading = ((Heading / 65536) * 360.0) / 65536

It just returns a number that I simple can not work with. i.e. 4.94065645841247E-323

i.e zero as near as dammit.

But that isn't surprising if you still have Heading defined as a Double. You cannot read a 32 bit fixed point number into a 64 bit floating point variable and expect to make any sense of it. I already pointed this out!!

Apologies for one mistake in my example earlier -- I should have typed 360 not 360.0. The latter is for floating point, which you weren't using!

But please re-read my previous reply, where I already pointed out your mistake in defining Heading as a Double. You must still be doing that to get a result like 4.94065645841247E-323!

Pete

Link to comment
Share on other sites

Public Function Plane_heading() As Single

...

Plane_heading = x / 65536 / 65536 * 360

Aha!

John, I just saw the solution to my confusion! The "Plane_heading" variable you are using IS defined as floating point ("Single", I'm fairly certain, is a 32-bit floating point variable type, the same as "float" in C). THIS is why you don't get zero or -1!

The one crucial line I didn't notice in the previous post with that formula is

Public Function Plane_heading() As Single

I can sleep now! ;-)

Pete

Link to comment
Share on other sites

JD when I do this

Public Function Plane_heading() As Single
Dim X As Long
Dim dwResult As Long
Call FSUIPC_Read(&H580, 4, VarPtr(X), dwResult)
Call FSUIPC_Process(dwResult)
Plane_heading = X / 65536 / 65536 * 360
Form1.Caption = Plane_heading
End Function

I get .312 any ideas?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share


×
×
  • 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.