Using Bluetooth Low Energy Devices with Flutter Capture

Bluetooth Low Energy Devices

Some Socket Mobile devices use Bluetooth Low Energy (S721, S550, S370, S320 and D600) to communicate with the host.

Unlike classic Bluetooth scanners that pair at the OS level, Bluetooth LE devices require an explicit discovery and connect flow managed by the SDK.

CaptureHelper handles the Bluetooth LE lifecycle automatically: discovery, connection, and disconnection.

It allows you to manged the whole Bluetooth LE flow from your Flutter app.

Discovery Flow Overview

The Bluetooth LE discovery and connection flow follows these steps:

addBluetoothDevice(mode: BluetoothDiscoveryMode.bluetoothLowEnergy)
        │
        ▼
  SDK scans for nearby Bluetooth LE devices
        │
        ├──▶ onDiscoveredDevice(DiscoveredDeviceInfo)  ← called for each device found
        │
        ▼
  onDiscoveryEnd(result)  ← scan complete
        │
        ▼
connectDiscoveredDevice(device)
        │
        ▼
  onDeviceArrival(CaptureHelperDevice)  ← device is now connected and ready

Register Bluetooth LE Callbacks

When opening CaptureHelper, add the onDiscoveredDevice and onDiscoveryEnd callbacks to handle discovered devices and the end of the discovery scan:

await helper.open(
  appInfo,
  onDeviceArrival: (CaptureHelperDevice device) {
    // A scanner connected — update your UI
  },
  onDeviceRemoval: (CaptureHelperDevice device) {
    // A scanner disconnected
  },
  onDecodedData: (DecodedData data, CaptureHelperDevice device) {
    // Barcode scanned
  },
  onDiscoveredDevice: (DiscoveredDeviceInfo info) {
    // A Bluetooth LE device was found during discovery
    // info.name — device name (e.g. "S721-XXXX")
    // info.identifierUuid — unique Bluetooth LE identifier
    // info.serviceUuid — Bluetooth LE service UUID
  },
  onDiscoveryEnd: (int result) {
    // Bluetooth LE scan finished
  },
);

The DiscoveredDeviceInfo object contains the following fields:

  • name: the device name (e.g. “Socket S721 [7EF619]”)

  • identifierUuid: the unique Bluetooth LE identifier for the device

  • serviceUuid: the Bluetooth LE service UUID

Starting Bluetooth LE Discovery

To start scanning for nearby Bluetooth LE devices, call addBluetoothDevice with the bluetoothLowEnergy mode:

await helper.addBluetoothDevice(mode: BluetoothDiscoveryMode.bluetoothLowEnergy);

For each Bluetooth LE device found in the vicinity, the onDiscoveredDevice callback is fired with a DiscoveredDeviceInfo instance. When the scan completes, the onDiscoveryEnd callback is fired.

Note

You can also discover classic Bluetooth devices using BluetoothDiscoveryMode.bluetoothClassic.

Connecting to a Discovered Device

When the user selects a discovered device from your UI, connect to it using connectDiscoveredDevice:

await helper.connectDiscoveredDevice(device: discoveredDeviceInfo);

Once the connection is established, the onDeviceArrival callback fires with a CaptureHelperDevice instance. The device is then available in helper.getDevices().

Disconnecting and Removing a Bluetooth LE Device

To remove a connected Bluetooth LE device:

await helper.removeBleDevice(device: connectedDevice);

Presence of a Bluetooth Low Energy Device

The presence of a Bluetooth LE device is handled through the onDeviceArrival and onDeviceRemoval callbacks passed to CaptureHelper.open().

onDeviceArrival is called when a device has connected and is ready to use. onDeviceRemoval is called when a device has disconnected and is no longer available.

Note

These callbacks are fired for any Socket Mobile device that connects or disconnects from the host, including both classic Bluetooth and Bluetooth LE devices.

Contactless Reader/Writer Data Format (D600 only)

When the contactless reader/writer reads data from a card, it can display this data in four different formats:

  • Tag Type and ID: DataFormat.tagTypeAndId This Data Format will display the type of card (NFC Forum, etc.) as well as the unique identifier associated with the card.

  • ID Only: DataFormat.idOnly This Data Format will only display the unique identifier from the card. (This format is not supported)

  • Tag Type and Data: DataFormat.tagTypeAndData This Data Format will display the type of card (NFC Forum, etc.) as well as the expected data on the card. This data can be translated into a String format or otherwise if expected.

  • Data Only DataFormat.dataOnly This Data Format will display only the data from the card. (This format is not supported.)

Setting and Getting the current Data Format (D600 only)

You can change the current data format by using one of the aforementioned data format types. Example of setting to DataFormat.tagTypeAndData:

CaptureProperty property = CaptureProperty(
  CapturePropertyIds.DataFormatDevice,
  CapturePropertyTypes.Byte,
  CapturePropertyValues.TagTypeAndData
);

dynamic result = await deviceCapture.setProperty(property);

Getting the current data format is similar to setting:

CaptureProperty property = CaptureProperty(
  CapturePropertyIds.DataFormatDevice,
  CapturePropertyTypes.None,
  {}
);

dynamic result = await deviceCapture.getProperty(property);