NXT Datalogging Exception
Page 1 of 1

Author:  Robo5009 [ Wed Feb 20, 2013 5:24 pm ]
Post subject:  NXT Datalogging Exception

I am trying to create a datalog with my accelerometer values in RobotC.

When I ran the program, an error screen appeared reading:

Byte Code Interpreter Exception:
Exception Type: 'Real Adress Range Exception(59)'

The reason I find this confusing is that in the line of coded in question (marked by the arrow), I cast the long variable robotstate.lasttime into an integer.

Here is my code (the important bits):

const int kDatalogSize = 1000;

task main ()   {
   nDatalogSize = kDatalogSize;
   const int kDataPointType1 = 1;
   const int kDataPointType2 = 2;

  while(true) {

     if(nUsedDatalogBytes >= kDatalogSize) {
     AddToDatalog(kDataPointType1, robotstate.accelvals.x);
 --> AddToDatalog(kDataPointType2, (int)robotstate.lasttime);

Important notes:
robotstate.accelvals.x is an integer (yet no errors).
robotstate.lasttime is essentially nPgmTime(also a long)

I did change a line of code in RobotCIntrinsics: I commented out the initial delaration for AddToDatalog(); and uncommented another declaration to take integers as values:

//intrinsic void AddToDatalog(compileConst int nDataPtIndex, const short data)
intrinsic void AddToDatalog(compileConst int nDataPtIndex, const int  nDataValue)

Anyone know why I am receiving this error?

P.S Posted this earlier in another section, hopefully I get better luck here.

Author:  Ernest3.14 [ Sat May 18, 2013 3:25 pm ]
Post subject:  Re: NXT Datalogging Exception

Your error seems to be an overflow one (the variable has overflowed into the adjacent memory slot). I think this is because longs are larger than ints, and therefore you can't cast longs to ints (it will compile, but at runtime the cast will fail). You can cast ints to longs though. The workaround would be to write your own casting function to handle this, something like:
int longToInt(long input)
    if (input==0)
        return 0;
    else if (input>32767) //upper limit of int variables
        return 32767;
    else if (input<-32768) //lower limit of int variables
        return 32768;
        return long;

The above code should work, but I haven't tested it. Get back to me if you're still around :)
Of course, you can change the limiting behavior to return 0 or whatever.

Author:  Robo5009 [ Thu Jun 20, 2013 6:08 pm ]
Post subject:  Re: NXT Datalogging Exception

Oops, no kidding, thanks for the help. Your solution works but I'll have to work something else out though since it doesn't work for my purposes. I need to enter very large numbers into the datalog which i'm not sure it supports. I'll fool around some more with the different datalogging options and see what I can figure out.

Author:  Ernest3.14 [ Fri Jun 21, 2013 12:56 am ]
Post subject:  Re: NXT Datalogging Exception

Ok. Good luck, and post what you come up with when you're done :)

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group