BluetoothServer
Last Updated On 2021-07-16
Version 5MinSDK 7Tutorial Video
Bluetooth server 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.
- 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.
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.
Enabled
Whether Bluetooth is enabled
HighByteFirst
Returns `true
IsAccepting
Returns true if this BluetoothServer component is accepting an incoming connection.
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.
AcceptConnection
Accept an incoming connection with the Serial Port Profile (SPP).
AcceptConnectionWithUUID
Accept an incoming connection with a specific UUID.
BytesAvailableToReceive
Returns an estimate of the number of bytes that can be received without blocking
Disconnect
Disconnect from the connected Bluetooth device.
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.
StopAccepting
Stop accepting an incoming connection.
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.
ConnectionAccepted
Indicates that a bluetooth connection has been accepted.