Skip to content

Commit

Permalink
Implemented threading support
Browse files Browse the repository at this point in the history
If a callback method is passed to the XBee constructor, a new thread will be spawned.
This thread will call the given callback method with any valid data received
from an XBee device. In order to clean up this thread properly, halt() must be called
on an XBee instance before closing its associated serial device.
  • Loading branch information
pmalmsten committed Jul 9, 2010
0 parents commit e9687e0
Show file tree
Hide file tree
Showing 23 changed files with 2,281 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
syntax: glob

*.pyc
*.svn
25 changes: 25 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
v1.5.0, 6/27/10 -- Initial Packaging. Fully restructured into a unified API with tests.
v1.7.0 6/29/10 -- Now supports both Series 1 and Series 2 modules
(the API turned out to be the same). Additionally:
* API frame logic was split into its own class, APIFrame
* XBee renamed to XBeeBase
* XBee1 renamed to XBee
* Tests updated to reflect changes; API frame tests
moved to test_frame.py, now test APIFrame instead of
XBee base class
* Test files renamed appropriately
* PyLint score improved
* Various docstring updates
* Updated example code to reflect changes
v1.8.0 7/8/10 -- Implemented threading support
* If a callback method is given to the XBeeBase constructor,
a new thread will automatically be spawned. This thread
will read from the serial port and call the given callback
method whenever a valid data packet arrives.
* XBeeBase.halt() was added. This method ensures the proper
shutdown of a separate thread if one has been spawned.
This method must be called before closing the serial
port used by an XBee instance in order to prevent
improper use of the serial port.


21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License

Copyright (c) 2010 Paul Malmsten, Amit Synderman, Marco Sangalli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
4 changes: 4 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include *.txt
recursive-include docs *.txt
recursive-include examples *.txt *.py
recursive-include scripts *.py
80 changes: 80 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
=========
XBee
=========

XBee provides an implementation of the XBee serial communication API. It
allows one to easily access advanced features of one or more XBee
devices from an application written in Python. An example use case might
look like this::

#! /usr/bin/python

# Import and init an XBee device
from xbee import XBee
import serial

ser = serial.Serial('/dev/ttyUSB0', 9600)
xbee = XBee(ser)

# Set remote DIO pin 2 to low (mode 4)
xbee.remote_at(
dest_addr='\x56\x78',
command='D2',
parameter='\x04')

xbee.remote_at(
dest_addr='\x56\x78',
command='WR')


Usage
============

Series 1, Series 2
------------------

To use this library with an XBee device, import the class
XBee and call its constructor with a serial port object.

In order to send commands via the API, call a method with the same
name as the command which you would like to send with words separated
by _'s. For example, to send a Remote AT command, one would call
remote_at().

The arguments to be given to each method depend upon the command to be
sent. For more information concerning the names of the arguments which
are expected and the proper data types for each argument, consult the
API manual for your XBee device, or consult the source code.

Caveats
---------

Escaped API operation has not been implemented at this time.

Dependencies
============

PySerial

Additional Dependencies (for running tests):
--------------------------------------------

Nose

XBee Firmware
-------------

Please ensure that your XBee device is programmed with the latest firmware
provided by Digi. Using old firmware revisions is not supported and
may result in unspecified behavior.

Contributors
==================

Paul Malmsten <[email protected]>

Special Thanks
==================

Amit Synderman,
Marco Sangalli
28 changes: 28 additions & 0 deletions deprecated/test.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import unittest
import os

test_modules = ['xbee.tests.test_xbee',
'xbee.tests.test_xbee1']

tests_path = 'xbee/tests'
tests_module_path = 'xbee.tests.'

def run_tests():
runner = unittest.TextTestRunner()
superSuite = unittest.TestSuite()

# Walk tests directory
path = os.path.abspath(tests_path)
for path, dirs, files in os.walk(path):
for f in files:
name, ext = os.path.splitext(f)

if ext == "py" or ext == ".py":
# Combine the name of the module with the package path
# This works because xbee.tests is a package
superSuite.addTests(unittest.defaultTestLoader.loadTestsFromName(tests_module_path + name))

runner.run( superSuite )

if __name__ == "__main__":
run_tests()
Loading

0 comments on commit e9687e0

Please sign in to comment.