BluetoothClient

Last Updated On 2021-07-16

Version 6MinSDK 7Tutorial Video

Bluetooth client component


Properties

You can set the below properties in the UI part of the builder.

  • CharacterEncoding - it's a string value which is set to utf-8 by default.
  • DelimiterByte - it's a non negative integer value which is set to 0 by default.
  • DisconnectOnError - it's a boolean value which is set to false by default.
  • HighByteFirst - it's a boolean value which is set to false by default.
  • Secure - it's a boolean value which is set to true by default.

Block Properties

You can set the below blocks properties in the blocks section of the builder.

AddressesAndNames

The addresses and names of paired Bluetooth devices


Available

Whether Bluetooth is available on the device


CharacterEncoding

Sets the character encoding to use when sending and receiving text. The default value is `"UTF-8"


DelimiterByte

Sets the delimiter byte to use when passing a negative number for the numberOfBytes parameter when calling ReceiveText, ReceiveSignedBytes, or ReceiveUnsignedBytes. Those functions will continue to read bytes until they encounter the value specified here. The default delimiter is 0, the null byte.


DisconnectOnError

Disconnects BluetoothClient automatically when an error occurs.


Enabled

Whether Bluetooth is enabled


HighByteFirst

Returns `true


IsConnected

On devices with API level 14 (LEVEL_ICE_CREAM_SANDWICH) or higher, this property returned is accurate. But on old devices with API level lower than 14, it may not return the current state of connection(e.g., it might be disconnected but you may not know until you attempt to read/write the socket.


Secure

Whether to invoke SSP (Simple Secure Pairing), which is supported on devices with Bluetooth v2.1 or higher. When working with embedded Bluetooth devices, this property may need to be set to False. For Android 2.0-2.2, this property setting will be ignored.



Methods

You can set the below method blocks in the blocks section of the builder.

BytesAvailableToReceive

Returns an estimate of the number of bytes that can be received without blocking

Connect

Connect to the Bluetooth device with the specified address and the Serial Port Profile (SPP). Returns true if the connection was successful.

ConnectWithUUID

Connect to the Bluetooth device with the specified address and UUID. Returns true if the connection was successful.

Disconnect

Disconnect from the connected Bluetooth device.

IsDevicePaired

Checks whether the Bluetooth device with the specified address is paired.

ReceiveSigned1ByteNumber

Receive a signed 1-byte number from the connected Bluetooth device.

ReceiveSigned2ByteNumber

Receive a signed 2-byte number from the connected Bluetooth device.

ReceiveSigned4ByteNumber

Receive a signed 4-byte number from the connected Bluetooth device.

ReceiveSignedBytes

Receive multiple signed byte values from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

ReceiveText

Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

ReceiveUnsigned1ByteNumber

Receive an unsigned 1-byte number from the connected Bluetooth device.

ReceiveUnsigned2ByteNumber

Receive a unsigned 2-byte number from the connected Bluetooth device.

ReceiveUnsigned4ByteNumber

Receive a unsigned 4-byte number from the connected Bluetooth device.

ReceiveUnsignedBytes

Receive multiple unsigned byte values from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

Send1ByteNumber

Send a 1-byte number to the connected Bluetooth device.

Send2ByteNumber

Send a 2-byte number to the connected Bluetooth device.

Send4ByteNumber

Send a 4-byte number to the connected Bluetooth device.

SendBytes

Send a list of byte values to the connected Bluetooth device.

SendText

Send text to the connected Bluetooth device.


Events

You can set the below event blocks in the blocks section of the builder.

BluetoothError

The BluetoothError event is no longer used. Please use the Screen.ErrorOccurred event instead.