@@ -138,7 +138,7 @@ private boolean uploadViaBootloader(String buildPath, String className)
138
138
// come back, so use a longer time out before assuming that the selected
139
139
// port is the bootloader (not the sketch).
140
140
if (((!Base .isWindows () && elapsed >= 500 ) || elapsed >= 5000 ) && now .contains (uploadPort )) {
141
- if (verbose || Preferences .getBoolean ("upload.verbose" ))
141
+ if (verbose || Preferences .getBoolean ("upload.verbose" ))
142
142
System .out .println ("Uploading using selected port: " + uploadPort );
143
143
caterinaUploadPort = uploadPort ;
144
144
break ;
@@ -174,29 +174,33 @@ private boolean uploadViaBootloader(String buildPath, String className)
174
174
175
175
boolean avrdudeResult = avrdude (commandDownloader );
176
176
177
- // For Leonardo wait until the bootloader serial port disconnects and the sketch serial
178
- // port reconnects (or timeout after a few seconds if the sketch port never comes back).
179
- // Doing this saves users from accidentally opening Serial Monitor on the soon-to-be-orphaned
180
- // bootloader port.
177
+ // For Leonardo wait until the bootloader serial port disconnects and the sketch serial
178
+ // port reconnects (or timeout after a few seconds if the sketch port never comes back).
179
+ // Doing this saves users from accidentally opening Serial Monitor on the soon-to-be-orphaned
180
+ // bootloader port.
181
181
if (true == avrdudeResult && boardPreferences .get ("bootloader.path" ) != null && boardPreferences .get ("bootloader.path" ).equals ("caterina" )) {
182
- try {
183
- Thread .sleep (500 );
184
- } catch (InterruptedException ex ) { }
185
- long timeout = System .currentTimeMillis () + 2000 ;
186
- while (timeout > System .currentTimeMillis ()) {
187
- List <String > portList = Serial .list ();
188
- uploadPort = Preferences .get ("serial.port" );
189
- if (portList .contains (uploadPort )) {
190
- // Remove the magic baud rate (1200bps) to avoid future unwanted board resets
191
- int serialRate = Preferences .getInteger ("serial.debug_rate" );
192
- System .out .println ("Set baud rate to " + serialRate );
193
- Serial .touchPort (uploadPort , serialRate );
194
- break ;
195
- }
196
- try {
197
- Thread .sleep (100 );
198
- } catch (InterruptedException ex ) { }
199
- }
182
+ try {
183
+ Thread .sleep (500 );
184
+ } catch (InterruptedException ex ) { }
185
+ long timeout = System .currentTimeMillis () + 2000 ;
186
+ while (timeout > System .currentTimeMillis ()) {
187
+ List <String > portList = Serial .list ();
188
+ uploadPort = Preferences .get ("serial.port" );
189
+ if (portList .contains (uploadPort )) {
190
+ try {
191
+ Thread .sleep (100 ); // delay to avoid port in use and invalid parameters errors
192
+ } catch (InterruptedException ex ) { }
193
+ // Remove the magic baud rate (1200bps) to avoid future unwanted board resets
194
+ int serialRate = Preferences .getInteger ("serial.debug_rate" );
195
+ if (verbose || Preferences .getBoolean ("upload.verbose" ))
196
+ System .out .println ("Setting baud rate to " + serialRate + " on " + uploadPort );
197
+ Serial .touchPort (uploadPort , serialRate );
198
+ break ;
199
+ }
200
+ try {
201
+ Thread .sleep (100 );
202
+ } catch (InterruptedException ex ) { }
203
+ }
200
204
}
201
205
202
206
return avrdudeResult ;
0 commit comments