Skip to content

Commit 377166f

Browse files
authored
IEP-965: Bug fix for serial port exception (#772)
The serial ports descriptor was initially split by the hyphen(-) which can be a valid serial port name char as well so instead now we are using the good old trust space( ) char to keep it clean and simple. Also did some ui improvements to help keep the user interface active while background tasks can take a while to resolve.
1 parent 1ffa07b commit 377166f

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

bundles/com.espressif.idf.launch.serial.ui/src/com/espressif/idf/launch/serial/ui/internal/NewSerialFlashTargetWizardPage.java

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353

5454
public class NewSerialFlashTargetWizardPage extends WizardPage {
5555

56-
private static final String PORT_NAME_DESCRIPTOR_SPLITOR = "-"; //$NON-NLS-1$
56+
private static final String PORT_NAME_DESCRIPTOR_SPLITOR = " "; //$NON-NLS-1$
5757
private static final String OS = "esp32"; //$NON-NLS-1$
5858
private static final String ARCH = "xtensa"; //$NON-NLS-1$
5959

@@ -66,6 +66,7 @@ public class NewSerialFlashTargetWizardPage extends WizardPage {
6666
private Map<String, List<String>> targetPortMap;
6767
private TargetPortInfo targetPortInfo;
6868
private Display display;
69+
private String port;
6970

7071
public NewSerialFlashTargetWizardPage(ILaunchTarget launchTarget) {
7172
super(NewSerialFlashTargetWizardPage.class.getName());
@@ -127,10 +128,13 @@ public void createControl(Composite parent) {
127128

128129
@Override
129130
public void widgetSelected(SelectionEvent e) {
130-
if (targetPortInfo.getState() == Job.RUNNING) {
131-
targetPortInfo.cancel();
132-
}
133-
targetPortInfo.schedule();
131+
display.asyncExec(() -> {
132+
if (targetPortInfo.getState() == Job.RUNNING) {
133+
targetPortInfo.cancel();
134+
}
135+
port = serialPortCombo.getText().split(PORT_NAME_DESCRIPTOR_SPLITOR)[0];
136+
targetPortInfo.schedule();
137+
});
134138
}
135139
});
136140
try {
@@ -154,7 +158,7 @@ public void widgetSelected(SelectionEvent e) {
154158
.getCommPort(targetPort);
155159
targetPort = targetPort + PORT_NAME_DESCRIPTOR_SPLITOR + serialPort.getDescriptivePortName();
156160
int i = 0;
157-
for (String port : ports) {
161+
for (String port : serialPortCombo.getItems()) {
158162
if (port.equals(targetPort)) {
159163
serialPortCombo.select(i);
160164
break;
@@ -265,24 +269,27 @@ public TargetPortInfo(String name) {
265269
@Override
266270
protected IStatus run(IProgressMonitor monitor) {
267271
EspToolCommands espToolCommands = new EspToolCommands();
272+
273+
String message = String.format(Messages.TargetPortUpdatingMessage, port);
268274
display.asyncExec(() -> {
269-
try {
270-
String port = serialPortCombo.getText().split(PORT_NAME_DESCRIPTOR_SPLITOR)[0];
271-
String message = String.format(Messages.TargetPortUpdatingMessage, port);
272-
if (infoArea != null && !infoArea.isDisposed())
273-
infoArea.append(System.lineSeparator() + message);
274-
Process chipInfoProcess = espToolCommands.chipInformation(port);
275-
InputStream targetIn = chipInfoProcess.getInputStream();
276-
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(targetIn));
277-
StringBuilder chipInfo = new StringBuilder();
278-
String readLine;
279-
while ((readLine = bufferedReader.readLine()) != null) {
275+
if (infoArea != null && !infoArea.isDisposed())
276+
infoArea.append(System.lineSeparator() + message);
277+
});
278+
try {
279+
Process chipInfoProcess = espToolCommands.chipInformation(port);
280+
InputStream targetIn = chipInfoProcess.getInputStream();
281+
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(targetIn));
282+
StringBuilder chipInfo = new StringBuilder();
283+
String readLine;
284+
while ((readLine = bufferedReader.readLine()) != null) {
285+
display.asyncExec(() -> {
280286
infoArea.append("."); //$NON-NLS-1$
281-
chipInfo.append(readLine);
282-
chipInfo.append(System.lineSeparator());
283-
}
284-
infoArea.append(System.lineSeparator());
285-
String chipType = extractChipFromChipInfoOutput(chipInfo.toString());
287+
});
288+
chipInfo.append(readLine);
289+
chipInfo.append(System.lineSeparator());
290+
}
291+
String chipType = extractChipFromChipInfoOutput(chipInfo.toString());
292+
display.asyncExec(() -> {
286293
if (StringUtil.isEmpty(chipType)) {
287294
if (infoArea != null && !infoArea.isDisposed())
288295
infoArea.setText(infoArea.getText() + System.lineSeparator()
@@ -291,11 +298,15 @@ protected IStatus run(IProgressMonitor monitor) {
291298
infoArea.append(System.lineSeparator());
292299
infoArea.append(String.format(Messages.TargetPortFoundMessage, port, chipType));
293300
}
294-
} catch (Exception e) {
295-
Logger.log(e);
296-
}
301+
});
302+
} catch (Exception e) {
303+
Logger.log(e);
304+
}
297305

306+
display.asyncExec(() -> {
307+
infoArea.append(System.lineSeparator());
298308
});
309+
299310
return Status.OK_STATUS;
300311
}
301312

0 commit comments

Comments
 (0)