- Log.info(this, "resetting device");
- sp.setDTR(true);
- sp.setRTS(true);
- Thread.sleep(500);
- Log.info(this, "deasserting reset signal");
- sp.setDTR(false);
- sp.setRTS(false);
- Thread.sleep(100);
- } catch (InterruptedException e) { throw new DeviceException(e); }
+ if (reader != null) {
+ reader.start();
+ reader = null;
+ }
+ ByteCallback bc = new ByteCallback() {
+ public synchronized void call(byte b) throws Exception {
+ retval =
+ ((b & 0xff) << 24) |
+ ((in.read() & 0xff) << 16) |
+ ((in.read() & 0xff) << 8) |
+ ((in.read() & 0xff) << 0);
+ this.notify();
+ }
+ };
+ synchronized(bc) {
+ callbacks.add(bc);
+ out.writeByte(6);
+ out.flush();
+ bc.wait();
+ }
+ return retval;
+ } catch (Exception e) { throw new DeviceException(e); }
+ }
+
+ public static interface ByteCallback {
+ public void call(byte b) throws Exception;
+ }
+
+ private Vector callbacks = new Vector();
+
+ private Thread reader = new Thread() {
+ public void run() {
+ System.out.println("*** reader thread begun");
+ while(true) {
+ try {
+ byte b = in.readByte();
+ ByteCallback bc = (ByteCallback)callbacks.remove(0);
+ bc.call(b);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ };
+
+ public synchronized void readBus(ByteCallback bc) throws DeviceException {
+ try {
+ callbacks.add(bc);
+ out.writeByte(2);
+ out.flush();
+ if (reader != null) {
+ reader.start();
+ reader = null;
+ }
+ } catch (IOException e) { throw new DeviceException(e); }
+ }
+
+ public synchronized void readInterrupts(ByteCallback bc) throws DeviceException {
+ try {
+ callbacks.add(bc);
+ out.writeByte(6);
+ out.flush();
+ if (reader != null) {
+ reader.start();
+ reader = null;
+ }
+ } catch (IOException e) { throw new DeviceException(e); }