Device discovery & connection
Android Java SDK: Device discovery & connection
Device discovery & connection
The app selects and authorizes Android USB first. Create com.qnbot.sdk.android.UsbSerialTransport, show inventory() candidates, and use the chosen item's name as the explicit port. Call requestPermission(port, result), await the system result, then recheck hasPermission(port) before constructing the SDK.
The current transport supports single-port CDC ACM. Implement SerialTransport for other chipsets or multiple ports. Do not open every inventoried device. Close transport if selection ends before SDK acceptance; after acceptance, SDK destruction releases it.
Configure and select
Add ExoConfig.builder().name("primary").connection(SerialConnection.port(selectedPort)) to SdkConfig, then create the SDK with Context and transport. Use sdk.exo().device("primary"), or device() when exactly one is configured. Refine ambiguous selections and fix missing configuration rather than choosing an arbitrary device.
Discovery scope
After USB permission is granted, call Sdk.discoverExos(context, transport) on a worker thread. The public DiscoverExos example prints each candidate's transport type, port and device information, or the typed per-port error that replaced them.
import android.content.Context;
import com.qnbot.sdk.Sdk;
import com.qnbot.sdk.android.SerialTransport;
import com.qnbot.sdk.exo.DiscoveredExo;
import com.qnbot.sdk.exo.ExoDeviceInfo;
import java.io.IOException;
import java.util.List;
/**
* Lists the Exo candidates reachable through the caller's Android serial transport.
*
* <p>Supply an Android {@link Context} and an authorized {@link SerialTransport}. Each candidate
* prints its port and device information, or the per-port discovery error that replaced them.
*/
public final class DiscoverExos {
private DiscoverExos() {}
public static void run(Context context, SerialTransport transport) throws IOException {
List<DiscoveredExo> found = Sdk.discoverExos(context, transport);
for (DiscoveredExo device : found) {
if (device.error != null) {
System.out.println("port=" + device.port + " error=" + device.error.code
+ " message=" + device.error.message);
continue;
}
ExoDeviceInfo info = device.deviceInfo;
System.out.println("transport=" + device.transportType + " port=" + device.port
+ " product=" + info.product + " serial=" + info.serialNumber);
}
}
}Discovery closes temporary endpoints and leaves the authorized transport available for SDK construction.
Discovery also includes required transportType, typed as ExoTransportType with the current value SERIAL. Partial and error records retain provenance. Use matching Java and native libraries from the same component delivery.
Device information
Before start, read the selected device's identity, firmware and capabilities with exo.device().getDeviceInfo(). The public DeviceInfo example prints the product, protocol version, serial number and hardware name, the firmware components, the encoder/handset/IMU component counts, and the telemetry/encoder/handset/IMU/haptics/wireless capability flags.
import android.content.Context;
import com.qnbot.sdk.Sdk;
import com.qnbot.sdk.SdkConfig;
import com.qnbot.sdk.android.SerialTransport;
import com.qnbot.sdk.config.SerialConnection;
import com.qnbot.sdk.exo.Exo;
import com.qnbot.sdk.exo.ExoConfig;
import com.qnbot.sdk.exo.ExoDeviceInfo;
/**
* Reads Exo product, firmware, component and capability information before start.
*
* <p>Supply an Android {@link Context}, an authorized {@link SerialTransport} and the device
* port; the SDK closes when the read completes.
*/
public final class DeviceInfo {
private DeviceInfo() {}
public static void run(Context context, SerialTransport transport, String port) throws Exception {
SdkConfig config = SdkConfig.builder()
.device(ExoConfig.builder()
.connection(SerialConnection.port(port))
.build())
.build();
try (Sdk sdk = new Sdk(config, context, transport); Exo exo = sdk.exo()) {
ExoDeviceInfo info = exo.device().getDeviceInfo();
System.out.println("product=" + info.product + " protocol=" + info.protocolVersion.major + "."
+ info.protocolVersion.minor + " serial=" + info.serialNumber
+ " hardware=" + info.hardwareName);
System.out.println("firmware=" + info.firmware.platform + "." + info.firmware.revision + "."
+ info.firmware.feature + "." + info.firmware.build);
System.out.println("encoders=" + info.components.encoders.available + "/"
+ info.components.encoders.totalSlots + " handsets=" + info.components.handsets.available
+ "/" + info.components.handsets.totalSlots + " imus=" + info.components.imus.available
+ "/" + info.components.imus.totalSlots);
System.out.println("capabilities telemetry=" + info.capabilities.telemetry
+ " encoders=" + info.capabilities.encoders + " handsets=" + info.capabilities.handsets
+ " imus=" + info.capabilities.imus + " haptics=" + info.capabilities.haptics
+ " wireless=" + info.capabilities.wireless);
}
}
}DeviceInfo.run takes the authorized transport and the explicit port; it closes the SDK when the read completes. Check capabilities before reading optional handset or IMU payloads.