How do I check if com Port is already being used by another application or if it is free to be used ?
import processing.serial.*;
Serial myPort;
void setup(){
myPort = new Serial(this, Serial.list()[0], 9600); // How to check if this port is free or not ??
}
void draw(){
serialPortCheck();
serialReadData();
}
void serialPortCheck(){
if(myPort.active()==false){
println("Error in com Port");
}
}
void serialReadData(){
if(myPort.available()>0){
println(myPort.readString());
}
}
// display serial port list
println(Serial.list());
printArray(Serial.list());
// get the first available port (use EITHER this OR the specific port code below)
String portName = Serial.list()[0];
// get a specific serial port (use EITHER this OR the first-available code above)
String portName = "COM5";
// open the serial port
port = new Serial(this, portName, 115200);
May in this links some hints if you looking for something else
Using try\catch was useful to determine state of port as “Port busy” or “Port not found”.
I was able to disconnect the Arduino (unplug) and connect to it again (after plugging back in) and receive data in Processing sketch without restarting the sketch… that is a positive sign.