Description
Versions: Leonardo, windows7, arduino 1.0.2 or 1.0.3
On windows, if you upload the ASCIITable sample and subsequently open the serial monitor, nothing gets printed.
Analysis: after uploading the sketch the serial port is touched (briefly opened) to take away the magic baud rate. (This was introduced to fix defect #995). However the sketch is already running and the 'while(!Serial);' loop sees the DTR becoming high and exits. As a consequence the sketch wants to send out its ascii table but the serial port will close soon after this and the data gets lost.
I investigated several options to solve this seemingly trivial problem but I found no good one.
The baudrate could be restored in the first (and then only) call to touchPort() routine (with baud rate 1200):
... port = (SerialPort) portId.open("tap", 2000); port.setSerialPortParams(irate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); port.setDTR(false); // will trigger the reset but device will still be around a while port.setSerialPortParams(oldRate, 8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); port.close(); ...
.
This would probably work most of the time (I did not try it though) but it is no good idea to send requests to a device after you instructed it to reset.
Restoring the baud rate when the booter is running makes no sense: on windows the bootloader comes back on a different port.
So the only good place to restore the baud rate is where it is done now. But to avoid the problem described here, it the port should be opened without DTR/RTS becoming set. I did not found a way to do that with rxtx.
Solution: Therefore I think it is best to just roll back touching the port after upload (unless somebody comes with a new idea). After all, the original problem described in issue 995 is easy to work around manually.
Also note that the issue 995 causes problems on mac, see #1186.