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:
SCWS.Bluetooth.startScan(): this allows application to detect bluetooth devices around you.
SCWS.Bluetooth.getDetected(): to get a list of detected devices.
SCWS.Bluetooth.register(): to register one of the detected and supported devices.At this point, or after a further
SCWS.Bluetooth.startScan()call, the device is paired and can be used as aSCWS.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
Objectwith 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
Promiseresolved with the detected devices.
- static SCWS.Bluetooth.getRegistered()¶
Gets the registered bluetooth peripheral.
The resolved value is a peripheral as an
Objectwith the following values:"label": the name of the peripheral. Could be missing ifSCWS.Bluetooth.register()has been called with no errors andSCWS.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
Promiseresolved with the registered peripheral, ornull.
- 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
UUIDaddress 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
Promiseresolved 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:
trueif bluetooth scanning was off.falseif 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
Promiseresolved withtrueorfalsedepending on the previous scanning state.
- static SCWS.Bluetooth.stopScan()¶
Stops scanning for bluetooth peripherals.
The resolved value can be the following:
trueif bluetooth scanning was started.falseif bluetooth scanning was already stopped.
- Throws:
SCWS.Error – Possible
Error.codes:"CXR_BT_PERMISSIONS_NOT_GRANTED"and"CXR_BT_INITIALIZATION_FAILED".- Returns:
A
Promiseresolved withtrueorfalsedepending on the previous scanning state.
- static SCWS.Bluetooth.release()¶
Releases the peripheral that we are connected to.
The resolved value can be the following:
trueif peripheral has been released.falseotherwise, 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
Promiseresolved withtrueorfalsewhether 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
Promiseresolved when the peripheral is unregistered.
- static SCWS.Bluetooth.isScanning()¶
Asks the system whether we are scanning for bluetooth peripherals or not.
- Returns:
A
Promiseresolved withtrueorfalse.