Class SerialPortClient

  • All Implemented Interfaces:
    ej.bluetooth.listeners.RemoteServiceListener

    public abstract class SerialPortClient
    extends ej.bluetooth.listeners.impl.DefaultRemoteServiceListener
    The SerialPortClient class represents a serial port client.
    • Constructor Summary

      Constructors 
      Constructor Description
      SerialPortClient​(ej.bluetooth.BluetoothConnection connection, ej.bluetooth.BluetoothService service)
      Creates a serial port client, using the serial port service provided by a remote device and the connection to this device.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method 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​(ej.bluetooth.BluetoothConnection connection, ej.bluetooth.BluetoothCharacteristic characteristic, byte[] value)  
      void onWriteCompleted​(ej.bluetooth.BluetoothConnection connection, ej.bluetooth.BluetoothAttribute attribute, byte status)  
      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.
      • Methods inherited from class ej.bluetooth.listeners.impl.DefaultRemoteServiceListener

        onReadCompleted
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SerialPortClient

        public SerialPortClient​(ej.bluetooth.BluetoothConnection connection,
                                ej.bluetooth.BluetoothService service)
                         throws AttributeNotFoundException
        Creates a serial port client, using the serial port service provided by a remote device and the connection to this device.
        Parameters:
        connection - the connection to the device.
        service - the serial port service provided by the device.
        Throws:
        AttributeNotFoundException - if one of the mandatory attributes of the service is missing.
    • Method Detail

      • start

        public void start()
        Starts this serial port client.
      • stop

        public void stop()
        Stops this serial port client.
      • sendData

        public void sendData​(byte[] data)
        Sends the given data to the server. The onDataSent(boolean) methods is called once the data has been sent to the server.
        Parameters:
        data - the data to send.
      • onWriteCompleted

        public void onWriteCompleted​(ej.bluetooth.BluetoothConnection connection,
                                     ej.bluetooth.BluetoothAttribute attribute,
                                     byte status)
        Specified by:
        onWriteCompleted in interface ej.bluetooth.listeners.RemoteServiceListener
        Overrides:
        onWriteCompleted in class ej.bluetooth.listeners.impl.DefaultRemoteServiceListener
      • onNotificationReceived

        public void onNotificationReceived​(ej.bluetooth.BluetoothConnection connection,
                                           ej.bluetooth.BluetoothCharacteristic characteristic,
                                           byte[] value)
        Specified by:
        onNotificationReceived in interface ej.bluetooth.listeners.RemoteServiceListener
        Overrides:
        onNotificationReceived in class ej.bluetooth.listeners.impl.DefaultRemoteServiceListener
      • onDataReceived

        protected abstract void onDataReceived​(byte[] data)
        Called when data has been received from the server.
        Parameters:
        data - the data received from the server.
      • onDataSent

        protected abstract void onDataSent​(boolean success)
        Called when data has been sent to the server.
        Parameters:
        success - true if the the data was sent successfully, false otherwise.