Jump to content
The simFlight Network Forums

GS - LOC Needle Value in VB.Net - help...


Recommended Posts

Hello,

I doesn't get the Values for the Nav1 Loc and GS needle in VB.NET. I got all values (Byte, Word, LongWord, SmallInt, LongInt) but the needed value (shortInt) range from -127 to +127 not.

Dim gsneedle As Integer
Dim MyResult As Short
Dim dwResult As Byte

Call FSUIPC_Read(&HC49, 1, gsneedle, dwResult)
Call FSUIPC_Process(dwResult)
Call FSUIPC_Get(gsneedle, MyResult)

Label2.Text = MyResult.ToString

Any help appreciated...

Regards,

Dirk

Link to comment
Share on other sites

I doesn't get the Values for the Nav1 Loc and GS needle in VB.NET. I got all values (Byte, Word, LongWord, SmallInt, LongInt) but the needed value (shortInt) range from -127 to +127 not.

The value is not a "short" (16 bit) but a signed byte (8 bit).

Dim gsneedle As Integer

Dim MyResult As Short

Dim dwResult As Byte

Call FSUIPC_Read(&HC49, 1, gsneedle, dwResult)

Call FSUIPC_Process(dwResult)

Two odd things there:

1: dwResult is a 32-bit result code, it won't fit into a byte.

2: You are correctly reading the 1 byte at offset 0C49, but into a 32-bit integer. You need to set that to zero first, or it is likely to contain rubbish in the unused 24 bits.

If you correct (2) then you will not see negative numbers -- the range will be 0 to 255. This is because the negative sign is in the single byte you have read, and will not be propagated into the other 24 bits. So to correct this you would need to OR into the 32-bit integer hex FFFFFF00 is the byte value is >= 128.

Regards,

Pete

Link to comment
Share on other sites

Hello Pete,

thanks for your quick response and help.

The VB.Net code

Dim gsneedle As Integer
Dim MyResult As Integer
Dim dwResult As Integer

Call FSUIPC_Read(&HC49, 1, gsneedle, dwResult)
Call FSUIPC_Process(dwResult)
Call FSUIPC_Get(gsneedle, MyResult)

If MyResult > 127 Then
    MyResult -= 256
End If
Label2.Text = MyResult

Regards,

Dirk

Link to comment
Share on other sites

The value is not a "short" (16 bit) but a signed byte (8 bit).

Two odd things there:

1: dwResult is a 32-bit result code, it won't fit into a byte.

2: You are correctly reading the 1 byte at offset 0C49, but into a 32-bit integer. You need to set that to zero first, or it is likely to contain rubbish in the unused 24 bits.

If you correct (2) then you will not see negative numbers -- the range will be 0 to 255. This is because the negative sign is in the single byte you have read, and will not be propagated into the other 24 bits. So to correct this you would need to OR into the 32-bit integer hex FFFFFF00 is the byte value is >= 128.

Pete,

VB.net has no signed byte data type. You have to use a short which covers -32768 to +32767.

VB.net "number" variables are initialized to zero implicitly upon declaration (and booleans to false, strings to 'Nothing', etc)(yeah I know, programmers should be allowed to fall on their own swords ).

I've been buried in 8051-variant assembler these days - feels kinda good mucking around in the"down 'n' dirty" stuff :-)

Scott

Scott L. Fausel, VMD

Integrated Flight Systems

Link to comment
Share on other sites

VB.net "number" variables are initialized to zero implicitly upon declaration (and booleans to false, strings to 'Nothing', etc)(yeah I know, programmers should be allowed to fall on their own swords ).

Ah, right. I was only being careful because, in C, only static (global) storage is initialised, the dynamic (local) stuff is just space reserved on the stack.

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.