SDKC++ SDK

Device discovery & connection

Discover wired and wireless gloves, select fixed devices, and connect multiple gloves.

Current version · 2.0.0

Device discovery & connection

Wired and Receiver wireless gloves both use GloveConfig. Connect the Receiver and turn on the gloves you need before creating Sdk; automatic discovery, fixed-port selection, and hand-side selection use the same configuration.

Device discovery

To list devices before creating the Sdk, call qnbot::discover_gloves(). The returned std::vector<qnbot::DiscoveredGlove> contains the serial port, left/right hand, device SN, and an optional per-device error:

const auto devices = qnbot::discover_gloves();
const auto selected = std::find_if(
    devices.begin(), devices.end(),
    [](const auto& device) {
        return (device.transport_type == qnbot::GloveTransportType::serial ||
                device.transport_type == qnbot::GloveTransportType::receiver_peer) &&
               !device.error && device.hand.has_value();
    });

if (selected != devices.end() && selected->hand) {
    qnbot::SerialConnection connection;
    connection.port = selected->port;
    qnbot::GloveConfig config{*selected->hand, connection};
}

When the port is occupied by another process, the device is still kept in the result, port is usable, and the condition is identified by qnbot::GloveDiscoveryErrorCode::port_busy (stable error code PORT_BUSY). Program logic should test the enum and must not parse the diagnostic message. The discovery result is a snapshot of the moment of the call; rediscover after devices are plugged or unplugged. For a complete example, see discover_gloves.cpp.

transport_type is serial for a wired glove and receiver_peer for a wireless glove. Each online Receiver glove has a separate record; records from one Receiver may share port, so distinguish them by hand and sn. receiver_usb identifies a Receiver USB entry, not a selectable glove. The example selects the first usable glove; filter by the required hand or port when several candidates exist.

Single glove

The single-glove scenario automatically discovers the only connected supported glove:

qnbot::SdkConfig config;
config.devices = {qnbot::GloveConfig{}};
qnbot::Sdk sdk(std::move(config));

A single-glove declaration without a configured side still requires exactly one unoccupied candidate. Fixed selection is only needed when automatic discovery cannot work, see Connecting the device.

One glove means one usable glove endpoint, not one USB port. If both hands are online on a Receiver, specify side to select one; the other hand need not be online when unused.

Two gloves

When connecting one left glove and one right glove at the same time, you only need to declare the side; there is no need to set connection explicitly:

qnbot::GloveConfig left;
left.side = qnbot::Side::left;

qnbot::GloveConfig right;
right.side = qnbot::Side::right;

qnbot::SdkConfig config;
config.devices = {left, right};

The SDK assigns wired or wireless gloves by side; serial enumeration order does not determine the streams. Each glove is assigned at most once: an ordinary wired port serves one glove, while opposite hands on one Receiver can share its port. Construction fails when a side is missing, same-side candidates are ambiguous, or identity verification fails. Use distinct logical names for same-side gloves (at most one may be unnamed), and pin them with distinct port or serial_number values.

When no device locating information is provided, SerialConnection{} uses the automatic discovery and side assignment described above.

Multiple gloves

Each enabled glove must have a unique name/side pair. At most one glove on a given side may omit its name; give the others distinct nonempty names. Naming every same-side glove is recommended. Opposite sides may share a name and can be selected by combining name and side.

When connecting three or more gloves, at least two are on the same side. To select each glove individually, set a unique name for each entry and use different port or serial_number values to pin down same-side gloves. name is only used by the application to select a glove and does not replace device locating information. At most one glove on a given side may be unnamed; different ports or serial numbers do not make duplicate name/side pairs valid.

qnbot::SerialConnection left_primary_connection;
left_primary_connection.port = "/dev/ttyUSB0";
qnbot::GloveConfig left_primary{qnbot::Side::left, left_primary_connection};
left_primary.name = "left-primary";

qnbot::SerialConnection left_backup_connection;
left_backup_connection.port = "/dev/ttyUSB1";
qnbot::GloveConfig left_backup{qnbot::Side::left, left_backup_connection};
left_backup.name = "left-backup";

qnbot::GloveConfig right;
right.side = qnbot::Side::right;
right.name = "right";

qnbot::SdkConfig config;
config.devices = {left_primary, left_backup, right};
qnbot::Sdk sdk(std::move(config));
auto selected = sdk.glove().device("left-primary");

No physical glove, or integrating your own device? Both cases can feed external hand frames frame by frame, and they are read through the same paths as a physical glove. See External input for the configuration and frame constraints.

Connecting the device

Sdk construction completes device discovery and identity verification before returning; start() establishes the continuously running connection and data streams, see Lifecycle. Use the connection options below when you need to pin a specific device.

A fixed port or serial number

A fixed deployment can specify the serial port:

qnbot::SerialConnection connection;
connection.port = "/dev/ttyUSB0";

qnbot::GloveConfig device_config{qnbot::Side::right, connection};
device_config.name = "primary";

When the SDK can recognize the port as a supported directly wired glove and both port and side are explicitly provided, the SDK still verifies the device identity first. For older directly wired gloves that cannot report a device identity, the SDK continues to connect using the configured serial port and left/right hand, and emits an "identity not verified" warning. Reconnection after a drop retries only that port and cannot confirm whether the recovered device is still the same physical glove. Automatic discovery, providing only port, providing only side, selecting by serial_number, and unrecognized port types still require device identity verification and cannot use this compatibility behavior.

You can also select by USB serial number. An empty SerialConnection{} uses automatic discovery:

qnbot::SerialConnection by_serial;
by_serial.serial_number = "YOUR-SERIAL-NUMBER";

When device locating information is set explicitly, auto_discover=true, port and serial_number are mutually exclusive; baudrate is optional.

Wireless gloves (Receiver)

Connect the Receiver to the computer over USB and turn on the gloves you need. Declare one GloveConfig per glove and set connection.port to the Receiver port. Opposite hands can use the same port; the SDK shares the physical connection:

#include <qnbot/glove.hpp>
#include <utility>

qnbot::SerialConnection receiver;
receiver.port = "/dev/ttyACM0";
qnbot::GloveConfig left{qnbot::Side::left, receiver};
left.name = "left";
qnbot::GloveConfig right{qnbot::Side::right, receiver};
right.name = "right";

qnbot::SdkConfig config;
config.devices = {left, right};
qnbot::Sdk sdk(std::move(config));

Replace the example port with the actual Receiver port; keep only one declaration for single-hand use. Wired and wireless gloves can be mixed using their respective ports. See GloveConfig for port-sharing and identity requirements.

Use the same pose(), skeleton(), output(), and haptics() APIs after connection. Compatible wireless gloves provide raw IMU. See Common questions for offline gloves.

Select and inspect a device

Sdk construction completes device discovery and identity verification before returning. Once creation succeeds, you can select devices and prepare data reads; continuous callbacks are best registered before start(). When relying on serial auto-discovery, Sdk construction accesses the devices; a discovery failure or unmet identity constraints directly makes construction fail.

Direct gloves are allocated when the Sdk is created, as shown below:

Rendering diagram

Select a device

When only one glove is enabled in the configuration, you can select it directly:

auto glove = sdk.glove();
auto device = glove.device();

In multi-glove scenarios, you can select by side:

auto glove = sdk.glove();
auto left = glove.device(qnbot::Side::left);
auto right = glove.device(qnbot::Side::right);
auto named_left = glove.device("shared-name", qnbot::Side::left);
  • When no device matches, NotFoundSelectionError is thrown.
  • When multiple devices match, AmbiguousSelectionError is thrown.
  • candidates() provides the selectable devices, and selector_kind() and selector_value() describe this selection.

Selecting by name and side

For example, name the main left and right gloves primary and the backup left glove backup. The two left gloves need different names; for physical gloves, also pin them to different ports or serial numbers.

auto left = glove.device("primary", qnbot::Side::left);
auto right = glove.device("primary", qnbot::Side::right);
auto backup = glove.device("backup");
const auto source_id = left.source_id();

In this three-glove configuration, primary alone matches both hands and left side alone matches two gloves, so both raise AmbiguousSelectionError. Name and side together select their intersection; no match raises NotFoundSelectionError.

Always read source_id from the selected device. Do not construct it from an SN, port, or name, or parse it to identify hardware; read get_device_info().canonical_sn for the serial number. A verified glove’s logical source follows its configured name and side, or its side when unnamed. Replacing hardware under the same name and side does not change that logical identifier to a new SN. This does not make old calibration valid for replacement hardware; see Migration.

device_selection.cpp demonstrates the selections above with three external gloves.

Inspect the device

device.get_device_info() returns the verified GloveDeviceInfo snapshot saved during SDK construction, including canonical_sn, device type, model, firmware version, hand, and hand source; it does not resend the identity command each time.

Device identifiers serve different purposes:

IdentifierSourcePurpose
nameGloveConfig::name, optionalThe application's own logical name; it can be left empty when the device is unique or can already be distinguished by side; it is recommended for multiple devices on the same side or complex topologies, and is used to select with glove.device(name)
source_idGloveDevice::source_id()Stable logical routing identifier built from configured name and side
canonical_snget_device_info().canonical_snThe canonical SN verified through device identity; the application should not derive it from the port or name
transport_typedevice.get_device_info().transport_typeserial for a wired glove; receiver_peer for a wireless glove

For legacy firmware connected with an explicit port + side that cannot provide an identity, the SDK does not fabricate these fields; the call throws UnavailableFeatureError, and capabilities that depend on a verified identity are unavailable.

source_id is not the hardware serial number. Read canonical_sn when hardware identity is required, and do not parse the source_id string format.

GloveDevice's start() and stop() act only on that device. The same-named operations on Glove act on all configured gloves.