Bluetooth

The SCWS.Bluetooth() provides an interface for manipulating bluetooth devices (or peripherals), including pairing and scanning. This is supported on iOS and Android platforms only.

Pairing a device allows you to use your bluetooth reader as a standard SCWS.Reader() object. Here are the steps to pair a bluetooth device:

  1. SCWS.Bluetooth.startScan(): this allows application to detect bluetooth devices around you.

  2. SCWS.Bluetooth.getDetected(): to get a list of detected devices.

  3. SCWS.Bluetooth.register(): to register one of the detected and supported devices.

  4. At this point, or after a further SCWS.Bluetooth.startScan() call, the device is paired and can be used as a SCWS.Reader().

The operation of pairing is permanent and could be done only once if only one bluetooth device is to be used.

Bluetooth interface has some constraints:

  • Getting detected devices is not possible if a bluetooth reader is currently paired.

  • Only one device can be registered, and so paired, at the same time.

static SCWS.Bluetooth.getDetected()

Gets the list of bluetooth peripherals that the system detects.

A bluetooth scanning must be started with SCWS.Bluetooth.startScan() before.

The resolved value is an array of detected peripherals. A peripheral is an Object with the following fields:

  • "label": the name of the peripheral, if applicable. Could be missing.

  • "UUID": the UUID of the peripheral.

  • "type": the type of the peripheral, one of the following values: "ACS", "FEITIAN" and "UNSUPPORTED".

Throws:

SCWS.Error – Possible Error.codes: "CXR_BT_PERMISSIONS_NOT_GRANTED", "CXR_BT_INITIALIZATION_FAILED", "CXR_BT_ALREADY_PAIRED" and "CXR_BT_NOT_SCANNING".

Returns:

A Promise resolved with the detected devices.

static SCWS.Bluetooth.getRegistered()

Gets the registered bluetooth peripheral.

The resolved value is a peripheral as an Object with the following values:

  • "label": the name of the peripheral. Could be missing if SCWS.Bluetooth.register() has been called with no errors and SCWS.onreaderadded() callback has not been called yet with corresponding bluetooth reader.

  • "UUID": the UUID of the peripheral.

If no peripheral is registered, resolved value is null.

Returns:

A Promise resolved with the registered peripheral, or null.

static SCWS.Bluetooth.register(UUID)

Registers a bluetooth peripheral in order to connect to it.

Scanning must be started, the peripheral to registered must be detected and returned by SCWS.Bluetooth.getDetected(), and must be supported.

Arguments:
  • UUID – the UUID address of the bluetooth peripheral to register as a string.

Throws:

SCWS.Error – Possible Error.codes: "CXR_BT_PERMISSIONS_NOT_GRANTED", "CXR_BT_INITIALIZATION_FAILED", "CXR_BT_NOT_SCANNING", "CXR_BT_DEVICE_NOT_DETECTED" and "CXR_BT_DEVICE_NOT_SUPPORTED".

Returns:

A Promise resolved when the operation completes.

static SCWS.Bluetooth.startScan()

Starts scanning for bluetooth peripherals.

Calling this function is the prerequisite before getting detected devices or before pairing and connecting to a registered peripheral.

Bluetooth scanning is automatically stopped when a paired device is connected.

The resolved value can be the following:

  • true if bluetooth scanning was off.

  • false if bluetooth scanning was already started.

Throws:

SCWS.Error – Possible Error.codes: "CXR_BT_PERMISSIONS_NOT_GRANTED", "CXR_BT_INITIALIZATION_FAILED" and "CXR_BT_ALREADY_PAIRED".

Returns:

A Promise resolved with true or false depending on the previous scanning state.

static SCWS.Bluetooth.stopScan()

Stops scanning for bluetooth peripherals.

The resolved value can be the following:

  • true if bluetooth scanning was started.

  • false if bluetooth scanning was already stopped.

Throws:

SCWS.Error – Possible Error.codes: "CXR_BT_PERMISSIONS_NOT_GRANTED" and "CXR_BT_INITIALIZATION_FAILED".

Returns:

A Promise resolved with true or false depending on the previous scanning state.

static SCWS.Bluetooth.release()

Releases the peripheral that we are connected to.

The resolved value can be the following:

  • true if peripheral has been released.

  • false otherwise, for instance if peripheral is not detected.

Throws:

SCWS.Error – Possible Error.codes: "CXR_BT_PERMISSIONS_NOT_GRANTED" and "CXR_BT_INITIALIZATION_FAILED".

Returns:

A Promise resolved with true or false whether the peripheral hass been released or not.

static SCWS.Bluetooth.unregister()

Unregisters the bluetooth peripheral currently registered.

If registered bluetooth peripheral is connected, it will be released.

Returns:

A Promise resolved when the peripheral is unregistered.

static SCWS.Bluetooth.isScanning()

Asks the system whether we are scanning for bluetooth peripherals or not.

Returns:

A Promise resolved with true or false.