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.
Using the Companion App (Recommended)¶
The recommended way to manage Bluetooth LE device connections is through the Socket Mobile Companion App. The Companion App handles device discovery, pairing, and connection management on behalf of the consumer app, providing a consistent and streamlined experience.
The sections below apply only if the consumer app intends to manage Bluetooth LE device connections directly, without relying on the Companion App’s device connection management.
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 |
|---|---|
|
|
|
|
|
No direct replacement |
|
No longer required; call methods directly on |