EasyManua.ls Logo

LEGO MINDSTORMS Robots

LEGO MINDSTORMS Robots
226 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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) {
Page 239
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 {

Table of Contents

Related product manuals