We are about to switch to a new forum software. Until then we have removed the registration on this forum.
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
Answers
Class Serial already got 2 concurrent callbacks: serialEvent() & serialAvailable().
However, those methods need to belong to an active PApplet instance. =;
If you do insist, you may attempt to hack Serial's Method fields serialEventMethod or serialAvailableMethod to point to another class' methods. :ar!
Hmmm, i see, but if my second thread is under the same PApplet, (i guess it is?) why "this" is not accepted so?
Keyword
this
is always of the datatype of the current scopedclass
. ~O)Why don't you post your code, or some sort of sample to let us know what you've achieved so far?
Here the nested class for the serial connection, than in my code need to work together an instance running it's own thread (here what is around is just an example):
I have to tell that, so far, seems to work correctly. Still i did not tried with more than one serial port.