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 DeviceArrival notification.

Configuring Contactless NFC Reader/Writer D600 and S550

The Socket Mobile Contactless NFC Reader/Writer D600, S550 and S370 are using Bluetooth Low Energy (Bluetooth LE) for connecting to the host.

The iOS platform fully supports both Socket Mobile NFC devices. Android currently supports the S550.

The BluetoothLE experience is handled by a Capture Device Manager. Following the same logic as for any other device, Capture will send a DeviceManagerArrival when BluetoothLE is supported.

The BluetoothLE connection process use a Capture Auto Discovery mechanism that is enabled as soon as the Capture BluetoothLE Device Manager Favorite contains either a “*” (star) character or a Unique Device UUID.

In the case of the favorite containing a “*”, the BluetoothLE Capture Device Manager will discover and connect to the first Socket Mobile it finds.

In the case of the favorite containing a Unique device UUID, the BluetoothLE Capture Device Manager will search and connect to the corresponding Socket Mobile Contactless NFC Reader/Writer.

Once a Socket Mobile Contactless NFC Reader/Writer is connected to the host, Capture sends a Device Arrival notification as for any other device.

BLE Device Manager onCaptureEvent Sample Code

You can check for the BLE Device Manager in the onCaptureEvent callback like you would any other capture event. See below.

case CaptureEventIds.DeviceManagerArrival:
    const newBleDeviceManager = new CaptureRn();
    let {name, guid, type} = e.value; //where 'e' is the capture event that is registered in the onCaptureEvent function.
    dev.openDevice(guid, capture).then((result) => {
        setStatus(`result of opening ${name} : ${result}`);
        setBleDeviceManagerCapture(dev);
        getFavorite(dev);
    })
    break;
case CaptureEventIds.DeviceManagerRemoval:
    setBleDeviceManagerCapture(null);
    break;

As you can see, we use the same openDevice method that we would use for a regular device arrival. Once we have opened the BLE Device Manager, we can now try to get any favorites using getFavorite. See below.

const getFavorite = async (dev) => {
    var property = new CaptureProperty(
        CapturePropertyIds.Favorite,
        CapturePropertyTypes.None,
        {}
    );

    try {
        let favorite = await dev.getProperty(property);
        setStatus('retrieving BLE Device Manager favorite... ');
        if (favorite.value.length === 0) {
            setFavorite(dev);
        } else {
            setStatus('Favorite found! Try using an NFC reader!');
        }
    } catch (err) {
        setStatus(`failed to get favorite: ${err.code} : ${err.message}`);
    }
};

Here we are making sure we have a favorite and if we do we can then be ready to pair with the closest NFC device. If our favorite’s value is empty, then we will need to set a favorite to ensure we can connect with NFC devices. To do this, we will make use of setProperty in our function called setFavorite. See below.

const setFavorite = async (bleDevice) => {
    var property = new CaptureProperty(
        CapturePropertyIds.Favorite,
        CapturePropertyTypes.String,
        '*',
    );

    try {
        var data = await bleDevice.setProperty(property);
        setStatus(`successfully set favorite for BLE Device Manager: '${newName}' `);
    } catch (res) {
        let {code, message} = res.error;
        setStatus(`failed to set favorite: ${code} : ${message}`);
    }
};

Once we are able to set the favorite, our app should be ready to connect with NFC devices nearby.

Note

A Device Manager Arrival is required in order to open a Device Manager and to be able to set or get its favorite. Such notification is only sent on the host supporting BluetoothLE and with Capture supporting at least one of the Socket Mobile Contactless NFC Reader/Writers.