Foppel Posted May 8, 2004 Report Posted May 8, 2004 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
Pete Dowson Posted May 8, 2004 Report Posted May 8, 2004 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 IntegerDim MyResult As ShortDim dwResult As ByteCall 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
Foppel Posted May 8, 2004 Author Report Posted May 8, 2004 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
Pete Dowson Posted May 8, 2004 Report Posted May 8, 2004 thanks for your quick response and help. The VB.Net code Does that work? Shouldn't you set "gsneedle" to zero before the Read, or are all variables in VB.NET zeroed for you? Pete
petdocvmd Posted May 9, 2004 Report Posted May 9, 2004 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
Pete Dowson Posted May 9, 2004 Report Posted May 9, 2004 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now