Skip to content

5.3 Multi Device

Since Version 6.0, we support connecting multiple devices at once.

To allow this, you first need to enable multi device support. By default, connecting more than one device will throw an error.

fun main() {
    val connectionManager = ConnectionManager()

    // Set this before connecting the first device
    connectionManager.setConnectionStrategy(IConnectionStrategy.MULTI_DEVICE_SLOTS).await()

    val eventHandler = ExampleEventHandler()
    connectionManager.startReceivingEvents(eventHandler)
    connectionManager.displayConnectionActivity()

    // Prevent app from exiting
    while (true) {
        Thread.sleep(10)
    }
}
class Main {
    public static void main(String[] args) throws InterruptedException {
        ConnectionManager connectionManager = new ConnectionManager();

        // Set this before connecting the first device
        connectionManager.setConnectionStrategy(IConnectionStrategy.COMPANION.MULTI_DEVICE_SLOTS);

        ExampleDelegate delegate = new ExampleDelegate();
        connectionManager.startReceivingEvents(delegate);
        connectionManager.displayConnectionActivity(false);

        // Prevent app from exiting
        while (true) {
            Thread.sleep(10);
        }
    }
}

Every callback method like didScanBarcode or didTouch already provides a reference to the device that initiated the respective action.

override fun didTouch(
    device: NIMMSTADevice,
    x: Double,
    y: Double,
    screen: Int,
    event: TouchEvent
) {
    // This will print the address of the device where the screen was touched
    println(device.address)
}
@Override
public void didTouch(
    @NotNull NIMMSTADevice nimmstaDevice,
    double x,
    double y,
    int screen,
    @NotNull TouchEvent touchEvent
) {
    // This will print the address of the device where the screen was touched
    System.out.println(nimmstaDevice.getAddress());
}

The advanced API can be accessed via the ConnectionManager.

// Retrieve a set of all devices
// This includes all devices that were connected at some point during the runtime of the program
// The order is preserved even if a device is reconnected
connectionManager.devices.all

// Retrieve a set of all connected devices
// Filters out all devices that are not currently connected
connectionManager.devices.connectedDevices

// Retrieve a set of all devices that are currently charging
// Check out the other filters as well
connectionManager.devices.filter(DeviceFilter.CHARGING)

// Retrieve a device by Address or ConnectionCode
connectionManager.devices[HS50ConnectionCode("ABCDE")]
connectionManager.devices[BluetoothDeviceMacAddress("FF:FF:FF:FF:FF:FF")]
// Retrieve a set of all devices
// This includes all devices that were connected at some point during the runtime of the program
// The order is preserved even if a device is reconnected
connectionManager.getDevices().getAll();

// Retrieve a set of all connected devices
// Filters out all devices that are not currently connected
connectionManager.getDevices().getConnectedDevices();

// Retrieve a set of all devices that are currently charging
// Check out the other filters as well
connectionManager.getDevices().filter(DeviceFilter.CHARGING);

// Retrieve a device by Address or ConnectionCode
connectionManager.getDevices().get(new HS50ConnectionCode("ABCDE"));
connectionManager.getDevices().get(new BluetoothDeviceMacAddress("FF:FF:FF:FF:FF:FF"));