We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Processing serial errors
Page Index Toggle Pages: 1
Processing serial errors (Read 731 times)
Processing serial errors
Mar 28th, 2010, 9:59am
 
I'm really new to processing and I am trying to use serial processing but I keep getting this error. I am trying to use code from the gizmologi.st

Here is the code just in case:
Code:
import processing.serial.*;

Serial myPort;
String filename = "photo.jpg";
byte[] photo = {};
Boolean readData = false;

void setup()
{
println( Serial.list() );
myPort = new Serial( this, Serial.list()[0], 38400 );
}

void draw()
{
byte[] buffer = new byte[64];
if( readData )
{
while( myPort.available() > 0 )
{
int readBytes = myPort.readBytes( buffer );
print( "Read " );
print( readBytes );
println( " bytes ..." );
for( int i = 0; i < readBytes; i++ )
{
photo = append( photo, buffer[i] );
}
}
}
else
{
while( myPort.available() > 0 )
{
print( "COM Data: " );
println( myPort.readString() );
}
}
}

void keyPressed()
{
if( photo.length > 0 ) {
readData = false;
print( "Writing to disk " );
print( photo.length );
println( " bytes ..." );
saveBytes( filename, photo );
println( "DONE!" );
}
else {
readData = true;
myPort.clear();
println( "Waiting for data ..." );
}
}


I keep getting this error when trying to compile:

Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
processing.app.debug.RunnerException: ArrayIndexOutOfBoundsException: 0
     at processing.app.Sketch.placeException(Unknown Source)
     at processing.app.debug.Runner.findException(Unknown Source)
     at processing.app.debug.Runner.reportException(Unknown Source)
     at processing.app.debug.Runner.exception(Unknown Source)
     at processing.app.debug.EventThread.exceptionEvent(Unknown Source)
     at processing.app.debug.EventThread.handleEvent(Unknown Source)
     at processing.app.debug.EventThread.run(Unknown Source)
Exception in thread "Animation Thread" java.lang.ArrayIndexOutOfBoundsException: 0
     at Arduino_to_Computer.setup(Arduino_to_Computer.java:32)
     at processing.core.PApplet.handleDraw(Unknown Source)
     at processing.core.PApplet.run(Unknown Source)
     at java.lang.Thread.run(Thread.java:619)

I'm a big time newby and any help is greatly appreciated!
Re: Processing serial errors
Reply #1 - Mar 29th, 2010, 2:10am
 
I was tempted to move the thread to Electronics,  Serial Library section, but it might be a syntax problem (more or less).
There is a line:
println( Serial.list() );
What does it print?

Perhaps you have no serial port detected, so the list is empty, hence the error.
Notes: indicating where the error is on the source helps too.
And in general, and particularly when hardware is involved, indicating what is your platform (Windows, Mac, Linux...) can be important too.
Re: Processing serial errors
Reply #2 - Apr 1st, 2010, 9:58pm
 
This is code from sam vusen. I am trying to grab an image saved into a serial eeprom into a processing folder. I was trying to compile the file and that is where I get the error. I thought Serial.list was a command in the serial library? I will try to connect the everything and then try again.
Page Index Toggle Pages: 1