public class XBeeDevice extends AbstractXBeeDevice
DigiMeshDevice
,
DigiPointDevice
,
Raw802Device
,
ZigBeeDevice
Constructor and Description |
---|
XBeeDevice(IConnectionInterface connectionInterface)
Class constructor.
|
XBeeDevice(String port,
int baudRate)
Class constructor.
|
XBeeDevice(String port,
int baudRate,
int dataBits,
int stopBits,
int parity,
int flowControl)
Class constructor.
|
XBeeDevice(String port,
SerialPortParameters serialPortParameters)
Class constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addDataListener(IDataReceiveListener listener)
Adds the provided listener to the list of listeners to be notified
when new data is received.
|
void |
addIOSampleListener(IIOSampleReceiveListener listener)
Adds the provided listener to the list of listeners to be notified
when new IO samples are received.
|
void |
addModemStatusListener(IModemStatusReceiveListener listener)
Adds the provided listener to the list of listeners to be notified
when new Modem Status events are received.
|
void |
addPacketListener(IPacketReceiveListener listener)
Adds the provided listener to the list of listeners to be notified
when new packets are received.
|
void |
close()
Closes the connection interface associated with this XBee device.
|
XBeeNetwork |
getNetwork()
Returns the network associated with this XBee device.
|
OperatingMode |
getOperatingMode()
Returns the Operating mode (AT, API or API escaped) of this XBee device.
|
int |
getReceiveTimeout()
Returns this XBee device configured timeout for receiving packets in
synchronous operations.
|
boolean |
isOpen()
Returns whether the connection interface associated to this device is
already open.
|
boolean |
isRemote()
Always returns
false , since this is always a local device. |
void |
open()
Opens the connection interface associated with this XBee device.
|
XBeeMessage |
readData()
Reads new data received by this XBee device during the configured
received timeout.
|
XBeeMessage |
readData(int timeout)
Reads new data received by this XBee device during the provided timeout.
|
XBeeMessage |
readDataFrom(RemoteXBeeDevice remoteXBeeDevice)
Reads new data received from the given remote XBee device during the
configured received timeout.
|
XBeeMessage |
readDataFrom(RemoteXBeeDevice remoteXBeeDevice,
int timeout)
Reads new data received from the given remote XBee device during the
provided timeout.
|
void |
removeDataListener(IDataReceiveListener listener)
Removes the provided listener from the list of data listeners.
|
void |
removeIOSampleListener(IIOSampleReceiveListener listener)
Removes the provided listener from the list of IO samples listeners.
|
void |
removeModemStatusListener(IModemStatusReceiveListener listener)
Removes the provided listener from the list of Modem Status listeners.
|
void |
removePacketListener(IPacketReceiveListener listener)
Removes the provided listener from the list of packets listeners.
|
void |
reset()
Performs a software reset on this XBee device and blocks until the
process is completed.
|
void |
sendBroadcastData(byte[] data)
Sends the provided data to all the XBee nodes of the network (broadcast).
|
void |
sendData(RemoteXBeeDevice xbeeDevice,
byte[] data)
Sends the provided data to the given XBee device choosing the optimal
send method depending on the protocol of the local XBee device.
|
void |
sendDataAsync(RemoteXBeeDevice xbeeDevice,
byte[] data)
Sends the provided data to the provided XBee device asynchronously.
|
XBeePacket |
sendPacket(XBeePacket packet)
Sends the given XBee packet synchronously and blocks until the response
is received or the configured receive timeout expires.
|
void |
sendPacket(XBeePacket packet,
IPacketReceiveListener packetReceiveListener)
Sends the given XBee packet and registers the given packet listener
(if not
null ) to be notified when the answers is received. |
void |
sendPacketAsync(XBeePacket packet)
Sends the given XBee packet asynchronously.
|
void |
setReceiveTimeout(int receiveTimeout)
Configures this XBee device timeout in milliseconds for receiving
packets in synchronous operations.
|
String |
toString() |
applyChanges, enableApplyConfigurationChanges, executeParameter, get16BitAddress, get64BitAddress, getADCValue, getConnectionInterface, getDestinationAddress, getDIOChangeDetection, getDIOValue, getFirmwareVersion, getHardwareVersion, getIOConfiguration, getIOSamplingRate, getNodeID, getPANID, getParameter, getPowerLevel, getPWMDutyCycle, getXBeeProtocol, isApplyConfigurationChangesEnabled, readDeviceInfo, readIOSample, setDestinationAddress, setDIOChangeDetection, setDIOValue, setIOConfiguration, setIOSamplingRate, setNodeID, setPANID, setParameter, setPowerLevel, setPWMDutyCycle, updateDeviceDataFrom, writeChanges
public XBeeDevice(IConnectionInterface connectionInterface)
XBeeDevice
object with the
given connection interface.connectionInterface
- The connection interface with the physical
XBee device.NullPointerException
- if connectionInterface == null
.XBeeDevice(String, int)
,
XBeeDevice(String, SerialPortParameters)
,
XBeeDevice(String, int, int, int, int, int)
,
IConnectionInterface
public XBeeDevice(String port, int baudRate)
XBeeDevice
object
physically connected to the given port name and configured at the
provided baud rate.port
- Serial port name where XBee device is attached to.baudRate
- Serial port baud rate to communicate with the device.
Other connection parameters will be set as default (8
data bits, 1 stop bit, no parity, no flow control).IllegalArgumentException
- if baudRate < 0
.NullPointerException
- if port == null
.XBeeDevice(IConnectionInterface)
,
XBeeDevice(String, SerialPortParameters)
,
XBeeDevice(String, int, int, int, int, int)
public XBeeDevice(String port, int baudRate, int dataBits, int stopBits, int parity, int flowControl)
XBeeDevice
object
physically connected to the given port name and configured to communicate
with the provided serial settings.port
- Serial port name where XBee device is attached to.baudRate
- Serial port baud rate to communicate with the device.dataBits
- Serial port data bits.stopBits
- Serial port data bits.parity
- Serial port data bits.flowControl
- Serial port data bits.IllegalArgumentException
- if baudRate < 0
or
if dataBits < 0
or
if stopBits < 0
or
if parity < 0
or
if flowControl < 0
.NullPointerException
- if port == null
.XBeeDevice(IConnectionInterface)
,
XBeeDevice(String, int)
,
XBeeDevice(String, SerialPortParameters)
public XBeeDevice(String port, SerialPortParameters serialPortParameters)
XBeeDevice
object
physically connected to the given port name and configured to communicate
with the provided serial settings.port
- Serial port name where XBee device is attached to.serialPortParameters
- Object containing the serial port parameters.NullPointerException
- if port == null
or
if serialPortParameters == null
.XBeeDevice(IConnectionInterface)
,
XBeeDevice(String, int)
,
XBeeDevice(String, int, int, int, int, int)
,
SerialPortParameters
public void addDataListener(IDataReceiveListener listener)
AbstractXBeeDevice
If the listener has been already included this method does nothing.
listener
- Listener to be notified when new data is received.AbstractXBeeDevice.removeDataListener(IDataReceiveListener)
,
IDataReceiveListener
public void addIOSampleListener(IIOSampleReceiveListener listener)
AbstractXBeeDevice
If the listener has been already included this method does nothing.
listener
- Listener to be notified when new IO samples are received.AbstractXBeeDevice.removeIOSampleListener(IIOSampleReceiveListener)
,
IIOSampleReceiveListener
public void addModemStatusListener(IModemStatusReceiveListener listener)
AbstractXBeeDevice
If the listener has been already included this method does nothing.
listener
- Listener to be notified when new Modem Status events are
received.AbstractXBeeDevice.removeModemStatusListener(IModemStatusReceiveListener)
,
IModemStatusReceiveListener
public void addPacketListener(IPacketReceiveListener listener)
AbstractXBeeDevice
If the listener has been already included, this method does nothing.
listener
- Listener to be notified when new packets are received.AbstractXBeeDevice.removePacketListener(IPacketReceiveListener)
,
IPacketReceiveListener
public void close()
public XBeeNetwork getNetwork()
InterfaceNotOpenException
- if this device connection is not open.XBeeNetwork
public OperatingMode getOperatingMode()
OperatingMode
public int getReceiveTimeout()
setReceiveTimeout(int)
public boolean isOpen()
public boolean isRemote()
false
, since this is always a local device.isRemote
in class AbstractXBeeDevice
false
since it is a local device.public void open() throws XBeeException
When opening the device an information reading process is automatically performed. This includes:
InterfaceAlreadyOpenException
- if this device connection is
already open.XBeeException
- if there is any problem opening this device
connection.close()
,
isOpen()
public XBeeMessage readData()
This method blocks until new data is received or the configured receive timeout expires.
The received timeout is configured using the setReceiveTimeout
method and can be consulted with getReceiveTimeout
method.
For non-blocking operations, register a IDataReceiveListener
using the method addDataListener(IDataReceiveListener)
.
XBeeMessage
object containing the data and the source
address of the remote node that sent the data. null
if
this did not receive new data during the configured receive
timeout.InterfaceNotOpenException
- if this device connection is not open.readData(int)
,
getReceiveTimeout()
,
setReceiveTimeout(int)
,
readDataFrom(RemoteXBeeDevice)
,
readDataFrom(RemoteXBeeDevice, int)
,
XBeeMessage
public XBeeMessage readData(int timeout)
This method blocks until new data is received or the provided timeout expires.
For non-blocking operations, register a IDataReceiveListener
using the method addDataListener(IDataReceiveListener)
.
timeout
- The time to wait for new data in milliseconds.XBeeMessage
object containing the data and the source
address of the remote node that sent the data. null
if
this device did not receive new data during timeout
milliseconds.IllegalArgumentException
- if timeout < 0
.InterfaceNotOpenException
- if this device connection is not open.readData()
,
readDataFrom(RemoteXBeeDevice)
,
readDataFrom(RemoteXBeeDevice, int)
,
XBeeMessage
public XBeeMessage readDataFrom(RemoteXBeeDevice remoteXBeeDevice)
This method blocks until new data from the provided remote XBee device is received or the configured receive timeout expires.
The received timeout is configured using the setReceiveTimeout
method and can be consulted with getReceiveTimeout
method.
For non-blocking operations, register a IDataReceiveListener
using the method addDataListener(IDataReceiveListener)
.
remoteXBeeDevice
- The remote device to read data from.XBeeMessage
object containing the data and the source
address of the remote node that sent the data. null
if
this device did not receive new data from the provided remote
XBee device during the configured receive timeout.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if remoteXBeeDevice == null
.readDataFrom(RemoteXBeeDevice, int)
,
getReceiveTimeout()
,
setReceiveTimeout(int)
,
readData()
,
readData(int)
,
RemoteXBeeDevice
,
XBeeMessage
public XBeeMessage readDataFrom(RemoteXBeeDevice remoteXBeeDevice, int timeout)
This method blocks until new data from the provided remote XBee device is received or the given timeout expires.
For non-blocking operations, register a IDataReceiveListener
using the method addDataListener(IDataReceiveListener)
.
remoteXBeeDevice
- The remote device to read data from.timeout
- The time to wait for new data in milliseconds.XBeeMessage
object containing the data and the source
address of the remote node that sent the data. null
if
this device did not receive new data from the provided remote
XBee device during timeout
milliseconds.IllegalArgumentException
- if timeout < 0
.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if remoteXBeeDevice == null
.readDataFrom(RemoteXBeeDevice)
,
getReceiveTimeout()
,
setReceiveTimeout(int)
,
readData()
,
readData(int)
,
RemoteXBeeDevice
,
XBeeMessage
public void removeDataListener(IDataReceiveListener listener)
AbstractXBeeDevice
If the listener was not in the list this method does nothing.
listener
- Listener to be removed from the list of listeners.AbstractXBeeDevice.addDataListener(IDataReceiveListener)
,
IDataReceiveListener
public void removeIOSampleListener(IIOSampleReceiveListener listener)
AbstractXBeeDevice
If the listener was not in the list this method does nothing.
listener
- Listener to be removed from the list of listeners.AbstractXBeeDevice.addIOSampleListener(IIOSampleReceiveListener)
,
IIOSampleReceiveListener
public void removeModemStatusListener(IModemStatusReceiveListener listener)
AbstractXBeeDevice
If the listener was not in the list this method does nothing.
listener
- Listener to be removed from the list of listeners.AbstractXBeeDevice.addModemStatusListener(IModemStatusReceiveListener)
,
IModemStatusReceiveListener
public void removePacketListener(IPacketReceiveListener listener)
AbstractXBeeDevice
If the listener was not in the list this method does nothing.
listener
- Listener to be removed from the list of listeners.AbstractXBeeDevice.addPacketListener(IPacketReceiveListener)
,
IPacketReceiveListener
public void reset() throws TimeoutException, XBeeException
AbstractXBeeDevice
reset
in class AbstractXBeeDevice
TimeoutException
- if the configured time expires while waiting
for the command reply.XBeeException
- if there is any other XBee related exception.public void sendBroadcastData(byte[] data) throws TimeoutException, XBeeException
This method blocks till a success or error transmit status arrives or the configured receive timeout expires.
The received timeout is configured using the setReceiveTimeout
method and can be consulted with getReceiveTimeout
method.
data
- Byte array containing the data to be sent.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if data == null
.TimeoutException
- if there is a timeout sending the data.XBeeException
- if there is any other XBee related exception.getReceiveTimeout()
,
setReceiveTimeout(int)
public void sendData(RemoteXBeeDevice xbeeDevice, byte[] data) throws TimeoutException, XBeeException
This method blocks till a success or error response arrives or the configured receive timeout expires.
The received timeout is configured using the setReceiveTimeout
method and can be consulted with getReceiveTimeout
method.
For non-blocking operations use the method
sendDataAsync(RemoteXBeeDevice, byte[])
.
xbeeDevice
- The XBee device of the network that will receive the
data.data
- Byte array containing the data to be sent.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if xbeeDevice == null
or
if data == null
.TimeoutException
- if there is a timeout sending the data.XBeeException
- if there is any other XBee related exception.getReceiveTimeout()
,
setReceiveTimeout(int)
,
sendDataAsync(RemoteXBeeDevice, byte[])
public void sendDataAsync(RemoteXBeeDevice xbeeDevice, byte[] data) throws XBeeException
Asynchronous transmissions do not wait for answer from the remote device or for transmit status packet.
xbeeDevice
- The XBee device of the network that will receive the
data.data
- Byte array containing the data to be sent.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if xbeeDevice == null
or
if data == null
.XBeeException
- if there is any XBee related exception.sendData(RemoteXBeeDevice, byte[])
,
RemoteXBeeDevice
public XBeePacket sendPacket(XBeePacket packet) throws TimeoutException, XBeeException
The received timeout is configured using the setReceiveTimeout
method and can be consulted with getReceiveTimeout
method.
Use sendXBeePacketAsync(XBeePacket)
or
#sendXBeePacket(XBeePacket, IPacketReceiveListener)
for
non-blocking operations.
packet
- XBee packet to be sent.XBeePacket
object containing the response of the sent
packet or null
if there is no response.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if packet == null
.TimeoutException
- if there is a timeout sending the XBee packet.XBeeException
- if there is any other XBee related exception.getReceiveTimeout()
,
AbstractXBeeDevice.sendXBeePacket(XBeePacket, IPacketReceiveListener)
,
AbstractXBeeDevice.sendXBeePacketAsync(XBeePacket)
,
setReceiveTimeout(int)
,
XBeePacket
public void sendPacket(XBeePacket packet, IPacketReceiveListener packetReceiveListener) throws XBeeException
null
) to be notified when the answers is received.
This is a non-blocking operation. To wait for the answer use
sendPacket(XBeePacket)
.
packet
- XBee packet to be sent.packetReceiveListener
- Listener for the operation, null
not to be notified when the answer arrives.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if packet == null
.XBeeException
- if there is any other XBee related exception.sendPacket(XBeePacket)
,
sendPacketAsync(XBeePacket)
,
IPacketReceiveListener
,
XBeePacket
public void sendPacketAsync(XBeePacket packet) throws XBeeException
This is a non-blocking operation that do not wait for the answer and is never notified when it arrives.
To be notified when the answer is received, use
AbstractXBeeDevice.sendXBeePacket(XBeePacket, IPacketReceiveListener)
.
packet
- XBee packet to be sent asynchronously.InterfaceNotOpenException
- if this device connection is not open.NullPointerException
- if packet == null
.XBeeException
- if there is any other XBee related exception.AbstractXBeeDevice.sendXBeePacket(XBeePacket)
,
AbstractXBeeDevice.sendXBeePacket(XBeePacket, IPacketReceiveListener)
,
XBeePacket
public void setReceiveTimeout(int receiveTimeout)
receiveTimeout
- The new receive timeout in milliseconds.IllegalArgumentException
- if receiveTimeout < 0
.getReceiveTimeout()
public String toString()
toString
in class AbstractXBeeDevice
© Copyright 2014–2014 Digi International Inc. All rights reserved.