public abstract class BaseTransport
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
protected java.lang.String |
_address |
protected com.unitech.lib.util.collections.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 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
|
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(com.unitech.lib.transport.event.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.
|
protected static final int DUMP
protected static final int INFO
protected static final int IO
protected java.lang.String TAG
protected volatile ConnectState _connState
protected volatile ConnectType _connType
protected volatile DeviceType _devType
protected volatile java.lang.String _devName
protected volatile java.lang.String _macAddress
protected volatile java.lang.String _address
protected com.unitech.lib.util.collections.ByteQueue _byteQueue
public BaseTransport()
public BaseTransport(DeviceType type, java.lang.String name, java.lang.String address)
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.public BaseTransport(DeviceType type, java.lang.String name, java.lang.String mac, java.lang.String address)
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.public DeviceType getDeviceType()
public void setDeviceType(DeviceType type)
type
- The DeviceType enumeration indicating the type of device.public java.lang.String getDeviceName()
public void setDeviceName(java.lang.String name)
name
- A string representing the name of the Device.public java.lang.String getMacAddress()
public void setMacAddress(java.lang.String mac)
mac
- A string representing the MAC address of the Device.public java.lang.String getAddress()
public void setAddress(java.lang.String address)
address
- A string representing the address of the Device.public abstract int available()
public abstract boolean connect()
public abstract void disconnect()
public abstract void listen()
public abstract void destroy()
public abstract int read(byte[] data, int offset, int length)
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.public abstract int read(byte[] data, int offset, int length, int timeout)
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.public abstract int write(byte[] data, int offset, int length)
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.public abstract int write(byte[] data, int offset, int length, int timeout)
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.public ConnectType getConnectType()
public ConnectState getState()
public int write(byte[] data)
data
- A byte array that specifies the data to transfer to the Device.public int write(byte[] data, int length)
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.public int read(byte[] data)
data
- A byte array to store the data received from the device.public int read(byte[] data, int length)
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.public void setStateListener(com.unitech.lib.transport.event.IConnectStateEventListener listener)
listener
- An instance of IConnectStateEventListener to receive the connection status
of an instance of the BaseTransport class.protected void setState(ConnectState state, java.lang.Object params)
public void checkBufferSize(int size)
public java.lang.String toString()
toString
in class java.lang.Object