public abstract class SerialPortClient extends DefaultRemoteServiceListener
SerialPortClient
class represents a serial port client.Constructor and Description |
---|
SerialPortClient(BluetoothConnection connection,
BluetoothService service)
Creates a serial port client, using the serial port service provided by a remote device and the connection to
this device.
|
Modifier and Type | Method and Description |
---|---|
protected abstract void |
onDataReceived(byte[] data)
Called when data has been received from the server.
|
protected abstract void |
onDataSent(boolean success)
Called when data has been sent to the server.
|
void |
onNotificationReceived(BluetoothConnection connection,
BluetoothCharacteristic characteristic,
byte[] value)
Called when a characteristic notification or indication is received.
|
void |
onWriteCompleted(BluetoothConnection connection,
BluetoothAttribute attribute,
byte status)
Called when a response to a write request is received.
|
void |
sendData(byte[] data)
Sends the given data to the server.
|
void |
start()
Starts this serial port client.
|
void |
stop()
Stops this serial port client.
|
onReadCompleted
public SerialPortClient(BluetoothConnection connection, BluetoothService service) throws AttributeNotFoundException
connection
- the connection to the device.service
- the serial port service provided by the device.AttributeNotFoundException
- if one of the mandatory attributes of the service is missing.protected abstract void onDataReceived(byte[] data)
data
- the data received from the server.protected abstract void onDataSent(boolean success)
success
- true if the the data was sent successfully, false otherwise.public void onNotificationReceived(BluetoothConnection connection, BluetoothCharacteristic characteristic, byte[] value)
RemoteServiceListener
onNotificationReceived
in interface RemoteServiceListener
onNotificationReceived
in class DefaultRemoteServiceListener
connection
- the connection with the device which has sent the notification.characteristic
- the characteristic which has changed.value
- the value of the characteristic.public void onWriteCompleted(BluetoothConnection connection, BluetoothAttribute attribute, byte status)
RemoteServiceListener
onWriteCompleted
in interface RemoteServiceListener
onWriteCompleted
in class DefaultRemoteServiceListener
connection
- the connection with the device which has sent the response.attribute
- the attribute which was written.status
- the response status (see BluetoothStatus
).BluetoothConnection.sendWriteRequest(BluetoothAttribute, byte[])
public void sendData(byte[] data)
onDataSent(boolean)
methods is called once the data has been
sent to the server.data
- the data to send.public void start()
public void stop()