Go Down

Topic: SerialException with Arduino v1.0.2 and Leonardo (Read 3514 times) previous topic - next topic

9dof

When I tried uploading this sketch I get SerialException after it's done uploading.

Code: [Select]
#define LED 13
#define DELAY 500

unsigned long nextTime;
int ledState = HIGH;

void setup() {
  pinMode(LED, OUTPUT);
  digitalWrite(LED, ledState);
  ledState = (ledState == HIGH) ? LOW : HIGH;
  nextTime = millis() + DELAY;
}

void loop() {
  if (millis() > nextTime) {
    nextTime += DELAY;
    digitalWrite(LED, ledState);
    ledState = (ledState == HIGH) ? LOW : HIGH;
  }
}


The sketch seems to run OK though.

This doesn't happen with a Uno target or with IDE v1.0.1 or v1.5.x

I'm on a Mac OS X Lion (10.7.5).

v1.0.1 has a hanging bug with tone() on Leonardo so I need to use either 1.0.2 or 1.5.x, but 1.5.x is still in beta.

Can someone else confirm this bug?

The full message from the IDE is as follows:

Code: [Select]
Binary sketch size: 4,952 bytes (of a 28,672 byte maximum)


processing.app.SerialException: Serial port '/dev/tty.usbmodemfd1211' already in use. Try quitting any programs that may be using it.
at processing.app.Serial.touchPort(Serial.java:119)
at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:201)
at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
at processing.app.Sketch.upload(Sketch.java:1671)
at processing.app.Sketch.exportApplet(Sketch.java:1627)
at processing.app.Sketch.exportApplet(Sketch.java:1599)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
at java.lang.Thread.run(Thread.java:680)


Thanks.

mepster

#1
Nov 16, 2012, 07:55 am Last Edit: Nov 16, 2012, 08:28 am by mepster Reason: 1
Yes I can confirm the bug. I found it with my own sketch, also tried your sketch.

Error messages are same as yours, verbatim - all the same java line numbers.

I am also on Arduino.app 1.0.2.

I am on Mountain Lion 10.8.2, however.

Also, I am using a Micro instead of a Leonardo. (I believe they are electrically identical?)

I don't get it with every upload, maybe 70% of uploads?

Yes my sketch also runs fine despite the error.

Oh - I just tried again and got a different error:
processing.app.SerialException: Error touching serial port '/dev/tty.usbmodemfd121'.
   at processing.app.Serial.touchPort(Serial.java:123)
   at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:201)
   at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
   at processing.app.Sketch.upload(Sketch.java:1671)
   at processing.app.Sketch.exportApplet(Sketch.java:1627)
   at processing.app.Sketch.exportApplet(Sketch.java:1599)
   at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
   at java.lang.Thread.run(Thread.java:680)
Caused by: gnu.io.UnsupportedCommOperationException: Invalid Parameter
   at gnu.io.RXTXPort.setSerialPortParams(RXTXPort.java:171)
   at processing.app.Serial.touchPort(Serial.java:113)
   ... 7 more

Could not repeat that one though. Usually I get your error, and sometimes no error.

Cheers.

P.S. I also have an Uno, and do not get the error with that (everything else the same).

P.P.S. I believe this is the right spot in the source code, see line 119 here:
https://github.com/arduino/Arduino/blob/master/app/src/processing/app/Serial.java

P.P.P.S. :-) Also, Arduino.app 1.5.1 does not produce this exception. (However the Micro is not among the supported boards in 1.5.1 ... I have to select "Leonardo".)

PeterVH

I am affraid it is caused by a fix I submitted for the problem described here: http://code.google.com/p/arduino/issues/detail?id=995&can=1&q=leonardo.

Sorry for that.

When starting an upload the ide sets the baurate to 1200. When the leonardo observes a DTR drop when the baudrate is 1200, it resets.
In order to avoid unintentional autoresets, the fix sets above sets the baudrate back to the value from the preferences, once the upload completed. For some reason this sometimes fails on your system (different locking scheme on the mac: lock still held by avrdude? the reason should be investigated...). On my system (kubuntu/linux 3.0.0-12) it always works correctly. I'll help think about a proper solution (don't have a mac though) :

  • Maybe just catch the exception and ignore it (after all, it can also happen the sketches serial port never comes back, this is of coarse ignored too...)

  • Retry touching a number of times?

  • ...


Fortunately, when the problem occurs, the sketch is already uploaded and works correctly, like you indicated.

Could you submit a bug report?


I'm seeing the same exception with my Arduino Micro. Arduino is v1.0.2:


Binary sketch size: 15,902 bytes (of a 28,672 byte maximum)


processing.app.SerialException: Serial port '/dev/tty.usbmodemfd111' already in use. Try quitting any programs that may be using it.
   at processing.app.Serial.touchPort(Serial.java:119)
   at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:201)
   at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
   at processing.app.Sketch.upload(Sketch.java:1671)
   at processing.app.Sketch.exportApplet(Sketch.java:1627)
   at processing.app.Sketch.exportApplet(Sketch.java:1599)
   at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
   at java.lang.Thread.run(Thread.java:680)

I'm hoping this has now been logged as a bug.

embers

I have received the following error message as well running a Leonardo on Mac OS X 10.8.2 and Arduino version 1.03.

processing.app.SerialException: Serial port '/dev/tty.usbmodemfd141' already in use. Try quitting any programs that may be using it.
   at processing.app.Serial.touchPort(Serial.java:119)
   at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:201)
   at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
   at processing.app.Sketch.upload(Sketch.java:1671)
   at processing.app.Sketch.exportApplet(Sketch.java:1627)
   at processing.app.Sketch.exportApplet(Sketch.java:1599)
   at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
   at java.lang.Thread.run(Thread.java:680)


What is interesting is the sketch will run. If I replace that sketch with a new one (using the OPEN command and a new sketch) I will sometimes get this error or not. In any event the new sketch will run. That is sometimes the IDE will state Upload complete and other times the IDE will state the above error message.  I have rebooted the computer to ensure that the port is identified.  I have tried all the .tty ports with the same result.

I also get the same thing.  I am new to the Arduino.
Blink does work, but I cannot get a servo to work (that could be unrelated to this post).

Here's what I get about 99% of the time when I Upload:

processing.app.SerialException: Serial port '/dev/tty.usbmodem1411' already in use. Try quitting any programs that may be using it.
   at processing.app.Serial.touchPort(Serial.java:119)
   at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:201)
   at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67)
   at processing.app.Sketch.upload(Sketch.java:1671)
   at processing.app.Sketch.exportApplet(Sketch.java:1627)
   at processing.app.Sketch.exportApplet(Sketch.java:1599)
   at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380)
   at java.lang.Thread.run(Thread.java:680)


I am running Arduino 1.0.3
Arduino Micro Board
Mac OS X 10.7.5
I have disabled the Firewall, shut off Bluetooth, and nothing else is connected via USB.

What else can I do?

Go Up