P
petdoc
Hi Folks,
I am trying to find the most perplexing bug I have had in a vb.net app to
date.
Here is some code:
Dim Data as Short
Data = Me.ReadPMAPDigits(pmOffsets.APIAS)
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": Raw IAS: " &
Data.ToString, "Data")
'Mask off everything but lowest 10 bits - we only need values below 511 and
no negative values
Data = Data And CShort(&H3FF)
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": IAS: " &
Data.ToString, "Masked Data")
'Trap outliers
If Data > CShort(511) Then
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": E-IAS: " &
Data.ToString, "Error")
Me.GlobalErrorCount += 1
Exit Function
End If
The function this code comes from resides in a "super loop" (called via
nonthreaded delegate invocation every 60ms), reads airspeed from a flight
simulator (via interprocess communication) and returns a short value that
typically is in the range of 0-400 and for the following data was fixed at
120. Here is a snippet of logged data that repeated for about 5 minutes:
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
So far so good. But then...
Data: 5/26/2004 10:03:13 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:03:13 PM: IAS: 120
Error: 5/26/2004 10:03:13 PM: IAS: 131072
Data: 5/26/2004 10:03:13 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:03:13 PM: IAS: 120
Error: 5/26/2004 10:03:13 PM: IAS: 131072
Now can somebody tell me 1) How can the variable "Data" change from the 2nd
Trace.writeline to the third Trace.writeline (all I did was compare it to a
constant in between) *and* 2)How it got stuffed with decimal 131,072 - a
value too large to be represented by a short???? How might I stop this?
Help! I'm losing my mind over this and even with error trapping it's
ruining my program.
Scott
I am trying to find the most perplexing bug I have had in a vb.net app to
date.
Here is some code:
Dim Data as Short
Data = Me.ReadPMAPDigits(pmOffsets.APIAS)
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": Raw IAS: " &
Data.ToString, "Data")
'Mask off everything but lowest 10 bits - we only need values below 511 and
no negative values
Data = Data And CShort(&H3FF)
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": IAS: " &
Data.ToString, "Masked Data")
'Trap outliers
If Data > CShort(511) Then
Trace.WriteLineIf(blnErrorLogging, Now.ToString & ": E-IAS: " &
Data.ToString, "Error")
Me.GlobalErrorCount += 1
Exit Function
End If
The function this code comes from resides in a "super loop" (called via
nonthreaded delegate invocation every 60ms), reads airspeed from a flight
simulator (via interprocess communication) and returns a short value that
typically is in the range of 0-400 and for the following data was fixed at
120. Here is a snippet of logged data that repeated for about 5 minutes:
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
Data: 5/26/2004 10:16:16 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:16:16 PM: IAS: 120
So far so good. But then...
Data: 5/26/2004 10:03:13 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:03:13 PM: IAS: 120
Error: 5/26/2004 10:03:13 PM: IAS: 131072
Data: 5/26/2004 10:03:13 PM: Raw IAS: 120
Masked Data: 5/26/2004 10:03:13 PM: IAS: 120
Error: 5/26/2004 10:03:13 PM: IAS: 131072
Now can somebody tell me 1) How can the variable "Data" change from the 2nd
Trace.writeline to the third Trace.writeline (all I did was compare it to a
constant in between) *and* 2)How it got stuffed with decimal 131,072 - a
value too large to be represented by a short???? How might I stop this?
Help! I'm losing my mind over this and even with error trapping it's
ruining my program.
Scott