It will never recover communications again, since after closing the port and reopening the serial.available() is zero.
On the other hand, I have tested a simple C program and it is working as expected, this issue only happens with Processing.
It seems the stop is done correctly, because if I try to open then the port with another application it works, but processing is unable to open it again.
// Example by Tom Igoe
import processing.serial.*;
Serial serial; // The serial port
String comPort;
int BAUD = 9600;
boolean synched;
void setup()
{
size(400, 300);
// List all the available serial ports:
printArray(Serial.list());
// Open the port you are using at the rate you want:
comPort = Serial.list()[4];
serial = new Serial(this, comPort, BAUD);
//delay(1000);
if (serial.active())
{
synched = true;
println(synched);
}
textAlign(CENTER, CENTER);
textSize(48); //Max textSize set
}
int hrtBeat;
void draw()
{
background(255);
//heartbeat
int timer = frameCount%30;
if (timer == 0)
{
//println(hrtBeat);
hrtBeat++;
}
fill(0);
text(hrtBeat, 200, 100-20);
if( (timer == 0) && synched )
{
for (int i=0; i<16; i++)
{
serial.write(i);
}
serial.write('\r');
serial.write('\n');
println(frameCount, "Serial sending...");
//text("Serial sending...", 200, 200-20);
}
}
// Stop (s)
void keyPressed()
{
if (key == 's')
{
serial.clear();
serial.stop();
println(serial.active());
println("mid-serial: "+serial);
synched = false;
}
// Restart (r)
if (key == 'r' && !serial.active())
{
printArray(Serial.list());
serial = new Serial(this, comPort, BAUD);
//delay(500);
println(serial.active());
println("post-serial: "+serial);
synched = true;
}
}
I use W10 and Processing 4.01.
I was able to start stop the serial port with Processing to: