com.unitech.lib.transport

## Class BaseTransport

- java.lang.Object
- - com.unitech.lib.transport.BaseTransport

- Direct Known Subclasses:
    TransportBluetooth, TransportUART

      public abstract class BaseTransport
      extends java.lang.Object

  The Transport class is a class for abstracting connections with Reader devices.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected java.lang.String` | `_address`
    `protected ByteQueue` | `_byteQueue`
    `protected ConnectState` | `_connState`
    `protected ConnectType` | `_connType`
    `protected java.lang.String` | `_devName`
    `protected DeviceType` | `_devType`
    `protected java.lang.String` | `_macAddress`
    `protected static int` | `DUMP`
    `protected static int` | `INFO`
    `protected static int` | `IO`
    `protected java.lang.String` | `TAG`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `BaseTransport()` Create an instance of the Transport class
    `BaseTransport(DeviceType type, java.lang.String name, java.lang.String address)` Create an instance of the Transport class
    `BaseTransport(DeviceType type, java.lang.String name, java.lang.String mac, java.lang.String address)` Create an instance of the Transport class

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract int` | `available()` Returns the length of data that can be read with the read method.
    `void` | `checkBufferSize(int size)`
    `abstract boolean` | `connect()` Attempts to connect to the appliance using an instance of the Transport class.
    `abstract void` | `destroy()` Destroys the instance and returns the resource.
    `abstract void` | `disconnect()` An instance of the Transport class closes the connection to the device to which the device is connected.
    `java.lang.String` | `getAddress()` Returns the address of the device to which the BaseTransport instance is connected.
    `ConnectType` | `getConnectType()` Returns the instance of Transport associated with device.
    `java.lang.String` | `getDeviceName()` Returns the name of the Device to which the BaseTransport instance is connected.
    `DeviceType` | `getDeviceType()` Returns the type of device to which the instance will be connected.
    `java.lang.String` | `getMacAddress()` Returns the MAC address of the device to which the BaseTransport instance is connected.
    `ConnectState` | `getState()` The instance of BaseTransport returns the connection status with device.
    `abstract void` | `listen()` An instance of the BaseTransport class waits for the device to connect.
    `int` | `read(byte[] data)` Read data received from the device.
    `int` | `read(byte[] data, int length)` Read data received from the device.
    `abstract int` | `read(byte[] data, int offset, int length)` Read data received from the device.
    `abstract int` | `read(byte[] data, int offset, int length, int timeout)` Read data received from the device.
    `void` | `setAddress(java.lang.String address)` Sets the address of the device to which the BaseTransport instance is connected.
    `void` | `setDeviceName(java.lang.String name)` Sets the name of the device to which the BaseTransport instance is connected.
    `void` | `setDeviceType(DeviceType type)` Sets the type of device to which the instance will be connected.
    `void` | `setMacAddress(java.lang.String mac)` Sets the MAC address of the device to which the BaseTransport instance is connected.
    `protected void` | `setState(ConnectState state, java.lang.Object params)`
    `void` | `setStateListener(IConnectStateEventListener listener)` Sets the listener to receive the connection status of an instance of the BaseTransport class.
    `java.lang.String` | `toString()`
    `int` | `write(byte[] data)` Transfer data to the device.
    `int` | `write(byte[] data, int length)` Transfer data to the device.
    `abstract int` | `write(byte[] data, int offset, int length)` Transfer data to the device.
    `abstract int` | `write(byte[] data, int offset, int length, int timeout)` Transfer data to the device.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### DUMP

          protected static final int DUMP

      See Also:
        Constant Field Values

    - #### INFO

          protected static final int INFO

      See Also:
        Constant Field Values

    - #### IO

          protected static final int IO

      See Also:
        Constant Field Values

    - #### TAG

          protected java.lang.String TAG

    - #### _connState

          protected volatile ConnectState _connState

    - #### _connType

          protected volatile ConnectType _connType

    - #### _devType

          protected volatile DeviceType _devType

    - #### _devName

          protected volatile java.lang.String _devName

    - #### _macAddress

          protected volatile java.lang.String _macAddress

    - #### _address

          protected volatile java.lang.String _address

    - #### _byteQueue

          protected ByteQueue _byteQueue

  - ### Constructor Detail

    - #### BaseTransport

          public BaseTransport()

      Create an instance of the Transport class

    - #### BaseTransport

          public BaseTransport(DeviceType type,
                               java.lang.String name,
                               java.lang.String address)

      Create an instance of the Transport class
      Parameters:
        `type` - A DeviceType enumeration that specifies the type of connected device using an instance of the Transport class.
        `name` - A string that specifies the name of the connected device using an instance of the Transport class.
        `address` - A string that specifies the address of the connected device by using an instance of the Transport class.

    - #### BaseTransport

          public BaseTransport(DeviceType type,
                               java.lang.String name,
                               java.lang.String mac,
                               java.lang.String address)

      Create an instance of the Transport class
      Parameters:
        `type` - A DeviceType enumeration that specifies the type of connected device using an instance of the Transport class.
        `name` - A string that specifies the name of the connected device using an instance of the Transport class.
        `mac` - A string that specifies the MAC address of the device to be connected using the instance of the Transport class.
        `address` - A string that specifies the address of the connected device by using an instance of the Transport class.

  - ### Method Detail

    - #### getDeviceType

          public DeviceType getDeviceType()

      Returns the type of device to which the instance will be connected.
      Returns:
        The DeviceType enumeration indicating the type of device.

    - #### setDeviceType

          public void setDeviceType(DeviceType type)

      Sets the type of device to which the instance will be connected.
      Parameters:
        `type` - The DeviceType enumeration indicating the type of device.

    - #### getDeviceName

          public java.lang.String getDeviceName()

      Returns the name of the Device to which the BaseTransport instance is connected.
      Returns:
        A string representing the name of the Device.

    - #### setDeviceName

          public void setDeviceName(java.lang.String name)

      Sets the name of the device to which the BaseTransport instance is connected.
      Parameters:
        `name` - A string representing the name of the Device.

    - #### getMacAddress

          public java.lang.String getMacAddress()

      Returns the MAC address of the device to which the BaseTransport instance is connected.
      Returns:
        A string representing the MAC address of the Device.

    - #### setMacAddress

          public void setMacAddress(java.lang.String mac)

      Sets the MAC address of the device to which the BaseTransport instance is connected.
      Parameters:
        `mac` - A string representing the MAC address of the Device.

    - #### getAddress

          public java.lang.String getAddress()

      Returns the address of the device to which the BaseTransport instance is connected.
      Returns:
        A string representing the address of the Device.

    - #### setAddress

          public void setAddress(java.lang.String address)

      Sets the address of the device to which the BaseTransport instance is connected.
      Parameters:
        `address` - A string representing the address of the Device.

    - #### available

          public abstract int available()

      Returns the length of data that can be read with the read method.
      Returns:
        Returns the length of data received from the device.

    - #### connect

          public abstract boolean connect()

      Attempts to connect to the appliance using an instance of the Transport class.
      Returns:
        Returns true if the connection attempt with the device is successful, false if it fails.

    - #### disconnect

          public abstract void disconnect()

      An instance of the Transport class closes the connection to the device to which the device is connected.

    - #### listen

          public abstract void listen()

      An instance of the BaseTransport class waits for the device to connect.

    - #### destroy

          public abstract void destroy()

      Destroys the instance and returns the resource.

    - #### read

          public abstract int read(byte[] data,
                                   int offset,
                                   int length)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
        `offset` - Integer specifying the start address at which data received from device will begin to be stored in a byte array.
        `length` - An integer specifying the maximum length at which data received from the device can be stored in a byte array.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### read

          public abstract int read(byte[] data,
                                   int offset,
                                   int length,
                                   int timeout)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
        `offset` - Integer specifying the start address at which data received from device will begin to be stored in a byte array.
        `length` - An integer specifying the maximum length at which data received from the device can be stored in a byte array.
        `timeout` - An integer that specifies the timeout for reading data received from the device.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### write

          public abstract int write(byte[] data,
                                    int offset,
                                    int length)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
        `offset` - An integer indicating the start address of the data to be transferred to the Device.
        `length` - An integer indicating the length of the data to be transferred to the Device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### write

          public abstract int write(byte[] data,
                                    int offset,
                                    int length,
                                    int timeout)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
        `offset` - An integer indicating the start address of the data to be transferred to the Device.
        `length` - An integer indicating the length of the data to be transferred to the Device.
        `timeout` - An integer specifying the timeout of data transmission to the device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### getConnectType

          public ConnectType getConnectType()

      Returns the instance of Transport associated with device.
      Returns:
        A ConnectType enumeration that indicates how the device is connected.

    - #### getState

          public ConnectState getState()

      The instance of BaseTransport returns the connection status with device.
      Returns:
        A ConnectState enumeration indicating the device and its connection status.

    - #### write

          public int write(byte[] data)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### write

          public int write(byte[] data,
                           int length)

      Transfer data to the device.
      Parameters:
        `data` - A byte array that specifies the data to transfer to the Device.
        `length` - An integer indicating the length of the data to be transferred to the Device.
      Returns:
        Returns the length of the data transferred to the Device.

    - #### read

          public int read(byte[] data)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### read

          public int read(byte[] data,
                          int length)

      Read data received from the device.
      Parameters:
        `data` - A byte array to store the data received from the device.
        `length` - An integer specifying the maximum length at which data received from the device can be stored in a byte array.
      Returns:
        Returns the length of data received from device and stored in a byte array.

    - #### setStateListener

          public void setStateListener(IConnectStateEventListener listener)

      Sets the listener to receive the connection status of an instance of the BaseTransport class.
      Parameters:
        `listener` - An instance of IConnectStateEventListener to receive the connection status of an instance of the BaseTransport class.

    - #### setState

          protected void setState(ConnectState state,
                                  java.lang.Object params)

    - #### checkBufferSize

          public void checkBufferSize(int size)

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`