Quantcast
Channel: Library Questions - Processing 2.x and 3.x Forum
Viewing all articles
Browse latest Browse all 2896

serial connection opened in a parallel thread

$
0
0

Hi all, i would like to have a serial port declared into an object running a parallel thread (to feed a drawing machine with gcode).

Now, if if i try to open it like this:

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

As i would do usually, it don't works, it say: The constructor Serial(PLOT.Controller, String, int) is undefined

So if i try:

myPort = new Serial(new PApplet(), Serial.list()[0], 57600);

I can send command over it.

But if i try to declare a void calle serialEvent() in my class, it does not receive nothing. And if i try:

@Override  void serialEvent(Serial p) {
  String inString = p.readString();
  println(inString);
}

It thell me: The method serialEvent(Serial) of type PLOT.Controller must override or implement a supertype method

What i'm doing is having a method like this, called at any thread cycle:

 void serialCheck(){
        while(serialPort.available() > 0){
           String incoming  = serialPort.readStringUntil('\n');
           if(incoming != null)print(incoming);
        }
      }

And looks like working, but i don't know if will be stable or there are better ways. Any suggestions?

Thanks


Viewing all articles
Browse latest Browse all 2896

Trending Articles