XBee Class Reference

Primary interface for communicating with an XBee Radio. More...

#include <XBee.h>

List of all members.

Public Member Functions

void readPacket ()
 Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty.
bool readPacket (int timeout)
 Waits a maximum of timeout milliseconds for a response packet before timing out; returns true if packet is read.
void readPacketUntilAvailable ()
 Reads until a packet is received or an error occurs.
void begin (long baud)
 Starts the serial connection at the supplied baud rate.
void getResponse (XBeeResponse &response)
XBeeResponsegetResponse ()
 Returns a reference to the current response Note: once readPacket is called again this response will be overwritten!
void send (XBeeRequest &request)
 Sends a XBeeRequest (TX packet) out the serial port.
uint8_t getNextFrameId ()
 Returns a sequential frame id between 1 and 255.
void setSerial (HardwareSerial &serial)
 Specify the serial port.


Detailed Description

Primary interface for communicating with an XBee Radio.

This class provides methods for sending and receiving packets with an XBee radio via the serial port. The XBee radio must be configured in API (packet) mode (AP=2) in order to use this software.

Since this code is designed to run on a microcontroller, with only one thread, you are responsible for reading the data off the serial buffer in a timely manner. This involves a call to a variant of readPacket(...). If your serial port is receiving data faster than you are reading, you can expect to lose packets. Arduino only has a 128 byte serial buffer so it can easily overflow if two or more packets arrive without a call to readPacket(...)

In order to conserve resources, this class only supports storing one response packet in memory at a time. This means that you must fully consume the packet prior to calling readPacket(...), because calling readPacket(...) overwrites the previous response.

This class creates an array of size MAX_FRAME_DATA_SIZE for storing the response packet. You may want to adjust this value to conserve memory.

Author:
Andrew Rapp

Member Function Documentation

bool XBee::readPacket ( int  timeout  ) 

Waits a maximum of timeout milliseconds for a response packet before timing out; returns true if packet is read.

Returns false if timeout or error occurs.

void XBee::readPacket (  ) 

Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty.

You may call xbee.getResponse().isAvailable() after calling this method to determine if a packet is ready, or xbee.getResponse().isError() to determine if a error occurred.

This method should always return quickly since it does not wait for serial data to arrive. You will want to use this method if you are doing other timely stuff in your loop, where a delay would cause problems. NOTE: calling this method resets the current response, so make sure you first consume the current response

void XBee::readPacketUntilAvailable (  ) 

Reads until a packet is received or an error occurs.

Caution: use this carefully since if you don't get a response, your Arduino code will hang on this call forever!! often it's better to use a timeout: readPacket(int)

void XBee::setSerial ( HardwareSerial &  serial  ) 

Specify the serial port.

Only relevant for Arduinos that support multiple serial ports (e.g. Mega)


The documentation for this class was generated from the following files:

Generated on Wed Dec 21 17:21:21 2011 for XBee-Arduino by  doxygen 1.5.8