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 › Serial Library in Class
Page Index Toggle Pages: 1
Serial Library in Class? (Read 646 times)
Serial Library in Class?
Nov 10th, 2009, 8:30am
 
hi all!
////////////////////////////////////////////in the main
Plotter myPlotter;

void setup()
{
 size(200, 200);
 myPlotter = new Plotter();
}

void draw() {
}

////////////////////////////////////////////in my class

import processing.serial.*;

class Plotter extends PApplet{

 Serial myPort;
 byte fin = 3;

 Plotter(){
   String portName = Serial.list()[0];
   println(portName);
   myPort = new Serial(this, portName, 9600);
   //myPort.write("SP1;EA10000,15000;OS;");
   //myPort.write("SP1;PU0,6000;");
   //myPort.write(fin);
 }

}

end it don't work, it is possible to integrate a library in class? Like this?

thank so munch at all!
Re: Serial Library in Class?
Reply #1 - Nov 10th, 2009, 8:59am
 
Yes.
But I doubt you can have two PApplet objects.
Don't make Plotter to extend PApplet, pass the PApplet object (this in setup()) to Plotter's constructor and store it (or just use it there).
Re: Serial Library in Class?
Reply #2 - Nov 10th, 2009, 4:09pm
 
hum.....Can you make a exemple?
I try but, don't work....

Thank!
Re: Serial Library in Class?
Reply #3 - Nov 11th, 2009, 1:38am
 
Code:
Plotter myPlotter;

void setup()
{
size(200, 200);
myPlotter = new Plotter(this);
}

void draw() {
}

////////////////////////////////////////////in my class

import processing.serial.*;

class Plotter {

Serial myPort;
byte fin = 3;

Plotter(PApplet pa){
String portName = Serial.list()[0];
println(portName);
myPort = new Serial(pa, portName, 9600);
//myPort.write("SP1;EA10000,15000;OS;");
//myPort.write("SP1;PU0,6000;");
//myPort.write(fin);
}

}
(untested...)
Page Index Toggle Pages: 1