Skip to content

Sending multi-byte values from Python to an Arduino board

Arduino is an open-source electronics prototyping platform. Several of our clients are using Arduino systems to build custom embedded components for scientific data acquisition. Arduino systems are cheap, flexible and quite easy to program using a specialized C-dialect and a pleasant IDE that comes with the Arduino SDK.

Many Arduino boards have a serial-over-USB connection for communicating with a host computer. We often use pyserial to communicate with these systems from Python. It’s not obvious how to send multi-byte values (such as Python integers) across the serial connection to an Arduino board, however. Todd Stavish wrote some nice code to send multi-byte values for one of our projects and read those values on the Arduino side using C unions:

http://blog.stavi.sh/python-code-that-writes-a-multibyte-value-lon


Physion Consulting is Hiring

Do you want to help change the face of basic science? Physion Consulting is hiring full time developers in the Boston, MA area to work on our upcoming scientific data management system. Demonstrable ability in software engineering, an interest in basic science and an appetite for learning are the only requirements. A CS degree or experience in a basic science lab are great.

We’re a self-funded startup, with paying customers. We care about our developers, offer competitive pay, full medical & dental benefits and a great work environment. We’ll gladly help you set up an internship in a lab or pay for classes if you’d like to learn more about the science our customers are doing.

Interested? Send us your CV. We’d love to see a link to your blog too.

NSF to require Data Management Plans from funded labs

The National Science Foundation recently announced that, beginning around October, 2010, all research proposals will require a data management plan.

It just so happens that Physion Consulting has a data management system in the pipeline. Stay tuned…

Tagged

GTM + TestMerge.app = UI testing bliss

I’m pleased to announce TestMerge.app, a tool that we’ve developed as part of the Core Plot project to aid managing the output of the Google Toolbox for Mac (GTM) framework.

Download

You can download TestMerge.app from the Core Plot downloads section or build from source by pulling from the Core Plot repository (hg clone https://core-plot.googlecode.com/hg/ core-plot).

Using TestMerge

GTM’s image and state comparison macros generate named rendered output of NS/UIViews, CALayers, NSWindows or the encoded state of NSObjects respectively. If an existing reference file of the same already exists in the test bundle’s Resources/ folder, the new output is compared against the reference with the test failing in the case that there is a mismatch (pixel-by-pixel or text) between the files. If no reference file exists, a new output file is generated. The GTM test macros make unit testing UI’s almost too easy. In Core Plot, we generate tens or hundereds of outputs from these macros on each test run.

When tests fail because the generated output doesn’t match the reference output, users of GTM’s test macros must manually compare the reference and output files, decide which to keep, then move files appropriately if needed. Since the failed output has a ‘_Failed’ suffix appended to the image/encoded state file’s name, the developer must rename the file if moving it to overwrite the existing reference file. Clearly, this can become a little cumbersome and will eventually lead to bit rot of the reference files.

Enter TestMerge.app. Taking the path to the folder of reference images and the path to the folder of output images in $TM_REFERENCE_PATH and $TM_OUTPUT_PATH environment variables respectively, TestMerge.app presents a UI for browsing and selecting from the reference/output comparisons. Only new output files (those with no corresponding reference) or failed output files (those that do not match their reference) are shown by TestMerge. Selecting a name on the left panel will show the reference and output for the image or state file with that name.

Screenshot of TestMerge image comparison
Screenshot of TestMerge image comparison

In the screenhot shown at the right (of TestMerge showing the output of its own unit tests), a named image pair is selected in the left pane. The referenc image is then shown on the left and the new output is shown on the right with the pixel differences highlighted in red. Encoded state output is shown similarly (though no fancy highlighting is done on the text diff yet).

Selecting “Select Reference” from the “Merge” menu selects the existing reference as the correct image or state (indicating a true test failure). Conversely, selecting “Select Output” from the “Merge” menu marks the new output as the correct new reference image/state (indicating that the programs out has changed and the test needs to be updated to match this new, correct, output).

A blue outline indicates the selected file (reference or output) in the right pane.

When you quit TestMerge, you’ll be promted to commit the choices you’ve made. If you selected the reference file for a pair, the new output will be deleted. If you selected the new output for a pair, the old reference file will be replaced (after appropriately renaming the output file). If you made no selection for a pair, both files will be left untouched. Obviously choosing to not commit the selections leaves all files untouched.

You’ll still have to manually add new reference files to your Xcode project unit test target, and you’ll have to add new files to your SCM, but TestMerge can’t do it all on the first version or there’d be nothing left to work on.

That’s it. A simple tool for a simple job.

The Core Plot (and TestMerge) projects are already configured to run TestMerge automatically after each unit test run. To do the same in your Xcode project, add a Run Script build phase after the Run Script build phase that calls your test runner. In the new phases’ script use

# Run TestMerge to merge GTM output, if necessary

export TM_REFERENCE_PATH=${PROJECT_DIR}/TestResources
export TM_OUTPUT_PATH=~/Desktop

TEST_MERGE_PATH/TestMerge.app/Contents/MacOS/TestMerge

You’ll have to modify the export lines to give the appropriate paths for your project. GTM’s output goes to ~/Desktop by default. You’ll also have to replace the TEST_MERGE_PATH with the appropriate path on your system.

Please file issues on the Core Plot issues tracker. Happy testing!

Tagged , , ,

Deprecating scikits.ann in favor of scipy.spatial

Now that scipy.spatial has a very competent KDTree implementation (in both python an C versions), Rob and I feel that it’s probably best to stop development of the ANN wrapper. It’s in a workable state and the code won’t be going anywhere, but any of our future efforts will go towards scipy.spatial. Give it a try.

Tagged ,

Container performance in Matlab

A colleague has been fighting with Matlab’s new object-oriented language features and Matlab’s hybrid pass-by-value and pass-by-reference semantics. His findings are quite interesting.

SciPy 2008 Proceedings online

The proceedings of the 2008 SciPy conference are now online. The articles provide a snapshot of some of the great work being done using SciPy as well as valuable references for SciPy users. Gaël Varoquaux has done a great job getting the whole collection in shape. Thanks Gaël!

Data type and byte order conversions for NSData using the STL

We’ve been spoiled working in Python’s numpy array library. Converting data types or byte order for numeric data in a numpy array is trivial (thanks to the work of numpy’s authors of course). When we’re in Objective-C land, the inability to change data types or byte orders on NSData instances is frustrating. So we’ve written a short C++ header that provides templated functions for converting the data type and/or byte order of numeric data stored in NSData/NSMutableData instances. I think it might be useful for others who don’t want to (re)learn C++ and the STL. Writing code in Objective-C to accomplish the same functionality is a mess of if/then/else or switch statements. Every job has a tool and C++ templates seem to be the best tool for this job (numpy’s authors have a similar solution using a code generator to keep things all in C).

For the brave and or insterested, take a look at NumericDataTypeConversions.h (BSD license). Bug reports or patches are welcome. Since it’s a C++ header, any Objetive-C file that includes it will have to have the .mm extension (or otherwise ensure that the file is compiled as Objective-C++). Happy coding.

scikits.ann in PyPI

After several folks had trouble getting the scikits.ann egg from the server listed in previous posts, I’ve uploaded the source and OS X 10.5 egg to PyPI. You can now install it via easy_install. Of course, you can still get it via the scikits SVN.

ANN namespace madness

I hadn’t checked the scikits Developer’s Trac recently. Apparently it’s now OK to use non-BSD (but OSI approved) licenses in the scikits namespace. So I’ve moved our ANN wrapper back. You can get it from the scikits SVN or via

easy_install -f http://rieke-server.physiol.washington.edu/~barry/python/ scikits.ann

if you’re on OS X 10.5.