Exemplo n.º 1
0
  public static void main(String args[]) {
    ipcon = new IPConnection();

    while (true) {
      try {
        ipcon.connect(HOST, PORT);
        break;
      } catch (java.net.UnknownHostException e) {
      } catch (java.io.IOException e) {
      } catch (com.tinkerforge.AlreadyConnectedException e) {
      }

      try {
        Thread.sleep(1000);
      } catch (InterruptedException ei) {
      }
    }

    smokeListener = new SmokeListener(ipcon);
    ipcon.addEnumerateListener(smokeListener);
    ipcon.addConnectedListener(smokeListener);

    while (true) {
      try {
        ipcon.enumerate();
        break;
      } catch (com.tinkerforge.NotConnectedException e) {
      }

      try {
        Thread.sleep(1000);
      } catch (InterruptedException ei) {
      }
    }

    try {
      System.out.println("Press key to exit");
      System.in.read();
    } catch (java.io.IOException e) {
    }

    try {
      ipcon.disconnect();
    } catch (com.tinkerforge.NotConnectedException e) {
    }
  }
Exemplo n.º 2
0
  public void connected(short connectedReason) {
    if (connectedReason == IPConnection.CONNECT_REASON_AUTO_RECONNECT) {
      System.out.println("Auto Reconnect");

      while (true) {
        try {
          ipcon.enumerate();
          break;
        } catch (com.tinkerforge.NotConnectedException e) {
        }

        try {
          Thread.sleep(1000);
        } catch (InterruptedException ei) {
        }
      }
    }
  }
 // THIS METHOD IS AUTOMATICALLY CALLED IN THE BACKGROUND:
 @Override
 protected boolean createKeys(final List<DeviceIdentifier> list) {
   try {
     ipc = new IPConnection(host, port);
     ipc.enumerate(
         new IPConnection.EnumerateListener() {
           @Override
           public void enumerate(String uid, String name, short stackID, boolean isNew) {
             if (isNew) {
               list.add(new DeviceIdentifier(name, uid, stackID));
             } else {
               refresh(false);
             }
           }
         });
   } catch (IOException ex) {
   }
   return true;
 }