I managed to get it to work. (based on info from previous comments)
Here is the code for anyone to refer in future.
import processing.serial.*;
Serial myPort;
String currentPort;
void setup(){
myPort = new Serial(this, Serial.list()[1], 9600);
currentPort=Serial.list()[1]; // Save current port
}
void draw(){
if(serialPortCheck()==true){
println("com port found");
}else{
println("com port lost");
}
serialReadData();
}
boolean serialPortCheck(){
boolean connected = false;
String[] str = Serial.list(); // Get the current list of available ports
for(int i=0; i<str.length; i++){
//println("com:"+currentPort+" str[i]:"+str[i]);
if(currentPort.equals(str[i])==true){ //check if currentPort is still in the list of comPorts
connected=true; // com port found so still connected
break;
}
}
return connected;
}
void serialReadData(){
if(myPort.available()>0){
println(myPort.readString());
}
}