We’ve updated the title of your post to better reflect the content and help others who might run into a similar issue. Thanks for sharing your debugging story, these kinds of posts are valuable for the community!
Thanks for sharing this. Looks like the issue came from using '8' and '1' as characters instead of 8 (int) and 1.0 (float). Easy mistake to make, especially since everything looks right at a glance!
Out of curiosity, did the error message help at all in finding this, or was it something you had to track down by trial and error?
import processing.serial.*;
// The serial port:
Serial _myPort;
// List all the available serial ports:
printArray(Serial.list());
// This genererated errors:
//_myPort = new Serial(_parent, _port, 115200, 'N', '8', '1');
// Reference: https://processing.org/reference/libraries/serial/Serial.html
// This works:
// Long Version
PApplet parent = this;
String portName = "COM3";
int baudRate = 9600;
char parity = 'N';
int dataBits = 8;
float stopBits = 1.0;
_myPort = new Serial(parent, portName, baudRate, parity, dataBits, stopBits);
// Short version that does not require variables above
//_myPort = new Serial(this, "COM3", 9600, 'N', 8, 1.0);
_myPort.write("Yay!");
There is no error message when I ‘compile’. I can see that the other side receives data (I can not see which data) but it does not send an expected reply back so it is not receiving correct data. If I use any terminal program instead of my Processing application it worked as expected.
Indeed. It was my stupidity to get that wrong.
It would be nice if the Serial library would check for invalid parameters and simply throw an exception.
@glv and @GoToLoop
The problem was not with the _parent.
The line was in a separate class in a separate file. I passed the parent (this) as an argument to the constructor when creating the object.
I was not clear about this because it was not relevant for my original topic title where I only wanted to vent some frustration about my stupidity.