Connecting Tech Pros Worldwide Forums | Help | Site Map

VERY weird variable behavior

petdoc
Guest
 
Posts: n/a
#1: Nov 20 '05
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





petdoc
Guest
 
Posts: n/a
#2: Nov 20 '05

re: VERY weird variable behavior


Turns out I *had* solved the bug - in THIS function. Unfortunately a
similar function that checked a different source for airspeed *also* had an
error trace identical to the one in question - and it was *that* function
that was generating the "ghost" error.

<blush> Sorry!

Scott

"petdoc" <petdocvmd*NOSPAM*@comcast.net> wrote in message
news:d8SdnWQ3a6amzijdRVn-uw@comcast.com...[color=blue]
> 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[/color]
and[color=blue]
> 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[/color]
2nd[color=blue]
> Trace.writeline to the third Trace.writeline (all I did was compare it to[/color]
a[color=blue]
> 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
>
>
>
>[/color]


Closed Thread