Bluetooth LE Devices

Bluetooth Low Energy (Bluetooth LE) is a wireless communication technology designed for short-range, low-power data transfer. It enables reliable connections while using minimal energy. Here are some Bluetooth LE devices, D600, S550 and S370.

Discovering Bluetooth LE Devices

Use AddBluetoothDeviceAsync directly on the CaptureHelper instance to start a Bluetooth LE discovery:

capture = new CaptureHelper();
await capture.AddBluetoothDeviceAsync(ICaptureProperty.Values.BluetoothDiscoveryMode.kBluetoothLowEnergy);

This starts a scan and fires a DeviceDiscovered event each time a Socket Mobile Bluetooth LE device is found. Register a handler to receive discovered devices:

public MainPage()
{
    InitializeComponent();

    capture = new CaptureHelper();
    capture.DeviceDiscovered += Capture_DeviceDiscovered;
}

private void Capture_DeviceDiscovered(object sender, CaptureHelper.DeviceDiscoveredArgs e)
{
    CaptureDiscoveredDeviceInfo info = e.DeviceDiscoveredInfo;
    string name           = info.Name;
    string identifierUuid = info.IdentifierUuid;
    string serviceUuid    = info.ServiceUuid;
}

To be notified when the scan ends, register a handler to the DiscoveryEnded event:

capture.DiscoveryEnded += Capture_DiscoveryEnded;

private void Capture_DiscoveryEnded(object sender, CaptureHelper.DiscoveryEndedArgs e)
{
    Debug.WriteLine("DiscoveryEnded");
}

Connecting to a Discovered Device

Pass the CaptureDiscoveredDeviceInfo received from the DeviceDiscovered event to ConnectToDiscoveredDeviceAsync to establish a connection. The device is saved and will automatically reconnect when available:

private async void Capture_DeviceDiscovered(object sender, CaptureHelper.DeviceDiscoveredArgs e)
{
    await capture.ConnectToDiscoveredDeviceAsync(e.DeviceDiscoveredInfo);
}

Once the connection is established, the DeviceArrival event is fired. Register a handler to interact with the device:

public MainPage()
{
    InitializeComponent();

    capture = new CaptureHelper();
    capture.DeviceArrival += Capture_DeviceArrival;
}

private void Capture_DeviceArrival(object sender, CaptureHelper.DeviceArgs e)
{
    CaptureHelperDevice device = e.CaptureDevice;
}

Note

For a combo device like the S370 which has 2 devices (NFC and barcode scanner), there will be two DeviceArrival and two DeviceRemoval events fired. The following code shows how you can distinguish and handle them::

private void Capture_DeviceArrival(object sender, CaptureHelper.DeviceArgs e)
{
    int deviceType = e.CaptureDevice.GetDeviceInfo().Type;

    if (deviceType == DeviceTypes.kNFCS370)
    {
        // Handle the NFC reader of the S370
    }
    else if (deviceType == DeviceTypes.kScannerS370)
    {
        // Handle the Barcode scanner of the S370
    }
}

Removing a Device

Once a Bluetooth LE device has been connected, it will automatically reconnect upon disconnection unless it has been removed using RemoveBluetoothDeviceAsync. Removing a device disconnects it and prevents any further automatic reconnection:

private async void RemoveDevice(CaptureHelperDevice device)
{
    await capture.RemoveBluetoothDeviceAsync(device);
}

Reading Data

Once the connection is established successfully, data read from the device (NFC card, Smartphone wallet card, or Barcode) can be received by registering a handler to the Capture Helper event: DecodedData.:

public MainPage()
{
    InitializeComponent();

    // initialize CaptureHelper
    capture = new CaptureHelper();

    // register for the Capture Helper events
    capture.DecodedData += Capture_DecodedData;

}

Deprecated Methods (before version 2.0)

The following methods were deprecated in Capture version 2.0 and are no longer supported.

Deprecated Method

Replacement

StartDeviceDiscoveryAsync(int)

capture.AddBluetoothDeviceAsync(kBluetoothLowEnergy)

SetFavoritesAsync(string)

capture.ConnectToDiscoveredDeviceAsync(CaptureDiscoveredDeviceInfo)

GetFavoritesAsync()

No direct replacement

DeviceManagerArrival event

No longer required; call methods directly on CaptureHelper