In the Libraries Reference for serialEvents it mentions a “which” parameter but does
not go into any details about it. I’ve search for any references on how to use this, but
have come up short. How does this parameter work and where do you use it in code?
I know I’ll probably be ask. I’m tinkering with an idea for automatically detecting com ports and this seems like it might be useful when dealing with an array of Serials. I’m not ready to share any code just yet, as I said, I’m just tinkering right now.
Thanks. I already know how to use more than one serial. I was asking about a feature that is mentioned.
I have dug into the library and apparently this feature does not exist. The way it’s stated, there should be a built in function within serialEvent that would return the port name that called it. The library reference should probably remove this statement to avoid confusion, or at least clarify that calling Serial.list()[number] returns a unique id that you need to use to compare the ports.
I understand that. What I’m saying is that isn’t a parameter. You can get the same result with this code:
import processing.serial.*;
String com0, com1;
Serial myPort0, myPort1; // The serial port
void setup()
{
size(400,200);
// List all the available serial ports:
printArray(Serial.list());
com0 = Serial.list()[4];
myPort0 = new Serial(this, com0, 9600);
myPort0.bufferUntil('\n');
com1 = Serial.list()[5];
myPort1 = new Serial(this, com1, 9600);
myPort1.bufferUntil('\n');
}
void draw()
{
}
void serialEvent(Serial thisPort)
{
if (thisPort.equals(myPort0))
{
String inString0 = myPort0.readString();
println(com0, inString0);
}
if (thisPort.equals(myPort1))
{
String inString1 = myPort1.readString();
println(com1, inString1);
}
}
The confusing thing is referencing that as a parameter. It makes it sound like there’s an easier way.
I’m just trying to be helpful for the next person that comes across this, and trust me, there’s a lot of people before me that have asked and have gotten no answer at all. To which I do thank you.