<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>XBee-Arduino: XBee Class Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">XBee-Arduino
   &#160;<span id="projectnumber">0.2</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="class_x_bee-members.html">List of all members</a>  </div>
  <div class="headertitle">
<div class="title">XBee Class Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Primary interface for communicating with an <a class="el" href="class_x_bee.html" title="Primary interface for communicating with an XBee Radio. ">XBee</a> Radio.  
 <a href="class_x_bee.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="_x_bee_8h_source.html">XBee.h</a>&gt;</code></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a7d788232f44e8b3c10dc686a0299fcc6"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#a7d788232f44e8b3c10dc686a0299fcc6">readPacket</a> ()</td></tr>
<tr class="memdesc:a7d788232f44e8b3c10dc686a0299fcc6"><td class="mdescLeft">&#160;</td><td class="mdescRight">Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty.  <a href="#a7d788232f44e8b3c10dc686a0299fcc6">More...</a><br/></td></tr>
<tr class="separator:a7d788232f44e8b3c10dc686a0299fcc6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ae1c9f3b53df50564ab9aca2716792b44"><td class="memItemLeft" align="right" valign="top">bool&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#ae1c9f3b53df50564ab9aca2716792b44">readPacket</a> (int timeout)</td></tr>
<tr class="memdesc:ae1c9f3b53df50564ab9aca2716792b44"><td class="mdescLeft">&#160;</td><td class="mdescRight">Waits a maximum of <em>timeout</em> milliseconds for a response packet before timing out; returns true if packet is read.  <a href="#ae1c9f3b53df50564ab9aca2716792b44">More...</a><br/></td></tr>
<tr class="separator:ae1c9f3b53df50564ab9aca2716792b44"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a594e2bb2ccb7b3fe7a2278b9324b4083"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#a594e2bb2ccb7b3fe7a2278b9324b4083">readPacketUntilAvailable</a> ()</td></tr>
<tr class="memdesc:a594e2bb2ccb7b3fe7a2278b9324b4083"><td class="mdescLeft">&#160;</td><td class="mdescRight">Reads until a packet is received or an error occurs.  <a href="#a594e2bb2ccb7b3fe7a2278b9324b4083">More...</a><br/></td></tr>
<tr class="separator:a594e2bb2ccb7b3fe7a2278b9324b4083"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a2d170fc3f2412712adee0af794dc6263"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a2d170fc3f2412712adee0af794dc6263"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#a2d170fc3f2412712adee0af794dc6263">begin</a> (Stream &amp;serial)</td></tr>
<tr class="memdesc:a2d170fc3f2412712adee0af794dc6263"><td class="mdescLeft">&#160;</td><td class="mdescRight">Starts the serial connection on the specified serial port. <br/></td></tr>
<tr class="separator:a2d170fc3f2412712adee0af794dc6263"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac88079aa744d36b26a0c6a0add939898"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="ac88079aa744d36b26a0c6a0add939898"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><b>getResponse</b> (<a class="el" href="class_x_bee_response.html">XBeeResponse</a> &amp;response)</td></tr>
<tr class="separator:ac88079aa744d36b26a0c6a0add939898"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a18250def80e8b643aa1ccc15a98937f3"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a18250def80e8b643aa1ccc15a98937f3"></a>
<a class="el" href="class_x_bee_response.html">XBeeResponse</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#a18250def80e8b643aa1ccc15a98937f3">getResponse</a> ()</td></tr>
<tr class="memdesc:a18250def80e8b643aa1ccc15a98937f3"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a reference to the current response Note: once readPacket is called again this response will be overwritten! <br/></td></tr>
<tr class="separator:a18250def80e8b643aa1ccc15a98937f3"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a802387f468be8622941d16739ac848f2"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a802387f468be8622941d16739ac848f2"></a>
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#a802387f468be8622941d16739ac848f2">send</a> (<a class="el" href="class_x_bee_request.html">XBeeRequest</a> &amp;request)</td></tr>
<tr class="memdesc:a802387f468be8622941d16739ac848f2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Sends a <a class="el" href="class_x_bee_request.html" title="Super class of all XBee requests (TX packets) Users should never create an instance of this class; in...">XBeeRequest</a> (TX packet) out the serial port. <br/></td></tr>
<tr class="separator:a802387f468be8622941d16739ac848f2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a25bd226e41517e8a66a13e531d31438d"><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="a25bd226e41517e8a66a13e531d31438d"></a>
uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#a25bd226e41517e8a66a13e531d31438d">getNextFrameId</a> ()</td></tr>
<tr class="memdesc:a25bd226e41517e8a66a13e531d31438d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Returns a sequential frame id between 1 and 255. <br/></td></tr>
<tr class="separator:a25bd226e41517e8a66a13e531d31438d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a58ff19e5342060ca91aea247db99b927"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_x_bee.html#a58ff19e5342060ca91aea247db99b927">setSerial</a> (Stream &amp;serial)</td></tr>
<tr class="memdesc:a58ff19e5342060ca91aea247db99b927"><td class="mdescLeft">&#160;</td><td class="mdescRight">Specify the serial port.  <a href="#a58ff19e5342060ca91aea247db99b927">More...</a><br/></td></tr>
<tr class="separator:a58ff19e5342060ca91aea247db99b927"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Primary interface for communicating with an <a class="el" href="class_x_bee.html" title="Primary interface for communicating with an XBee Radio. ">XBee</a> Radio. </p>
<p>This class provides methods for sending and receiving packets with an <a class="el" href="class_x_bee.html" title="Primary interface for communicating with an XBee Radio. ">XBee</a> radio via the serial port. The <a class="el" href="class_x_bee.html" title="Primary interface for communicating with an XBee Radio. ">XBee</a> radio must be configured in API (packet) mode (AP=2) in order to use this software. </p>
<p>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(...) </p>
<p>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. </p>
<p>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.</p>
<dl class="section author"><dt>Author</dt><dd>Andrew Rapp </dd></dl>
</div><h2 class="groupheader">Member Function Documentation</h2>
<a class="anchor" id="a7d788232f44e8b3c10dc686a0299fcc6"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void XBee::readPacket </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty. </p>
<p>You may call <em>xbee</em>.<a class="el" href="class_x_bee.html#a18250def80e8b643aa1ccc15a98937f3" title="Returns a reference to the current response Note: once readPacket is called again this response will ...">getResponse()</a>.isAvailable() after calling this method to determine if a packet is ready, or <em>xbee</em>.<a class="el" href="class_x_bee.html#a18250def80e8b643aa1ccc15a98937f3" title="Returns a reference to the current response Note: once readPacket is called again this response will ...">getResponse()</a>.isError() to determine if a error occurred. </p>
<p>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 </p>

</div>
</div>
<a class="anchor" id="ae1c9f3b53df50564ab9aca2716792b44"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">bool XBee::readPacket </td>
          <td>(</td>
          <td class="paramtype">int&#160;</td>
          <td class="paramname"><em>timeout</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Waits a maximum of <em>timeout</em> milliseconds for a response packet before timing out; returns true if packet is read. </p>
<p>Returns false if timeout or error occurs. </p>

</div>
</div>
<a class="anchor" id="a594e2bb2ccb7b3fe7a2278b9324b4083"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void XBee::readPacketUntilAvailable </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Reads until a packet is received or an error occurs. </p>
<p>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: <a class="el" href="class_x_bee.html#ae1c9f3b53df50564ab9aca2716792b44" title="Waits a maximum of timeout milliseconds for a response packet before timing out; returns true if pack...">readPacket(int)</a> </p>

</div>
</div>
<a class="anchor" id="a58ff19e5342060ca91aea247db99b927"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void XBee::setSerial </td>
          <td>(</td>
          <td class="paramtype">Stream &amp;&#160;</td>
          <td class="paramname"><em>serial</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Specify the serial port. </p>
<p>Only relevant for Arduinos that support multiple serial ports (e.g. Mega) </p>

</div>
</div>
<hr/>The documentation for this class was generated from the following files:<ul>
<li><a class="el" href="_x_bee_8h_source.html">XBee.h</a></li>
<li>XBee.cpp</li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Sat Feb 1 2014 18:47:30 for XBee-Arduino by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>
