Dear chuckians,

Not sure how many of you have messed with the serial objects - but I’m having a bit of a head-scratcher and wondered if anyone had any ideas about this.

I built a little box with one knob and one switch - which I’m planning to use as a master volume and mute switch for a multichannel audio installation that is running in Chuck.

The Arduino code is really basic:

const int SwitchPin = 12;
const int VolPin = 0;

void setup() 
{
  //turn on serial communication
  Serial.begin(57600);

  //set switch pin and turn on pullup resistor
  pinMode (SwitchPin, INPUT);
  digitalWrite (SwitchPin, HIGH);
}

void loop() 
{

  Serial.print(digitalRead(SwitchPin));
  Serial.print(' ');
  Serial.println(analogRead(VolPin));
  delay(50);

}

OK - so I first built a little Max patch to test it, which works flawlessly as far as I can tell.

I then wrote a little chuck script, based partially on one of Spencer’s examples.  It simply grabs the data and prints it to the console.

It works great for awhile, but after a few minutes, it always crashes with an array-out-of-bounds exception:

NullPointerException: (array access) on line[35]

I’m grabbing two ints, and looping through and printing them out.  Why is the array size suddenly getting mucked up here?   It’s intermittent, and sometimes doesn’t happen for several minutes, but always results in a crash eventually.  Any ideas?? (chuck code below)


SerialIO.list() @=> string list[];
SerialIO cereal;

//the name of my arduino box's serial port
"usbserial-12DP0657" => string port;

//number of serial device
-1=>int device;

//loop through any ports and find the one with the right name
for(0=>int i; i < list.cap(); i++)
{

    

    //check for correct port name
    if (list[i].find(port) != -1)
    { 
        //and assign the device number
        i => device;
    }
    else 
        -1 => device;
}

//open the serial port
cereal.open(device, SerialIO.B57600, SerialIO.ASCII);

//loop through and grab the serial port data
while(true)
{
    cereal.onInts(2) => now;
    cereal.getInts() @=> int ints[];

        

    //print out to console
    for(0=>int i; i < ints.cap(); i++)    //<- this is where the problem seems to happen
    {
        chout <= ints[i] <= " ";
    }
    chout <= IO.newline();
}



—ss

[ - ]  Scott Smallwood - Associate Professor - University of Alberta  [ - ]