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 & HelpElectronics,  Serial Library › error disabling serialEvent() for COM3
Page Index Toggle Pages: 1
error disabling serialEvent() for COM3 (Read 2472 times)
error disabling serialEvent() for COM3
Jul 30th, 2008, 4:44am
 
error, disabling serialEvent() for //./COM3
java.lang.reflect.InvocationTargetException
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)

I'm getting this error SOMETIMES, once I get this error, I would keep getting it everytime I attempt to run my code until I shutdown Processing.

I accomplish my goal without using the serialEvent but I rather my program be more computer resource friendly by not having to run a loop to check the size of the buffer all the time.

I'm using a FT232RL as my serial port and trying to communicate with a EM-406A GPS module at 4800 baud. The FT232RL chip is the only serial COM port and it is COM3, I did choose the correct port in my code.

Only other thread in this forum having this problem is
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Electronics;action=display;num=1183525352;start=0#0
Re: error disabling serialEvent() for COM3
Reply #1 - Oct 13th, 2008, 9:10pm
 
I had a similar problem before. Do you require a constant framerate? You could try noLoop() in your setup method, then call redraw() from the serialEvent().

I have not been able to reproduce the problem even after adding serialEvent and reading/writing different variables. I resorted to checking for available every frame. Sorry I don't have a better solution.
Re: error disabling serialEvent() for COM3
Reply #2 - May 20th, 2009, 3:17am
 
I struggled with the same error. the above forum link actually tells how to solve the problem, and without having made detailed research into the library, I guess the reason for this error is the following:

the Serial Object:

myPort = new Serial(this, Serial.list()[0], 115200);

calls on instantiation the public  

void serialEvent(Serial sp)

method of the extended PApplet Object (every Processing Patch is in fact an extended PApplet Class). I assume this call is there to test if such a method is defined. Hoever its Exception Handling doesnt deal very gracefull with the possible occurence of accesses to not yet instantiated objects inside this method.

In order to avoid this error it seems as if it is enough to make sure all the accessed instances have actually been instantiated before the Serial Object is instantiated.
Re: error disabling serialEvent() for COM3
Reply #3 - May 24th, 2009, 9:52pm
 
I wanted to post my tip for dealing with this error, as I had a very similar problem, and ran across this thread in a Google search for ways to solve it. Then a friend suggested a try...catch block.

My design involves listening for incoming packets from XBee radios. My error occurred because serialEvent(Serial) was getting called, and the program was trying to parse the incoming packet, before the serial connection had been fully initialized in the setup() function. For some unknown reason, it only threw the InvocationTargetException the first time the program started after plugging in, not subsequent times. If this sounds familiar, this may help:

Code:

void serialEvent(Serial XBee) {
 try {
 //read a byte from the port
   int curByte = XBee.read();
//if the byte value is 0x7E, new packet
   if (curByte == 0x7E) { //start the byte
if (packet[2] > 0) { //previous packet has been fully acquired
 //write better test for this?
 parseData(packet); //load the whole packet into the buffer
}
byteCounter = 0;
   }
 
   //put the current byte into the packet at the current position
   packet[byteCounter] = curByte;
   //increment byteCounter
   byteCounter++;
 } catch (Exception e) {
   println("Initialization exception");
//    decide what to do here
 }  
}


This XBee packet-listening function is cribbed straight from Making Things Talk... all I did was enclose the whole thing in the try{} part. The first few times this function is called, you'll catch the error and print the debug string, but it allows the program to fail gracefully and start behaving normally once the serial port connection is up. The only downside is that the first couple packets will be dropped.
Page Index Toggle Pages: 1