Beispiel #1
0
  public static ZigBee getLocal() throws ZigBeeException, SerialException {
    synchronized (getLocalLock) {
      if (local != null) {
        if (serialPort == null) {
          serialPort = new Serial();
          if (local.apiMode) {
            serialPort.addListener(local);
          }
        }
        return local;
      }

      try {
        ZigBee l = new ZigBee();
        local = l; // must do this first, otherwise isLocal fails.
        // l isn't really complete yet, but it's good enough for
        // local communications.
        l.enterAPIMode();
        // Just queue up these commands and let the incoming
        // api message processor deal with the results.
        l.executeCommand("SL", null, internalWait);
        l.executeCommand("SH", null, internalWait);
        l.executeCommand("NI", null, internalWait);
        l.executeCommand("MY", null, internalWait);
        l.executeCommand("ID", null, internalWait);
        l.executeCommand("DL", null, internalWait);
        l.executeCommand("DH", null, internalWait);

        // Can't get profile id and manufacturer_id with out doing a loop back node id.
        l.bps = Long.parseLong(Preferences.get("serial.debug_rate"));
        l.parity = Preferences.get("serial.parity").charAt(0);
        return l;
      } catch (Exception e) {
        close();
        local = null;
        e.printStackTrace();
        if (e instanceof ZigBeeException) {
          throw (ZigBeeException) e;
        } else if (e instanceof SerialException) {
          throw (SerialException) e;
        }
        throw new ZigBeeException(e.getMessage());
      }
    }
  }
Beispiel #2
0
 public static void searchForNodesWait() throws ZigBeeException, SerialException {
   ZigBee l = getLocal();
   l.executeCommand("ND", null, 5000);
 }
Beispiel #3
0
 public static void searchForNodes() throws ZigBeeException, SerialException {
   ZigBee l = getLocal();
   l.executeCommand("ND", null, 0);
   // Nodes will automatically be populated as responses come in.
 }