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 › How to use SerialEvent() in Eclipse
Page Index Toggle Pages: 1
How to use SerialEvent() in Eclipse (Read 1505 times)
How to use SerialEvent() in Eclipse
Sep 12th, 2009, 12:26pm
 
Hi there,

anyone know how to use SerialEvent funtion from Serial Library in Eclipse? Y wrote a Serial class to have all Serial communication together. But the main class from which I use the Serial class cant trigger the SerialEvent. I can imagen that I have to tell the main class, that there is a Listener in the Serial Class...?
When I use code in Serial Class:

while (serialPort.available() > 0) {
                 inByte = serialPort.read();
           }

it works just fine. But when I try to use the SerialEvent function in the class:

private void serialEvent(Serial triggertPort) {
                 int anzPackete;
                 byte[] inBuffer = new byte[12]

                 anzPackete = serialPort.readBytes(inBuffer);
}

the function is not triggert.
Did anyone know how to add the SerialEvent Listener to my mainClass??

greetzi
Re: How to use SerialEvent() in Eclipse
Reply #1 - Sep 13th, 2009, 1:01am
 
As long as your main class extends a PApplet, you should only need to make the serialEvent function public.

When you initialize the serialPort object (the constructor takes a reference to your sketch: "this"), it will automatically look for the public function.
Re: How to use SerialEvent() in Eclipse
Reply #2 - Sep 16th, 2009, 8:18am
 
That's what I did. But if I write a function SerialEvent() in the Object, it is never triggert! Also I refered in the constructor to my PApplett.

Or do I have to make an instance of Serial in my mainClass and then refer in my Serial object to it??

ItS still not working:-(

I think it is the same question for mousePressed(). Is is it possible to use the mousePressed function in an object that is referenced to the Main PApplet?

Thanks for help:-)
Re: How to use SerialEvent() in Eclipse
Reply #3 - Sep 16th, 2009, 10:23pm
 
You can either call a function inside your custom object to handle mouse operations, or you can add a mouse listener to your object.
This may help:
http://processing.org/discourse/yabb2/num_1118340690.html

As for the serial event; are you using
"SerialEvent(Serial triggertPort)"
or
"serialEvent(Serial triggertPort)"

Capitalization counts.
Page Index Toggle Pages: 1