1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-01-18 07:52:14 +01:00

Showing dialog when serial port not found on upload.

This commit is contained in:
David A. Mellis 2010-11-24 14:03:21 -05:00
parent 1d13cd4f89
commit 5d9602a28a
6 changed files with 112 additions and 28 deletions

View File

@ -898,23 +898,7 @@ public class Editor extends JFrame implements RunnerListener {
//public SerialMenuListener() { }
public void actionPerformed(ActionEvent e) {
if(serialMenu == null) {
System.out.println("serialMenu is null");
return;
}
int count = serialMenu.getItemCount();
for (int i = 0; i < count; i++) {
((JCheckBoxMenuItem)serialMenu.getItem(i)).setState(false);
}
JCheckBoxMenuItem item = (JCheckBoxMenuItem)e.getSource();
item.setState(true);
String name = item.getText();
//System.out.println(item.getLabel());
Preferences.set("serial.port", name);
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
//System.out.println("set to " + get("serial.port"));
selectSerialPort(((JCheckBoxMenuItem)e.getSource()).getText());
}
/*
@ -929,7 +913,35 @@ public class Editor extends JFrame implements RunnerListener {
*/
}
protected void selectSerialPort(String name) {
if(serialMenu == null) {
System.out.println("serialMenu is null");
return;
}
if (name == null) {
System.out.println("name is null");
return;
}
JCheckBoxMenuItem selection = null;
for (int i = 0; i < serialMenu.getItemCount(); i++) {
JCheckBoxMenuItem item = ((JCheckBoxMenuItem)serialMenu.getItem(i));
if (item == null) {
System.out.println("name is null");
continue;
}
item.setState(false);
if (name.equals(item.getText())) selection = item;
}
if (selection != null) selection.setState(true);
//System.out.println(item.getLabel());
Preferences.set("serial.port", name);
serialMonitor.closeSerialPort();
serialMonitor.setVisible(false);
serialMonitor = new SerialMonitor(Preferences.get("serial.port"));
//System.out.println("set to " + get("serial.port"));
}
protected void populateSerialMenu() {
// getting list of ports
@ -2218,6 +2230,31 @@ public class Editor extends JFrame implements RunnerListener {
return true;
}
public boolean serialPrompt() {
populateSerialMenu();
int count = serialMenu.getItemCount();
Object[] names = new Object[count];
for (int i = 0; i < count; i++) {
names[i] = ((JCheckBoxMenuItem)serialMenu.getItem(i)).getText();
}
String result = (String)
JOptionPane.showInputDialog(this,
"Serial port " +
Preferences.get("serial.port") +
" not found.\n" +
"Retry the upload with another serial port?",
"Serial port not found",
JOptionPane.PLAIN_MESSAGE,
null,
names,
0);
if (result == null) return false;
selectSerialPort(result);
return true;
}
/**
@ -2260,6 +2297,9 @@ public class Editor extends JFrame implements RunnerListener {
} else {
// error message will already be visible
}
} catch (SerialNotFoundException e) {
if (serialPrompt()) run();
else statusNotice("Upload canceled.");
} catch (RunnerException e) {
//statusError("Error during upload.");
//e.printStackTrace();

View File

@ -150,7 +150,7 @@ public class Serial implements SerialPortEventListener {
}
if (port == null) {
throw new SerialException("Serial port '" + iname + "' not found. Did you select the right one from the Tools > Serial Port menu?");
throw new SerialNotFoundException("Serial port '" + iname + "' not found. Did you select the right one from the Tools > Serial Port menu?");
}
}

View File

@ -0,0 +1,39 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Copyright (c) 2007 David A. Mellis
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.app;
public class SerialNotFoundException extends SerialException {
public SerialNotFoundException() {
super();
}
public SerialNotFoundException(String message) {
super(message);
}
public SerialNotFoundException(String message, Throwable cause) {
super(message, cause);
}
public SerialNotFoundException(Throwable cause) {
super(cause);
}
}

View File

@ -1518,8 +1518,8 @@ public class Sketch {
}
return null;
}
protected boolean exportApplet(boolean verbose) throws Exception {
return exportApplet(tempBuildFolder.getAbsolutePath(), verbose);
}
@ -1529,7 +1529,7 @@ public class Sketch {
* Handle export to applet.
*/
public boolean exportApplet(String appletPath, boolean verbose)
throws RunnerException, IOException {
throws RunnerException, IOException, SerialException {
// Make sure the user didn't hide the sketch folder
ensureExistence();
@ -1566,7 +1566,7 @@ public class Sketch {
// }
upload(appletFolder.getPath(), foundName, verbose);
return true;
}
@ -1593,7 +1593,7 @@ public class Sketch {
protected String upload(String buildPath, String suggestedClassName, boolean verbose)
throws RunnerException {
throws RunnerException, SerialException {
Uploader uploader;

View File

@ -29,6 +29,7 @@ package processing.app.debug;
import processing.app.Base;
import processing.app.Preferences;
import processing.app.Serial;
import processing.app.SerialException;
import java.io.*;
import java.util.*;
@ -43,7 +44,7 @@ public class AvrdudeUploader extends Uploader {
// XXX: add support for uploading sketches using a programmer
public boolean uploadUsingPreferences(String buildPath, String className, boolean verbose)
throws RunnerException {
throws RunnerException, SerialException {
this.verbose = verbose;
Map<String, String> boardPreferences = Base.getBoardPreferences();
String uploadUsing = boardPreferences.get("upload.using");
@ -71,7 +72,7 @@ public class AvrdudeUploader extends Uploader {
}
private boolean uploadViaBootloader(String buildPath, String className)
throws RunnerException {
throws RunnerException, SerialException {
Map<String, String> boardPreferences = Base.getBoardPreferences();
List commandDownloader = new ArrayList();
String protocol = boardPreferences.get("upload.protocol");

View File

@ -29,6 +29,8 @@ package processing.app.debug;
import processing.app.Base;
import processing.app.Preferences;
import processing.app.Serial;
import processing.app.SerialException;
import processing.app.SerialNotFoundException;
import java.io.*;
import java.util.*;
@ -63,11 +65,11 @@ public abstract class Uploader implements MessageConsumer {
}
public abstract boolean uploadUsingPreferences(String buildPath, String className, boolean verbose)
throws RunnerException;
throws RunnerException, SerialException;
public abstract boolean burnBootloader(String target, String programmer) throws RunnerException;
protected void flushSerialBuffer() throws RunnerException {
protected void flushSerialBuffer() throws RunnerException, SerialException {
// Cleanup the serial buffer
try {
Serial serialPort = new Serial();
@ -90,6 +92,8 @@ public abstract class Uploader implements MessageConsumer {
serialPort.setRTS(true);
serialPort.dispose();
} catch (SerialNotFoundException e) {
throw e;
} catch(Exception e) {
e.printStackTrace();
throw new RunnerException(e.getMessage());