import java.io.∗;
import java.util.∗;
import javax.comm.∗;
public class Download {
public static void main (String[] args) {
String filename = args[args.length - 1];
String portName = "COM1";
for (int i = 0; i < args.length - 2; i++) {
if (args[i].equals("-port")) portName = args[i + 1];
}
try { new Download (filename, portName); }
catch (NoSuchPortException nspe) {
System.out.println("Sorry, I don't know about the " +
portName + " port. ");
}
catch (PortInUseException piue) {
System.out.println("Sorry, somebody else is using " +
portName + ".");
}
catch (UnsupportedCommOperationException ucoe) {
System.out.println(ucoe);
}
catch (IOException ioe) {
System.out.println("An IOException occurred: " + ioe);
}
}
private SerialPort mPort;
private Reader mFileIn;
private Writer mOut;
private PortListener mPortListener;
private static final int kCharSleep = 20;
private static final int kTimeOut = 800;
public Download(String filename, String portName)
throws NoSuchPortException, PortInUseException,
UnsupportedCommOperationException, IOException {
initialize(portName);
mFileIn = new FileReader (filename);
run();
}
protected void initialize(String portName)
throws NoSuchPortException, PortInUseException,
UnsupportedCommOperationException, IOException {
CommPortIdentifier id =
CommPortIdentifier.getPortIdentifier(portName);
mPort = (SerialPort)id.open("Download", 1000);
Page 237
Need help?
Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?
Questions and answers