Steve's blog

A blog about what's going on in Analysis UK...

Build Indicator - Part 3 (The software)

This is part 3 of the Build Indicator series. In this part I describe the communications library and using this as part of a MSBuild task as well as the test harness.

Previous Parts :

License : Please use, copy and modify this code as you wish, all I ask is that you don’t take credit for the bits I wrote. You should ensure it’s fit for purpose before using it.

The Arduino build indicator works via fairly simple RS232 communications so you can adapt your own build monitor (or other system) to use the indicator easily, or download the Arduino build indicator library and use/modify to suite your needs. You can also download the firmare for the Arduino from here.

The library consists of 3 projects at this time :

  • The main communications project.

  • A MSBuild task project.

  • A test harness.

All the software described here is written in C# and targets .NET 2.0 so it should be usable from any .Net 2.0+ project, you can add the AnalysisUK.BuildIndicators.Arduino.dll as a reference or include the project and reference that as part of the solution.

In the download is a Arduino.sln Visual Studio 2005 solution file which includes the main communications project, the MSBuild task project and the Test Harness WinForms program.

The Communications project :

This project consists of four classes and one enumeration.

  • ArduinoController – this is the main class to use for communicating with the Arduino.

  • ArduinoSimulator – this is a mock of the main controller class which does nothing other than to write the command to the debug window, but is useful when hardware isn't available. It is a subclass of the main ArduinoController class.

  • ProjectStatus – this is an enumeration detailing the project status.

  • CommandBase – this is a base class which all commands to be sent to the Arduino should inherit from. Currently there is only one command but it may well be extended in the future.

  • SetProjectStatusCommand – this is a command class which should be sent to the Arduino via the controller to set the project status.

Using the controller :

The below code is from the MSBuild task and shows how to use the command and controller.

SetProjectStatusCommand command = new SetProjectStatusCommand(ProjectNumber, (ProjectStatus)Status);

using (ArduinoController controller = new ArduinoController())
controller.CommPort = CommPort;

When the SendCommand method is called with the command this is sent to the Arduino which updates the output corresponding to the ProjectNumber to show the Status.

Using MSBuild :

Included in the download is a MSBuild task. This can be included in a MSBuild project and called to update the status.

You can either copy the targets and task reference from the TestBuildStatusIndicator.proj MSBuild file or use the file directly. You will need to correct the AssemblyFile location.

The ProjectNumber and CommPort should be updated to the Comm port the Arduino is on and the appropriate project number.

To call the sample MSBuild tasks from a Visual Studio command line use :

MSBuild TestBuildStatusIndicator.proj /t:IndicateBuildGood

MSBuild TestBuildStatusIndicator.proj /t:IndicateBuilding

MSBuild TestBuildStatusIndicator.proj /t:IndicateBuildFailed

The MSBuild targets are defined as :

<Project DefaultTargets="IndicateBuildGood" xmlns="">

<UsingTask TaskName="AnalysisUK.BuildIndicators.Arduino.MSBuild.BuildStatusIndicator" AssemblyFile=".\bin\Debug\AnalysisUK.BuildIndicators.Arduino.MSBuild.dll"/>


<Target Name="IndicateBuildFailed">
<BuildStatusIndicator CommPort="$(CommPort)" ProjectNumber="$(ProjectNumber)" Status="1" />

<Target Name="IndicateBuildGood">
<BuildStatusIndicator CommPort="$(CommPort)" ProjectNumber="$(ProjectNumber)" Status="2" />

<Target Name="IndicateBuilding">
<BuildStatusIndicator CommPort="$(CommPort)" ProjectNumber="$(ProjectNumber)" Status="6" />

Using the Test Harness :

Also included in the project is a test harness, this is a simple WinForms application which again uses the main communications project and provides a simple UI to exercise the build indicator.

Future parts :

I'm currently working on including the Arduino build indicator into CCTray for use with CCNET so that will be available in a future posting.