Steve's blog

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

Windows 7 .iso file handling – Close but No Cigar!

Typically when I have an iso file what I want to do is mount it as a DVD Drive, not spend 10 minutes burning the thing just so I can then read it on the same machine and in the process wasting a DVD and causing more environmental damage with the plastic. OK so that's useful if I take it to a different machine or need to boot from the disk, but that's rare for me now days.

Guess what, in Windows 7 you can burn a iso image to disk. Great, that's a nice touch, but you can't mount the thing!

Windows 7 burn iso image to disk

One cool addition to Windows 7 is being able to create and map a .vhd (virtual disk) as a disk on the machine in Disk Management (I've not tried it yet – apparently you can even boot from it – freaky & cool!). Now tell me why can I do that and yet I can not attach a iso image file, that's massively frustrating.

What makes it really crazy is that when you download from MSDN you get .iso files, now even with Vista you have to go and get extra software to handle them. At least you can burn them easily in W7 but really, I should be able to download a SQL server 2008 iso from MSDN, right click and mount it in W7 and install it.

I store all the iso's I download from MSDN on a network share and access them as I need them. If I burn them to disk I just loose them, so the bulk iso storage works really well for me.

It's similar in Server 2008 R2, no option to mount the CD/DVD and by default the burn option isn't their either – but then that's for the best really as I'd want the default install to be locked down as much as possible.

I did wonder if their was some kind of legal, patent, copyright issue around the iso image thing, but Hyper-V can mount an iso image to be use as a CD/DVD drive in a Hyper-V instance so why can't Windows 7 do that?

Please Microsoft give us the ability to mount an iso image as a DVD drive!

Until they do I'm sticking with MagicISO which works a treat – and it's freeware! (Thank you MagicIso inc!).

I'm also hoping one day we see DVD drives that can do LightScribe or similar without having to flip the disk but I doubt we will ever see that (at least for a reasonable price!).

Windows 7 Taskbar – FAIL!

Like many others I've been trying out Windows 7 just recently.

My trial of it didn't start well with the MSDN version being available around the same time as the public release – I mistakenly thoughts as a paying MSDN subscriber I might get it a little earlier but hey, I get to find out and fix any problems in my applications at the same time my users get to see the issues. Still at least my stuff doesn't eat your MP3's!

I installed a test version of W7 in a Hyper-V instance which didn't go all that smoothly either, first time around and I had to have a second go, but that might have been because I put the iso of Windows 7 on a NAS and a network problem may have crept in causing the installation not to find the files it wanted.

Next (I think) because I access my Hyper-V set-up using the Hyper-V MMC snap-in from my Vista box copy and paste doesn't work between the two machines so entering the product code and trying to paste the Url in to browse for the patch to stop W7 trashing my MP3's was painful. But hey, I should save my Hyper-V bashing for another day as I could go on for some time about that!

What really annoys me with W7 is what has happened to the taskbar.

Apparently I'm not alone. Don't get me wrong, I'm not against change and I like a lot of what's changed over the years in Windows, generally it's been for the better.

With Vista, XP and those before it I actually like the quick launch toolbar. I like it having small icons and I use it heavily (I have 18 apps in there). I also like the notification area, not massively but for a lot of applications it's perfect. Theirs a number of application I don't want in their and think they should live else where (like the ATI stuff, SmartStamp, OpenOffice QuickStart) but I can live with that.

In XP Microsoft gave us the collapsing notification area and initially I adopted that but ended up finding it annoying, the worst of which was with Outlook email notification as I had times when XP would decide it should hide it and then you didn't get to see it hence ignoring new email (OK so not a bad thing) or other times when receiving a lot of emails it would cause the notification area to shrink and grow which was really annoying and had a side effect on the running programs and made it difficult to hit the correct icon.

There is one big problem with the quick launch, toolbar and notification area in XP and Vista and it's this that I believe Microsoft are trying to solve with the redesign in Windows 7. The problem is you can't fit much into the default Quick Launch and Notification areas.

So the way I see it is you have two options:


  • Go the Windows 7 route and redesign the toolbar – FAIL.

    Windows7 Toolbar

    Windows7 Toolbar


  • Make the toolbar 2 units high by default – this works a treat for me!

    Vista toolbar 2 units hight

    Vista toolbar 2 units hight



Let me explain why I don't like the new Windows 7 Toolbar:


  • The new taskbar is to tall – way to tall. It's smaller than my current Vista taskbar because I have that 2 units high, but the height for 1 unit in Windows 7 is not far off the 2 unit Vista one, so that means when I set it to be 2 units high it's massive - stupidly massive. I'll explain shortly why I like the toolbar 2 units high.


  • I've never liked the grouping option of the Taskbar. I see that's on by default again, you can switch that off, or to group when it's full.

    What I also don't get is why when grouping is on and you only have 1 instance of the app do you just get the icon but when it's off you get the icon and the application name? Why not the icon and app name normally? Although if you do show the application title like we are use to it becomes ever more confusing as to how you “quick launch” an application.

    Anyway, I can never find the running application I want when grouping is on.


  • Theirs not really a quick launch bar any more, you can pin your applications to the toolbar instead. These are full height icons taking up a lot of space (width and height) and then when you launch the application guess what, the icon stays where it is looking just like the launch icon, except when you click it again it actually minimises the window.

    Now some applications are slow to load, some get messed up and load outside the screen area or minimise incorrectly/badly on start-up or go straight to the notification area on start-up you could end up in a big mess figuring out what's going on with the W7 way of taskbar launching.

    And if you've launched an application from the taskbar and want to start a new session of it (say you want another IE 7 because you've got to many tabs open in the current IE7) it's really not obvious. You have to right click the icon and then choose the application name from the menu. novel!


  • The notification area, if you use it correctly it's great and sadly some apps abused it. Now for something like Dinner Timer Lite you really want that icon showing so you can send the running Dinner Timer Lite instance to the tray and hover over it to see how long you've got left quickly and easily, not click an up arrow then hover.

    Other application change colour or blink to inform you of things, this can be really useful, sometimes the icon changes such as when you mute the speakers and it's useful to see that at a glimpse, but for most of the time it's easy to ignore the notification area if you are not interested.

    Still at least with the notification area there is some hope as you can set it back to how it was, Except, now that one little icon takes a lot of space and if you make the toolbar 2 units high you can only get 2 icons vertically, so the waste of space isn't especially resolved.


Here's how I fix the Vista/XP ToolBar problems:



I make the taskbar 2 units high. Nice and Simple!

You get a lot more running applications in the taskbar before it gets overly cluttered (to the point that my head gets cluttered before the taskbar).


  • You get 2x as many applications in the quick launch toolbar.


  • You get 3x as many applications in the notification area.


  • You get to see the date, time AND the day of the week in the clock area (which I really like).



On a default Windows Vista/XP set-up anything more than 6 icons in the notification area is a pain and similar for the quick launch area.

With 2 units high I have 18 quick launch apps, 13 notification icons, the date, time and day and currently 11 running applications without a problem.

Now I have a 22” wide-screen monitor so things are a little easier but I run exactly the same set-up at work where I have only a 19” square monitor and it works just as well, if not better as the quick launch and notification area don't take up hardly any room.

So you have two choices:

Either:


  • Implement a really easy change to Windows 7 and make the toolbar 2 units high by default, keeping everything else exactly as it is in Vista and XP so building on what you know and not introducing new code.


  • Change the taskbar to a new way that people have to adapt to, change the way you quick launch applications, change the way you see your notification icons, introduce new and most likely more complex code to the Windows 7 Code base which will not have been tested as well as previous versions.


Personally, I think that the XP/Vista taskbar works well and that making it 2 units high solves the problems with the quick launch and the notification area and making the change in Windows 7 just introduces code that isn't needed and with no doubt lots of new and fun bugs.

Fingers crossed that theirs an option to use the previous taskbar implementation in W7 or failing that some amusing adverts mocking the new taskbar so the pain has some good.

DNS Problems

Apologies for the recent outage of Dollars2Pounds and the other exchange rate sites. You may not have noticed if you or your ISP had the DNS values in cache as the site was actually up and running.

Just a couple of days ago I updated Dollars2Pounds to use the DNS servers of the host I have the server with, thinking that it would reduce the load on my servers and that they would be less likely to go down than my servers.

How very wrong I was, earlier this evening I got an email from the site monitoring service I use (site up time) telling me that Dollars2Pounds was unreachable.

A quick check and the site was up and running but the DNS servers were not returning anything and the host providers main web site was down as well.

Hopefully this is a rare occurrence, however since EV1Servers got taken over things have gone badly, not least the 3 day outage recently when a transformer blew up.

Lets hope things improve as it's really painful to change hosts and you don't really know what will happen at a new hosts.

I've also managed to accidentally knock the odd site off line over the past week whilst I've been setting up the accounts on the new server.

The good news is that all my exchange rates sites (Dollars2Pounds, Pounds2Euro etc.) are now on a more powerful server and using a more up to date exchange rate source which is updated every 15 or 60 mins. dependent on the currency pair.

MSBuild Item List Iteration

Repeating a task for each item in a MSBuild item list is really easy if the task supports ; seperated lists, if not, well it's still easy but trying to remember the syntax is another matter!

This keeps catching me out and I've seen few examples of its use around so if for no other reason than as a reminder to myself here's how to iterate a list of items with MSBuild.

Define your item list as something like:

<ItemGroup>
<InstallerFiles Include="$(MSBuildProjectDirectory)\Setup\**\Release\*.msi" />
</ItemGroup>

In this example I have a folder .\Setup\ which contains multiple subfolders of different setup projects which generate msi files.

Method 1:

<Target Name="CopyOutput">
<Message Text="Copying installers to Build Output folder. Source = @(InstallerFiles)"/>
<Copy SourceFiles="@(InstallerFiles)" DestinationFolder="$(BuildOutputFolder)" />
</Target>

This example copies all of the msi files into the BuildOutputFolder.

This method relies on the Copy target to accept a “;” separated list of values. Sadly if you have a task that only takes a single value then your a little stuffed with the @ operator.

Method 2:

<Target Name="CopyOutput">
<Message Text="Copying installers to Build Output folder. Source = %(InstallerFiles.FullPath)"/>
<Copy SourceFiles="%(InstallerFiles.FullPath)" DestinationFolder="$(BuildOutputFolder)" />
</Target>

This method will call the Copy task once for each item in the InstallerFiles list. But that's not really a fair example as you can just use the @ operator for Copy.

Here's another example that's more appropriate.

<PropertyGroup>
<DeploymentLocalPath>$(CCNetWorkingDirectory)\Setup\</DeploymentLocalPath>
<VersionUpdater>VersionVDProj.exe</VersionUpdater>
<VerisonFile>$(CCNetWorkingDirectory)\Version.txt</VerisonFile>
</PropertyGroup>

<ItemGroup>
<SetupProjects Include="$(DeploymentLocalPath)**\*.vdproj" />
</ItemGroup>

<Target Name="Version">
<!-- Some bits to set MSIVersion normally go here and have been removed for clarity →

<Exec Command='$(VersionUpdater) -msi "%(SetupProjects.FullPath)" version=$(MSIVersion)'/>
</Target>

Here I use the VS.NET Deployment Project Version Updater (http://www.codeproject.com/KB/install/VersionVDProj.aspx) to update each of the setup projects with the MSIVersion number, but this could be any colsole application that took a filename.

The .FullPath is a “Wellknown Item Metadata” property. Theirs more listed on the MSDN page

Sara Ford also has an example of a good use of metadata for recursive copying (http://blogs.msdn.com/saraford/archive/2005/11/08/490445.aspx).

Theirs also an interesting MSBuild wiki over on Channel 9.

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;
controller.Open();
controller.SendCommand(command);
}


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="http://schemas.microsoft.com/developer/msbuild/2003">

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

<PropertyGroup>
<ProjectNumber>1</ProjectNumber>
<CommPort>COM5</CommPort>
</PropertyGroup>

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

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

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


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.

Dinner Timer Lite V1.1 Released – and it's Huge!

Literally, huge. Below is a photo of my 22” wide-screen monitor with Dinner Timer Lite running. As you can see it fills the screen nicely with a big font – now you can easily see Dinner Timer Lite from the other end of the kitchen or further.

Photo of large Dinner Timer Lite

before you ask, yes you can make it smaller!

Just in-case you are wondering, yes that is the snowman build indicator on the left and it's not lit up because the build machine wasn't running (saving a little electricity and reducing the heat in the office!).

There are a few other cool additions to V1.1, these include :

Added Twitter notifier – now notify your friends and family automatically when you start dinner, when it will be ready, tweet notifications when it's about to be ready, when it's ready and through Dinner Timer Lite's unique overrun timer tweet when the dinners burnt.

Here's screen shot of setting up the Twitter notifier to send out a message when the timer has overrun :

Twitter

Here's a screen shot of my Twitter tweets. You can also follow me as BookSwapSteve on Twitter

Tweets

I've also improved bubble notifications – Bubble and twitter notifiers now support text template replacements. Include any of the following for them to be replaced with the appropriate values when run : {{RunMins}}, {{StartTime}}, {{EndTime}}, {{MinsRemaining}}, {{MinsOverrun}}.

Additional sounds for the sound notifier including : Cow moo, Air horn, Alarm beep, Alarm clock beep, Alarm ring, All clear, Ambulance, Aooga horn, Boat air horn, Boing, Boing2, Boxing bell multi, Bullet ricochet, Buzzer, Buzzer 2, Buzzer 3, Buzzer 4, Buzzer 5, Buzzer heavy, Buzz through loud, Buzz thru and Chainsaw.

The time options available in the drop down list is now user configurable and includes the ability to name the times. e.g. you can enter a timer called "Pizza" and have it set as a 12 minute timer, the list will then show Pizza which can be easily selected and when the timer is started it will run for 12 minutes.

Here's a sample of modifying the time option to show pizza :

Setting the time options.

Selecting the pizza time.

The options boxes have been resized for the default Windows Vista font size.

I've also added warnings for opacity settings where the timer may not be visible and a extra context menu item has been added to the notification area icon to reveal the timer if it is difficult to see. Both myself and a few others had managed to get Dinner Timer Lite to be so transparent that we couldn't find it to restore it.

I've also changed the installer to be a single exe so no unzipping required and the binaries and installer are digitally signed so you know their genuinely from me (Analysis UK).

Their are also various under-the-cover improvements to facilitate some new features in the next release, including the first stage of splitting out of the notifiers from the main application with the intention of allowing developers to create their own notifier plugins, but thats going to have to wait for a future version before it's fully implemented.

Moving from .NET 2.0 to .NET 3.5 on Plesk - welcome to Server Application Unavailable errors

I just uploaded a new version of DinnerTimer.com which moved from being a .net 2.0 site to a .net 3.5 site, the server has .net 3.5 installed and every thing went well until I navigated to DinnerTimer.com

I was greeted by :

Server Application Unavailable
The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web browser to retry your request.
Administrator Note: An error message detailing the cause of this specific request failure can be found in the application event log of the web server. Please review this log entry to discover what caused this error to occur.

The error message in the event log was :

Exception: System.IO.FileLoadException

Message: Could not load file or assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Access is denied.

This struck me as a little crazy as all my other sites on the server are .NET 2.0 and the previous site was .NET 2.0.

After much searching on the net and trying a variety of things (including giving permission to the various IIS accounts to .net 3/3.5 folders in windows folder and setting up a dedicated 3.5 App pool for the site) I finally added IIS_WPG permissions on the "Web Sites" folder in IIS manager and the site magically appeared. Now I just have to wonder what the security implications are and if that broke any other sites.

You have to love simple upgrades! I'm not sure if this is a general issue with IIS or because I'm running plesk which uses different security & user settings to a normal IIS setup.

Analysis UK email problems

Apologies to anybody that's tried to email me in the last week but my emails been broken.

It turns out that the email service I use as a front end had an old personal email address in their billing information for me, so when my annual subscription was due I didn't get a reminder because I no longer have the personal email address I used (I finally ditched Demon and sadly lost the email address I had with them since about 1998 – my advice is don't get an email address tied to your internet provider – better yet, get your own domain name and use that for email so you are not tied to any company – but be sure to remember to renew your domain name!).

Having had lots of spam recently I through that the reduced level of emails was just because the spam was slowing down – the automated status emails from my web sites were still coming through because they went directly to the mail server and not via the front end thing, so it looked like I was still getting emails on that account, hence it wasn't until I sent my self an email from a separate account (I know – I need to get out more) and it bounced that I realised something was wrong.

Hopefully all fixed now.

The irony of the situation is that I signed up with the service so that I wouldn't loose emails if my email server went down. They provide 2 front end mail delivery servers that forward it onto the real mail server when it's running. I think I've lost more email because of it than I ever lost because my server was down.

Vista 64 Blue Screen Hell

I recently updated my development box to a nice new quad core processor and with it stuck in 8Gigs of ram. I would have been more than happy to stick with Windows XP as I had on my old dev box but the 32 bit version is limited to 4G (more like 3.5G) of ram so all that extra goodness would have been wasted, hence I crazily decided to opt for Vista 64.

What a mistake! It's like using Windows ME all over again and we all know what a terrible product that was.

So to start with the motherboard an Asus P5Q PRO for some reason doesn't support sleep which is a big thing with Vista, I would go off to have dinner and come back to find the PC rebooting because it had gone to sleep. Sadly I wasn't always that lucky – it would often corrupt the CMOS and loose the date/time. If I had one of my Arduino based projects such as the connected it would also be frozen at the Bios Legacy USB detect stage.

I can't really blame Vista for what is a motherboard problem so I've disabled the sleep function and replaced it on the Start menu with Shutdown. When I wrote LazyLoad I didn't think it would be useful on Vista because of the improvements Microsoft made – It hasn't taken long for me to realise LazyLoad is still well worth running on Vista!

So onto the real big problem I'm having, almost daily blue screen of death's. This appears to be caused by the ATI graphics card – a Radeon HD 3650, just great. I regularly get a blank screen followed by Vista telling me it's recovered from a stopped graphics driver. However almost daily the screens start blinking darkness and then when I've had enough time to glimpse at the work I'm about to loose it all goes blue claiming an ati driver failed.

Just to really annoy me when the machine reboots Vista prompts with it's “Windows has recovered from an unexpected shutdown” and gives me a “Check for solution” option, it then appears to do something, followed by quietly hiding it's self never to be seen again, not a sorry we couldn't find anything, or a try the vendors web site for the latest drivers, or a yep we know another ati driver problem, nope, it just disappears as if it's embarrassed and wants to quietly leave the room having wet it's self.

Windows has recovered from an unexpected shutdown

I've had ATI cards before and not liked them, I really should have known better. Whilst looking for the link for the 3650 on the ATI site the search summed ati up for me. I entered hd 3650 and hit enter to search, not realising I had to change the “Select Site:” drop down. I got a JavaScript box saying “Please select a site.” and they kindly cleared my search text so I had to enter it again (whilst not making the same mistake of hitting enter) and then select the ATI site. How could something so simple be so unfriendly?

And what's with the improved TCP/IP stack in Vista. I though networking with Vista was supposed to be much improved. If I watch a movie that's on another machine one of two things happens, either the file explorer will freeze and show the green progress bar whilst trying to browse the folders or when I finally open the file my whole PC will freeze whilst Windows Media player opens the file. And if the other machine is busy doing something like a backup I really know about it on my Vista box (BTW – often the other machine is a Vista box!). I thought with 4 cores a gigabit network and an improved TCP stack Vista would still be usable whilst it tried to sort out connections with networked machines. My old XP box with it's single processor was is so much better for networking.

As for the new “improved” windows explorer, I so hate it, I mean really hate it. If I'm trying to copy files or folders with Explorer in details view (which I prefer) from one location to another I regularly end up with them going into a sub folder of the destination because of the change in the way the hover selection works as it's really difficult to get exactly between the folders when dropping. As for default view (list view) that's just to annoying, You've got loads of extra column headings and if you have a long file name it's often obscured, it looks like you can resize the columns but that doesn't work – you have to change to details view to do that – it gets me EVERY time and annoys me intensely every time.

Is it just me or has the audio stuff got worse, my last box (XP) pushed out the audio via the SP/DIF and headphones socket at the same time, I can't see how to do that in Vista, so if I want to switch from headphones to speakers I have to stop what I'm listening to, change the default or use something like WinAmp's settings to change the output (not easy to get to) then change to the RCA Digital output. What a pain in the ****, I want both outputs together – is that such a stupid requirement? I wonder if that's another Asus special.

I'm so very glad FireFox remembers the pages I had open, all to often I've been part way through reading an article for the PC to blue screen on me and by the time I'm back up and running I've forgotten where I found the article. Fire up FireFox and restore - magic! I so wish IE did the same, especially as it's a lot less stable than FireFox and crashes it's self frequently.

So in conclusion, it's really great so much effort has gone into the Aero to make Vista look nice whilst introducing whole new instability issues, revaming Windows Explorer to take annoying to a whole new level whilst totally defeating usability and that the TCP has been speeded up to the point that Vista to Vista networking freezes the machine and browsing a file share regularly messes up, that's on top of the slew of security measures which resulted in me being unable to browse my NAS without having to get into the depths of Vista settings.

I appreciate most of the problems are actually hardware (MB/Graphics card) but it's still annoying to have seen so much effort go into making the thing look nice only to have it fall over, I've seen it all to often with various products where the manufacture has put lots of effort into making the thing look really nice but failed to make a usable product (more on that and my home automation problems latter). Take for example software products that have their window an unusual shape - I know instantly that I'm not going to be able to use it, all to often I've tried software where the products a funny shape and the functionality and usability of the product are just so poor – please please please lets get back to making usable products and get over our obsessive desire for things to look pretty whilst not worrying about being able to use them.

Well the good news is in the hour it's taken me to write this the machines not blue screened!

Build Indicator – Part 2 (The firmware)

This is part 2 of the Build Indicator series. Part 1 – the construction of the hardware is here.

The firmware is written using the Arduino’s own programming language which is much like C/C++, using the IDE provided it’s easy to develop the code and push it down to the Arduino.

I decided that as the Arduino has 13 IO pins it would be a shame not to make these available for 6 build indicators so 6 individual projects could be monitored. I’ve not used OO to implement the code so it’s a little messy with individual arrays for project status, red and green led pins which are indexed based on the project number. I think you can create classes but this has to be done in external C++ files so for a simple application like this I didn’t worry to add that extra complexity.

Serial (RS232) communications is used to send a status message down to the Arduino build indicator to update the project status.

The full Arduino build indicator code can be download here.

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.

Variable declaration :


    1 /*


    2   Build Indicator (c) Analysis UK Ltd 2008


    3  *


    4   Digital Pin Assignments:


    5   0 - RX


    6   1 - TX


    7   2 - Project 6 - Green LED


    8   3 - Project 6 - Red LED


    9   4 - Project 5 - Green LED


   10   5 - Project 5 - Red LED


   11   6 - Project 4 - Green LED


   12   7 - Project 4 - Red LED


   13   8 - Project 3 - Green LED


   14   9 - Project 3 - Red LED


   15   10 - Project 2 - Green LED


   16   11 - Project 2 - Red LED


   17   12 - Project 1 - Green LED


   18   13 - Project 1 - Red LED


   19  */


   20 


   21 #define VERSION "1.0"


   22 


   23 // Project not enabled of not connected.


   24 int PROJECT_OFF = 0;


   25 


   26 // Project build failed


   27 int PROJECT_FAIL = 1; // 001


   28 


   29 // Project build good


   30 int PROJECT_GOOD = 2; // 010


   31 


   32 // project building from a failed project.


   33 int PROJECT_BUILDING_FAIL = 5; // 101


   34 


   35 // project building from a good build.


   36 int PROJECT_BUILDING_GOOD = 6; // 110


   37 


   38 // Maximum number of projects.


   39 int maxProjects = 6;


   40 


   41 // Project status codes.  Indexed by project.


   42 int projectStatus[] = {


   43   0, 0, 0, 0, 0, 0};


   44 


   45 // Pins for the Red LEDs.  Indexed by project. 


   46 int redLEDPin[] = {


   47   13, 11, 9, 7, 5, 3};


   48 


   49 // Pins for the Green LEDs.  Indexed by project.


   50 int greenLEDPin[] = {


   51   12, 10, 8, 6, 4, 2}; // pins 0 and 1 reserverd for RS232.





The arrays redLEDPin and greenLEDPin represent the pins to use for the red/green leds and are indexed on the project number (i.e. project 0's red led is on pin 13). The array projectStatus holds the status of the project and again is indexed by the project number.

Setup:


   54 // run once, when the sketch starts


   55 void setup()                   


   56 {


   57   // Initialise the ports for output to drive the LEDs


   58   for (int i=0; i<maxProjects; i++) {


   59     pinMode(greenLEDPin[i], OUTPUT);    // sets the digital pin as output for the green/blue part of the tri color LED


   60     pinMode(redLEDPin[i], OUTPUT);      // sets the digital pin as output for the red part of the tri color LED


   61   }


   62 


   63   // Setup Serial communications


   64   Serial.begin(57600);


   65 }




The setup method iterates through all the projects setting up the pins designated as led’s for output and then sets up serial communications at a baud rate or 57,600. Fortunately the Arduino takes care of the difficult serial comms bits for us.

Main Loop:


   67 // Main loop, runs over and over again


   68 void loop()                   


   69 { 


   70   // Check and Read settings from PC


   71   ReadCommands();


   72 


   73   // Update the LED's to indicate project status'


   74   UpdateLEDs();


   75 


   76   // Idle.      


   77   Idle();


   78 }


   79 




The loop method is the main application loop that the Arduino will enter once setup is complete and will keep repeating.

Within loop we call 3 basic methods, ReadCommands() which will check the serial port for commands from the host, UpdateLEDs() which will update the leds based on the project status and Idle() which just inserts a small delay but can be used for other background tasks.

The comms protocol is a fairly simple one. All messages should start with a byte value of 2 and terminate with a byte value of 3 so the Arduino can easily know when a instruction has been received.

To update a project status send the ascii string “@P[x]=y” with x being the project number 1-6 and y being the status (0, 1, 2, 5, 6).

To query the version number of the firmware send ?V.

I’ve stolen the comms protocol from another project I’m working on with the Arduino that has more commands and queries so I’ve based all commands where the Arduino has to do work on the @ character and all queries on the ? character to help separate out the commands and queries.

RS232 Message handling:


   86 // Read commands sent from the PC


   87 void ReadCommands()


   88 {


   89   // Check if serial data available, if so then read this in


   90 


   91   // Read all from the serial port until no more bytes available looking for the


   92   // start byte (1) of a message.


   93   while (Serial.available()) {


   94     //read the incoming byte:


   95     int incomingByte = Serial.read();


   96 


   97     // Start identifier.  STX


   98     if (incomingByte == 2) {


   99       // Found start byte now read in until we get the end of message byte.


  100       ReadSeialCommand();


  101       return;


  102     }


  103   } 


  104 }


  105 


  106 // Read a command from the serial port.  Read until the read byte


  107 // is an end of message (new line) indicator.


  108 void ReadSeialCommand() {


  109   // Expect maximum of 25 bytes (normally 6)


  110   byte buffer[25];


  111   int index=0;


  112 


  113   while (true) {


  114     if (Serial.available()) {


  115       // read the incoming byte:


  116       int incomingByte = Serial.read();


  117 


  118       // Terminating byte


  119       // Wait for ETX (End of text - transmision)


  120       if (incomingByte==3) {


  121         ProcessRequest(buffer);


  122         return;


  123       }


  124       else {


  125         buffer[index] = incomingByte;


  126         index++;


  127       }


  128 


  129       // Check for buffer overflow and give up if it has.


  130       if (index>25) {


  131         Serial.print("Error:Buffer Overflow.\n\r");


  132         return;


  133       }


  134     }


  135   }


  136 }


  137 


  138 void ProcessRequest(byte request[]) {


  139 


  140   boolean processed = false;


  141 


  142   // Check for Query commands (? at the start)


  143   if (request[0] == 63) {


  144     // Query


  145     processed = ProcessQuery(request);


  146   }


  147   else if (request[0] == 64) {


  148     // Set (@P[x]=0) - Set Project x = status.


  149     processed = ProcessSetValue(request);


  150   }


  151 


  152   if (!processed) {


  153     Serial.print ("Error:Unknown Request.\n\r");


  154   }


  155 }


  156 


  157 boolean ProcessQuery(byte request[]) {


  158 


  159   boolean processed = false;


  160 


  161   switch (request[1]) {


  162   case 86: // ?V - version


  163     processed = SendVersion();


  164   default:


  165     Serial.print ("Error:Unknown Query.\n\r");


  166   }   


  167   return processed;


  168 }


  169 


  170 boolean ProcessSetValue(byte request[]) {


  171 


  172   boolean processed = false;


  173   byte command = request[1];


  174   // Allow ascii version of the fan number.


  175   //Position 2 should be [


  176   byte project = request[3] - 48; // 48 = 0


  177   //position 4 should be ]


  178   //position 5 should be =


  179   //position 6 should be the raw value.


  180   byte value = request[6];


  181 


  182   switch (command) {


  183   case 80: //@P[x]=y Set project x status y.  y is ascii version of the status (0-9).  so subtract 48.


  184     processed = SetProjectStatus((int)project, (int)value - 48);


  185     break;


  186   default:


  187     Serial.print ("Error:Unknown set command.");


  188   }


  189 


  190   return processed;


  191 }


  192 


  193 boolean SendVersion() {


  194   Serial.print ("Version=");


  195   Serial.print (VERSION);


  196   Serial.print ("\n\r");


  197   return true;


  198 }


  199 


  200 // Set the status for the project.


  201 boolean SetProjectStatus(int project, int status) {


  202 


  203   if (projectStatus[project-1] != status) {


  204     projectStatus[project-1] = status;


  205 


  206     // Build failed.  Flash the red LED briefly to get attention.


  207     if (status == 1) {


  208       digitalWrite(greenLEDPin[project-1], LOW);


  209 


  210       for (int i=0; i<6; i++) {


  211         digitalWrite(redLEDPin[project-1], HIGH);


  212         delay(100);


  213         digitalWrite(redLEDPin[project-1], LOW);


  214         delay(100);


  215       }


  216     }


  217   }


  218 


  219   return true;


  220 }


  221 




The method ReadCommands() will read the input buffer until it receives the start byte then call ReadSerialCommand() which reads the rest of the command into a buffer until it received the end byte. I’ve limited the buffer to 25 bytes which should be plenty and if this overflows then we just abandon it. Their is no timeout between receiving the start and end bytes so this could cause a problem if the end byte is not received.

Notice in the method SetProjectStatus() that the project index used is -1 from the project value sent. When sending commands the first project is project 1 however the Arduino uses 0 based arrays.

In SetProjectStatus() if the project state changes to be failure (value 1) then the red led is flashed 6 times to draw attention to the indicator.

Project State Indication:


  222 boolean UpdateLEDs() {


  223 


  224   for (int i=0; i<maxProjects; i++) {


  225     int greenLEDStatus = LOW;


  226     int redLEDStatus = LOW;


  227 


  228     switch (projectStatus[i]) {


  229     case 0: // NC


  230       // No acton


  231       break;


  232     case 1: // Fail


  233       redLEDStatus = HIGH;


  234       break;


  235     case 2: // Good


  236       greenLEDStatus = HIGH;


  237       break;


  238     case 5: // Building from a Fail build


  239     case 6: // Building from a good build


  240       greenLEDStatus = HIGH;


  241       redLEDStatus = HIGH;


  242       break;


  243     default:


  244       redLEDStatus = HIGH;


  245       break;


  246     }


  247 


  248     // Determine project LED pins and set them appropriatly.


  249     digitalWrite(redLEDPin[i], redLEDStatus);


  250     digitalWrite(greenLEDPin[i], greenLEDStatus);


  251   }


  252 }




In the method UpdateLEDs() we update the led status based on the project status.

If you are wondering what happened to status codes 3 & 4 I’ve used a bit based project status. 0001 (1) is fail, 0010 (2) is good, 01xx is building so 0101 (5) is building from a previously failed state and 0110 (6) is building from a good previous good state.

If you want to use indicators other than leds for your project state then you can update the UpdateLEDs() method with another way to indicate the project status (maybe a LCD panel?).

That’s basically the firmware, not much to it, the Arduino does most of the work for us which is the best bit!

To program the Arduino connect it up, install the drivers (my Vista x64 and Vista x86 installs got the drivers from Windows Update without a problem and also installed the VCP virtual com port drivers). Open up the IDE, ensure the board and serial port are correct and load the build indicator firmware, then hit the upload to I/O board button.

In the next entry I’ll talk about the PC application to drive the Arduino.