Hi,
I'm hoping some of the more seasoned processing / java people can help me on the correct course of action:
I've got a situation where I need to communicate with an external serial device (an arduino in this case) over an extended period of time. This is an autonomous setup, and isn't actively monitored. I've got a problem where it seems at times the arduino is dropping the serial connection briefly, and the processing sketch subsequently crashes.
I can't stop the arduino from doing this, so I'm attempting to make processing handle the problem gracefully.
Frustratingly I don't see an easy way of testing if a connection is currently active. Serial.list seems to list all ports regardless of if one of them is already in use (by processing). I can't test for a lack of the port being available, as by the time it tests, the arduino will very likely be back up and running.
What I've so far managed is to get working is:
Code:
serialPort = new Serial(this, "/dev/tty.usbserial-A9006LiY", 9600);
try {
serialPort.write('1');
}
catch(RuntimeException e){
println("serial not present");
serialPort = new Serial(this, "/dev/tty.usbserial-A9006LiY", 9600);
}
--note the hard coded serial port would be inserted based on user selection at program start
--note I can't start and stop the serial connection each time I use it (at times i need to communicate once per second, and my testing tells me stopping and starting a connection can take up to 2 seconds)
Here I'm catching the exception at serial.write time. I'd prefer to be able to check for an active port rather than attempt to use it and fail. Is this possible?
serial.stop() seems to know if a connection is active, so is there some way to test it?
any other comments?
cheers!