BrainStem.NET Library

The BrainStem.NET library is a C# implementation of the Acroname BrainStem command set. It is not a managed wrapper to the existing BrainStem C library, but is a native .NET library that writes to the BrainStem using its serial protocol. The library was built with Visual Studio 2008 against the .NET 2.0 Framework.

I’ve released this library under the BSD License. Pre-compiled binaries and source code are provided in the distribution below.

Command Set

I started this library with the specific goal of moving servos for a robotics project. As such, I only intended to implement some of the commands available through the serial protocol. However, once I got started, I included support for digital and analog-to-digital IO, system parameter gets and sets, and a number of other features. At the time of this writing the following commands are supported:

Command Set

Test Harness

I’ve included a Windows application to test the library. This application is akin to the GP Application from Acroname. Here are a few screenshots:

Screenshot 1 Screenshot2 Screenshot 3 Screenshot 4 Screenshot 5

Documentation

I used Sandcastle and the Sandcastle Help File Builder to generate the documentation. It’s included in the downloadable package in compiled help format (.chm). An online version is also available.

Getting Started

A look at the test harness is a great way to familiarize yourself with the library. I’ve also included Command-Line and Windows sample projects, but here’s a few notes on getting started.

There are three main classes, all in the Bespoke.Robotics.BrainStem namespace: Packet, Stream, and CommandManager. Packets represent communication units within the system (Host-to-BrainStem, BrainStem-to-Host, and BrainStem-to-Router). You won’t normally need to create packets on your own, nor process received packets. The CommandManager class will handle all of this for you. The Stream class represents a connection between the host and the BrainStem. This class handles the reading and writing of Packets over the serial port. The Stream class includes two event hooks, HeartbeatReceived and PacketReceived, that allow you to process received packets if you’re so inclined. Again, the CommandManager will handle this for you, but this can be helpful at times. The CommandManager class contains a series of static methods that represent the supported command set.

You can setup the API with as little as 3 lines of code. Instantiate and open a Stream object and initialize the CommandManager with the newly opened Stream.

Stream stream = new Stream();
stream.Open();
int commandReplyTimeout = 1000;
CommandManager.Init(stream, commandReplyTimeout);

After that, begin making calls to the CommandManager methods.

CommandManager.SaveServoParameters(mModuleAddress);
CommandManager.SoftwareReset(mModuleAddress);

More Information

If you have any questions or comments I’d like to hear from you. You can reach me at pvarchol@bespokesoftware.org or leave a comment below.

Downloads (Current Version: 2.0 – Release Date: 1/17/2010)

Previous Revisions