upm  0.4.1
Sensor/Actuator repository for libmraa (v0.8.0)
Public Member Functions | List of all members

API for the XBee modules. More...

Detailed Description

This is a generic UART driver for use with Digi XBee modules. It was tested with the XBee S1 802.15.4 module and the XBee S6B WiFi module.

It provides basic UART support for sending and receiving data to and from the device. It is controlled by an AT or API command set.

It is connected at 9600 baud by default.

These devices are typically configured using Digi's X-CTU windows software, however it is possible of course to configure them manually using AT commands. See the examples.

Public Member Functions

synchronized void delete ()
 
 XBee (int uart)
 
boolean dataAvailable (long millis)
 
int readData (String buffer, long len)
 
String readDataStr (int len)
 
int writeData (String buffer, long len)
 
int writeDataStr (String data)
 
int setBaudRate (int baud)
 
int setBaudRate ()
 
boolean commandMode (String cmdChars, int guardTimeMS)
 
boolean commandMode (String cmdChars)
 
boolean commandMode ()
 
String stringCR2LF (String str)
 

Constructor & Destructor Documentation

XBee ( int  uart)

XBee object constructor

Parameters
uartDefault UART to use (0 or 1). Default is 0.

Member Function Documentation

boolean commandMode ( String  cmdChars,
int  guardTimeMS 
)

Attempts to enter AT Command Mode. When Idle, data sent to the device (assuming it is not in API mode) is silently transmitted to the configured destination. Running this command attempts to place the device into command mode, allowing you to send AT commands. Note, after a configurable period of inactivity, the device will exit command mode automatically (default 10 seconds).

Both the cmdChars (+++) and the Guard Time can be configured on the device to different values using AT configuration commands.

Parameters
cmdCharsThe command mode characters, default "+++"
guardTimeMSThe number of milliseconds to wait before and after sending the command characters. Default is 1000 (1 second).
Returns
true if successful (received an "OK"), false otherwise
boolean dataAvailable ( long  millis)

Checks to see if there is data available for reading

Parameters
millisNumber of milliseconds to wait; 0 means no waiting
Returns
true if there is data available for reading
int readData ( String  buffer,
long  len 
)

Reads any available data into a user-supplied buffer. Note: the call blocks until data is available for reading. Use dataAvailable() to determine whether there is data available beforehand, to avoid blocking.

Parameters
bufferBuffer to hold the data read
lenLength of the buffer
Returns
Number of bytes read
String readDataStr ( int  len)

Reads any available data and returns it in a std::string. Note: the call blocks until data is available for reading. Use dataAvailable() to determine whether there is data available beforehand, to avoid blocking.

Parameters
lenMaximum length of the data to be returned
Returns
string containing the data read
int setBaudRate ( int  baud)

Sets the baud rate for the device. The default is 9600.

Parameters
baudDesired baud rate
Returns
true if successful
String stringCR2LF ( String  str)

This is a convenience method that converts each CR () in a string to a LF (
) and returns it. This is useful for outputting the response to an AT command for instance, which is typically CR terminated.

Parameters
strThe string to convert
Returns
The converted string
int writeData ( String  buffer,
long  len 
)

Writes the data in the buffer to the device. If you are writing an AT command, be sure to terminate it with a carriage return ()

Parameters
bufferBuffer to hold the data to write
lenLength of the buffer
Returns
Number of bytes written
int writeDataStr ( String  data)

Writes the std:string data to the device. If you are writing an AT command, be sure to terminate it with a carriage return ()

Parameters
dataBuffer to write to the device
Returns
Number of bytes written

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