mPort.close();
}
catch (IOException ioe) {}
System.exit(0);
}
protected void sendReturn() throws IOException, InterruptedException {
mOut.write('\r');
mOut.flush();
Thread.sleep(kCharSleep);
// Wait for response, or time out.
long savedTime = System.currentTimeMillis();
boolean trucking = true;
while (trucking) {
if (mPortListener.isComplete()) trucking = false;
long currentTime = System.currentTimeMillis();
if (currentTime - savedTime > kTimeOut) trucking = false;
Thread.sleep(20);
}
}
public class PortListener
implements Runnable {
private Thread mThread;
private BufferedReader mIn;
private boolean mComplete = false;
private boolean mError = false;
private String mLastLine;
public PortListener (Reader in) {
mIn = new BufferedReader(in);
mThread = new Thread(this);
mThread.start();
}
public void run() {
String line;
try {
while((line = mIn.readLine()) != null) {
line = line.trim();
mLastLine = line;
if (line.indexOf("ok") != -1) mComplete = true;
if (line.indexOf("redefine") != -1) mComplete = true;
if (line.indexOf("undefined") != -1) mComplete = mError = true;
if (line.length() == 0) mComplete = true;
}
}
catch (IOException ioe) {
System.out.println("PortListener: ioe " + ioe);
}
}
public void stop() throws IOException {
Page 239
Need help?
Do you have a question about the MINDSTORMS Robots and is the answer not in the manual?