@@ -106,36 +106,40 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
106
106
t = prefs .get ("upload.wait_for_upload_port" );
107
107
boolean waitForUploadPort = (t != null ) && t .equals ("true" );
108
108
109
- String uploadPort = prefs .getOrExcept ("serial.port" );
109
+ String userSelectedUploadPort = prefs .getOrExcept ("serial.port" );
110
+ String actualUploadPort = null ;
110
111
111
112
if (doTouch ) {
112
113
try {
113
114
// Toggle 1200 bps on selected serial port to force board reset.
114
115
List <String > before = Serial .list ();
115
- if (before .contains (uploadPort )) {
116
+ if (before .contains (userSelectedUploadPort )) {
116
117
if (verbose )
117
118
System .out .println (
118
- I18n .format (_ ("Forcing reset using 1200bps open/close on port {0}" ), uploadPort ));
119
- Serial .touchForCDCReset (uploadPort );
119
+ I18n .format (_ ("Forcing reset using 1200bps open/close on port {0}" ), userSelectedUploadPort ));
120
+ Serial .touchForCDCReset (userSelectedUploadPort );
120
121
}
121
122
Thread .sleep (400 );
122
123
if (waitForUploadPort ) {
123
124
// Scanning for available ports seems to open the port or
124
125
// otherwise assert DTR, which would cancel the WDT reset if
125
126
// it happened within 250 ms. So we wait until the reset should
126
127
// have already occured before we start scanning.
127
- uploadPort = waitForUploadPort (uploadPort , before );
128
+ actualUploadPort = waitForUploadPort (userSelectedUploadPort , before );
128
129
}
129
130
} catch (SerialException e ) {
130
131
throw new RunnerException (e );
131
132
} catch (InterruptedException e ) {
132
133
throw new RunnerException (e .getMessage ());
133
134
}
134
- prefs .put ("serial.port" , uploadPort );
135
- if (uploadPort .startsWith ("/dev/" )) {
136
- prefs .put ("serial.port.file" , uploadPort .substring (5 ));
135
+ if (actualUploadPort == null ) {
136
+ actualUploadPort = userSelectedUploadPort ;
137
+ }
138
+ prefs .put ("serial.port" , actualUploadPort );
139
+ if (actualUploadPort .startsWith ("/dev/" )) {
140
+ prefs .put ("serial.port.file" , actualUploadPort .substring (5 ));
137
141
} else {
138
- prefs .put ("serial.port.file" , uploadPort );
142
+ prefs .put ("serial.port.file" , actualUploadPort );
139
143
}
140
144
}
141
145
@@ -158,9 +162,9 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
158
162
throw new RunnerException (e );
159
163
}
160
164
165
+ String finalUploadPort = null ;
161
166
if (uploadResult && doTouch ) {
162
167
try {
163
- String previousUploadPort = PreferencesData .get ("serial.port" );
164
168
if (waitForUploadPort ) {
165
169
// For Due/Leonardo wait until the bootloader serial port disconnects and the
166
170
// sketch serial port reconnects (or timeout after a few seconds if the
@@ -170,7 +174,11 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
170
174
long started = System .currentTimeMillis ();
171
175
while (System .currentTimeMillis () - started < 2000 ) {
172
176
List <String > portList = Serial .list ();
173
- if (portList .contains (previousUploadPort )) {
177
+ if (portList .contains (actualUploadPort )) {
178
+ finalUploadPort = actualUploadPort ;
179
+ break ;
180
+ } else if (portList .contains (userSelectedUploadPort )) {
181
+ finalUploadPort = userSelectedUploadPort ;
174
182
break ;
175
183
}
176
184
Thread .sleep (250 );
@@ -181,7 +189,13 @@ public boolean uploadUsingPreferences(File sourcePath, String buildPath, String
181
189
}
182
190
}
183
191
184
- BaseNoGui .selectSerialPort (uploadPort );
192
+ if (finalUploadPort == null ) {
193
+ finalUploadPort = actualUploadPort ;
194
+ }
195
+ if (finalUploadPort == null ) {
196
+ finalUploadPort = userSelectedUploadPort ;
197
+ }
198
+ BaseNoGui .selectSerialPort (finalUploadPort );
185
199
return uploadResult ;
186
200
}
187
201
0 commit comments