Connecting a Socket Mobile Device

Socket Mobile Companion

The easiest way to connect a Socket Mobile Device to a host independently of a Capture enabled app is to use the Socket Mobile Companion app.

Socket Mobile Companion for iOS can be found on the App Store, and for Android on Play Store .

Connecting with a Socket Mobile barcode scanner

The Socket Mobile barcode scanners use Bluetooth for connecting to the host.

For an Android host, Socket Mobile Companion takes care of all the details to connect and pair to a Socket Mobile scanner.

For iOS host, the application needs to be configured with some specific settings that include an External Accessory Protocol String and some Privacy Bluetooth Description strings.

The application is aware when the scanner is connected and ready to be used when it receives the onDeviceArrival callback (or the DeviceArrival notification if using the low-level API).

Connecting a BLE or NFC Device

The Socket Mobile Contactless NFC Reader/Writer D600, S550, S370, and the new S721 barcode scanner use Bluetooth Low Energy (BLE) to connect to the host.

Discovering Nearby Devices

Start a BLE or Classic Bluetooth scan:

// BLE scan (for S721, D600, S550, S370, S320...)
await helper.addBluetoothDevice(BluetoothDiscoveryMode.BluetoothLowEnergy);

// Classic Bluetooth scan (for S720, D720, S820...)
await helper.addBluetoothDevice(BluetoothDiscoveryMode.BluetoothClassic);

Each nearby device fires the onDiscoveredDevice callback with a DiscoveredDeviceInfo object containing name, identifierUuid, and serviceUuid. When the scan ends, onDiscoveryEnd is called.

Note

Deduplicate by identifierUuid when accumulating discovered devices — the SDK may fire onDiscoveredDevice more than once for the same device during a scan.

Connecting a Discovered Device

Pass the DiscoveredDeviceInfo to connectDiscoveredDevice:

const connectDevice = async (device: DiscoveredDeviceInfo) => {
    try {
        await helper.connectDiscoveredDevice(device);
        // On success, onDeviceArrival fires with a CaptureHelperDevice
    } catch (err) {
        console.error('Failed to connect:', err?.error?.message);
    }
};

Disconnecting a Device

To disconnect a connected BLE device:

const disconnectDevice = async (device: CaptureHelperDevice) => {
    try {
        await helper.removeBleDevice(device);
        // On success, onDeviceRemoval fires
    } catch (err) {
        console.error('Error disconnecting:', err?.error?.code);
    }
};

You can also disconnect using the original discovered device info:

await helper.disconnectFromDiscoveredDevice(discoveredDevice);

Using the Low-Level API

If you need full control, you can still use the low-level CaptureRn API directly. The BLE connection flow is handled by a Capture Device Manager. Capture sends a DeviceManagerArrival event when BLE is supported on the host. Open it the same way you open a regular device, then hold onto the reference:

case CaptureEventIds.DeviceManagerArrival:
    const newBleDeviceManager = new CaptureRn();
    let {name, guid} = e.value;
    newBleDeviceManager.openDevice(guid, capture).then((result) => {
        setStatus(`result of opening ${name} : ${result}`);
        setBleDeviceManagerCapture(newBleDeviceManager);
    });
    break;
case CaptureEventIds.DeviceManagerRemoval:
    if (bleDeviceManagerCapture) {
        bleDeviceManagerCapture.close();
        setBleDeviceManagerCapture(null);
    }
    break;

Then start a scan by calling setProperty on the root capture instance:

import { BluetoothDiscoveryMode } from 'react-native-capture';

const launchBluetoothLeDiscovery = async () => {
    const property = new CaptureProperty(
        CapturePropertyIds.AddDevice,
        CapturePropertyTypes.Byte,
        BluetoothDiscoveryMode.BluetoothLowEnergy,
    );
    try {
        await capture.setProperty(property);
    } catch (res) {
        const {code, message} = res.error;
        setStatus(`BLE scan failed: ${code}: ${message}`);
    }
};

Handle discovery events in your onCaptureEvent callback:

case CaptureEventIds.DeviceDiscovered:
    if (e.value?.identifierUuid) {
        const existing = stateRef.current.discoveredDevices;
        if (!existing.find(d => d.identifierUuid === e.value.identifierUuid)) {
            setDiscoveredDevices([...existing, e.value]);
        }
    }
    break;
case CaptureEventIds.DiscoveryEnd:
    setStatus('Discovery has ended');
    break;

Connect a discovered device by calling setProperty on the BLE Device Manager instance:

const connectDiscoveredDevice = async (device) => {
    if (!bleDeviceManagerCapture) return;
    const property = new CaptureProperty(
        CapturePropertyIds.ConnectDiscoveredDevice,
        CapturePropertyTypes.String,
        device.identifierUuid + ';' + device.serviceUuid,
    );
    try {
        await bleDeviceManagerCapture.setProperty(property);
    } catch (res) {
        const {code, message} = res.error;
        setStatus(`Failed to connect: ${code}: ${message}`);
    }
};

Disconnect using RemoveDevice on the root capture instance:

const disconnectDevice = async (device) => {
    const property = new CaptureProperty(
        CapturePropertyIds.RemoveDevice,
        CapturePropertyTypes.String,
        device.guid,
    );
    try {
        await capture.setProperty(property);
    } catch (res) {
        setStatus(`Error disconnecting: ${res?.error?.code}`);
    }
};