private void masterDisconnect(final BrickMaster master) {
   final MasterListener listener = this.listenerMap.get(master);
   if (listener != null) {
     master.removeStackCurrentListener(listener);
     master.removeStackVoltageListener(listener);
     master.removeUSBVoltageListener(listener);
     this.listenerMap.remove(master);
   }
 }
Пример #2
0
  // Note: To make the examples code cleaner we do not handle exceptions. Exceptions you
  //       might normally want to catch are described in the documentation
  public static void main(String args[]) throws Exception {
    IPConnection ipcon = new IPConnection(); // Create IP connection
    BrickMaster master = new BrickMaster(UID, ipcon); // Create device object

    ipcon.connect(host, port); // Connect to brickd
    // Don't use device before ipcon is connected

    // Get voltage and current from stack (in mV/mA)
    int voltage = master.getStackVoltage();
    int current = master.getStackCurrent();

    System.out.println("Stack Voltage: " + voltage / 1000.0 + " V");
    System.out.println("Stack Current: " + current / 1000.0 + " A");

    System.console().readLine("Press key to exit\n");
    ipcon.disconnect();
  }
  private void masterConnect(final BrickMaster master) {
    if (!this.listenerMap.containsKey(master)) {
      final MasterListener listener = new MasterListener(master);
      master.addStackCurrentListener(listener);
      master.addStackVoltageListener(listener);
      master.addUSBVoltageListener(listener);

      try {
        master.setStackCurrentCallbackPeriod(250);
        master.setStackVoltageCallbackPeriod(250);
        master.setUSBVoltageCallbackPeriod(250);
      } catch (final TimeoutException e) {
        // master vanished
      } catch (final NotConnectedException e) {
        // master vanished
      }
      this.listenerMap.put(master, listener);
    }
  }