Seems like end of the year brought new interesting .NET Micro Framework capable hardware. GHI Electronics introduced their FEZ initiative, which truly opens .NET Micro Framework space to everybody and I think we will hear much more about it in the future. But today I want to blog about new hardware from Sytech Designs, U.K based company. You might know Sytech Designs as a distributor of Device Solutions hardware as well as embedded solutions vendor.

MicroDev 400x262 Meridian Heart

Meridian as we want it

Sytech Designs came up with the small factor development board based on Meridian CPU. I personally value the decision to use well known CPU with good community and manufacturer support. Especially because installation of the new SDK would be boring and Meridian was missing his Single Board Computer reincarnation a lot. Although, we have Meridian/P, which is the first Meridian for hobbyist, it lacks some peripherals out-of-the-box (Ethernet, D-Sub 9, SD/MMC). The new MicroDev is declared as a development kit but it can bee used as a single board computer, which is where I see the big potential.

It comes with the D-Sub 9 serial connector, Ethernet, SD/MMC card slot and GPIO extension header. Debugging is done via USB, as we are used to do with Meridian. Beside the standard GPIO extension header (two GPIOs designated for LED and button), there is a LCD extension connector.

For all those hobby or low-series applications where Tahoe-II was too clumsy and Meridian/P too raw, the MicroDev is the perfect choice.

MicroDev 400x262 Peripherals

Features

  • Freescale i.MXS ARM920T at 100MHz
  • 8MBytes SDRAM
  • 4MBytes Flash
  • USB application download and debug
  • 2 Serial Ports: 1 logic level + 1 RS232 level
  • SPI
  • I2C
  • PWM
  • Frequency Counter
  • Ethernet via RJ45 connector
  • SD Card
  • JTAG connector
  • TFT LCD Touchscreen expansion connector
  • Button and LED accessible from application code
  • 27 GPIO pins - all can be configured as interrupts
  • Power via External +5v or via USB
  • 3V3 Power Supply o/p available
  • All Meridian signals available via 0.1” headers
  • Dimensions: 100x65 mm
  • 6x Mounting holes
  • More at http://www.sytechdesigns.com/

When upgrading different beta versions of .NET MF 4.0 or doing final upgrade to RTM, one can experience problems in Vsual Studio during compilation. Typically this compilation error is shown:

Error 1 The "Microsoft.SPOT.Tasks.GetDeviceFrameworkPaths" task could not be loaded from 
the assembly Microsoft.SPOT.Tasks,Version=4.0..,Culture=neutral,PublicKeyToken=2670f5f21e7f4192. 
Could not load file or assembly 'Microsoft.SPOT.Tasks, Version=4.0, Culture=neutral, 
PublicKeyToken=2670f5f21e7f4192' or one of its dependencies. The system cannot find the file 
specified. Confirm that the  declaration is correct, and that the assembly and all 
its dependencies are available.	
C:\Program Files (x86)\MSBuild\Microsoft\.NET Micro Framework\v4.0\Device.targets	101	9

Investigation

Error message points to C:\Program Files (x86)\MSBuild\Microsoft.NET Micro Framework\v4.0\Device.targets where everything seems to be fine. But Device.targets imoprts Tasks.settings from the same directory, which is very important. This files basicaly defines the name of TaskAssembly, which consists of two registry keys. And this is the problematic place. The necessary registry keys are sometimes not created or updated by the installation process (don’t know why).

<PropertyGroup>
    <CurBuildNumber>$(Registry:HKEY_LOCAL_MACHINE\Software\Microsoft\.NETMicroFramework\v4.0@BuildNumber)</CurBuildNumber>
    <CurRevNumber>$(Registry:HKEY_LOCAL_MACHINE\Software\Microsoft\.NETMicroFramework\v4.0@RevisionNumber)</CurRevNumber>

    <TasksAssembly>Microsoft.SPOT.Tasks,Version=4.0.$(CurBuildNumber).$(CurRevNumber),Culture=neutral,PublicKeyToken=2670f5f21e7f4192</TasksAssembly>
</PropertyGroup>

Resolution

To fix the problem, it’s necessary to change the registry value to proper its values. Specifically InstallRoot, BuildNumber, RevisionNumber. Following code snipet is .reg file that works for the .NET Micro Framework 4.0 SDK final version. In case of different version of the .NET MF, check the version value of C:\Program Files (x86)\Microsoft .NET Micro Framework\v4.0\Tools\Microsoft.SPOT.Tasks.dll, to obtain proper BuildNumber and RevisionNumber.

32-bit system version

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETMicroFramework\v4.0]
@=""
"InstallRoot"="C:\\Program Files\\Microsoft .NET Micro Framework\\v4.0\\"
"BuildNumber"="1681"
"RevisionNumber"="0"

64-bit system version

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETMicroFramework\v4.0]
@=""
"InstallRoot"="C:\\Program Files (x86)\\Microsoft .NET Micro Framework\\v4.0\\"
"BuildNumber"="1681"
"RevisionNumber"="0"

Some Windows Mobile devices today are equip with USB mass storage drive functionality. It means, that device is not connected to computer via activesync but behaves as a USB flash disk. However, some customers don’t like this feature and wants to disable this functionality for their users. Disabling just ActiveSync won’t help in this case.

To solve this issue I’ve done a little research and put together the following ADM script for Windows Mobile mobile management templates into System Center Mobile Device Manager 2008. It’s very simple to use, just add this template to your Active Directory templates and start using USB Mass Storage policy under the Security Policies.

CLASS MACHINE
CATEGORY "Windows Mobile Settings"
      CATEGORY "Security Policies"
           POLICY "USB Mass Storage"           
           KEYNAME "SOFTWARE\Policies\Microsoft\Windows Mobile Settings\Registry\HKLM\Drivers\USB\FunctionDrivers"
           
              ACTIONLISTON 
                  KEYNAME "SOFTWARE\Policies\Microsoft\Windows Mobile Settings\Registry\HKLM\Drivers\USB\FunctionDrivers\Mass_Storage_Class" 
                      VALUENAME "Dll" 
                      VALUE "USBMSFN.dll"
                  KEYNAME "SOFTWARE\Policies\Microsoft\Windows Mobile Settings\Registry\HKLM\Drivers\USB\FunctionDrivers" 
                      VALUENAME "DefaultClientDriver" 
                      VALUE "RNDIS" 
              END ACTIONLISTON 
              ACTIONLISTOFF 
                  KEYNAME "SOFTWARE\Policies\Microsoft\Windows Mobile Settings\Registry\HKLM\Drivers\USB\FunctionDrivers\Mass_Storage_Class" 
                      VALUENAME "Dll" 
                      VALUE "none"
                  KEYNAME "SOFTWARE\Policies\Microsoft\Windows Mobile Settings\Registry\HKLM\Drivers\USB\FunctionDrivers" 
                      VALUENAME "DefaultClientDriver" 
                      VALUE "RNDIS" 
              END ACTIONLISTOFF            
            END POLICY
      END CATEGORY 
END CATEGORY

It’s a been quite while, when I published the the first article about C328R Jpeg camera. It turns out to be the most discussed article on my blog. With new features, that came with .NET Micro Framework 3.0, I’ve decided to make a little update to C328R class.

C328R camera module 340x290 C328R camera module

What’s new

One thing that changed in version 3.0 of Micro Framework was the serial port API. Since C328R camera module is operated via serial port, the update was necessary. Anyway, this brings one big advantage of one compatible class for .NET Micro Framework and full .NET Framework. In next days I will try to connect the camera to desktop computer and to talk to it from C#. Long story short, the constructor and initialization of the C328R class might look like this.

// Create camera  
C328R camera = new C328R(new SerialPort("COM2", 115200));  

// Synchronize with camera 
camera.Sync();   

// Set baud rate - optional  
camera.SetBaudRate(C328R.BaudRate.Baud115200); 
// Set light frequency - optional 
camera.LigtFrequency(C328R.FrequencyType.F50Hz); 

// Initiate camera and picture details
camera.Initial(C328R.ColorType.Jpeg, 
                C328R.PreviewResolution.R160x120, 
                C328R.JpegResolution.R640x480);

Saving picture to SD card

The only thing I’ve changed in the demo application is the persistence of the picture on the SD card. Since .NET Micro Framework 3.0 introduced native support for the file system, I thought it would be nice to integrate it. Tahoe-II comes with SD card slot which is mapped as directory called SD1. Make sure to change this directory to fit your hardware. Some sample images taken by the camera and stored to the SD card are attached. Notice that saving picture to SD card takes few seconds.

private void SaveFileOnDisk(byte[] pictureData)
{
    // This directory is valid for Tahoe-II SD card slot only!!
    Directory.SetCurrentDirectory(@"SD1");

    // Some unique picture name based on time
    string pictureName = string.Concat(
                            "IMG_",
                            DateTime.Now.Hour.ToString(),
                            DateTime.Now.Minute.ToString(),
                            DateTime.Now.Second.ToString(),
                            ".jpeg");

    // Save the data into file
    using (FileStream fs = new FileStream(pictureName, 
                                          FileMode.Create, 
                                          FileAccess.Write, 
                                          FileShare.ReadWrite))
    {
        fs.Write(pictureData, 0, pictureData.Length);
        fs.Close();
    }
}

Download

Old and new version are now bundled in one zip archive. Download demo here C328R_stuff.zip [32 Kb]. Demo source code was moved to my GitHub repository.

Sample pictures

C328R sample 1 640x480 Part of my office desk

C328R sample 2 640x480 Things on my office desk

C328R sample 3 640x480 Self portrait


There was a question last week in the discussion group about animated bitmaps. The main problem was with chaining single bitmaps from resources into one animation. In one of my old projects I was using simple image strip, where frames were stored in the single image. I think, this might be useful also in the .NET Micro Framework.

Heating spiral 560x100 Animation strip

The AnimatedIcon class is very simple and it’s constructor takes three arguments. First is the bitmap strip, second is the width of one frame and third argument is animation interval. Jan Kučera also came with solution for animated icons for .NET Micro Framework. His class enables starting and stopping of animation.

I believe that usage of AnimatedIcon is pretty straight-forward. The only issue I see is the speed of animation for large images.

mainWindow = new Window();
mainWindow.Height = SystemMetrics.ScreenHeight;
mainWindow.Width = SystemMetrics.ScreenWidth;

AnimatedIcon image = new AnimatedIcon(Resources.GetBitmap(Resources.BitmapResources.spirala),
                                      70,   // Width of one frame
                                      200); // Animation interval
mainWindow.Child = image;
public class AnimatedIcon : UIElement
{
    /// <summary>
    /// Creates new instance of AnimatedIcon
    /// </summary>
    /// <param name="bitmap">Source bitmap strip</param>
    /// <param name="width">Width of one frame</param>
    /// <param name="interval">Animation interval in miliseconds</param>
    public AnimatedIcon(Bitmap bitmap, int width, int interval)
    {
        _bitmap = bitmap;
        _width = width;            
        _totalCount = (bitmap.Width / _width);
        _timer = new DispatcherTimer(this.Dispatcher);
        _timer.Interval = new TimeSpan(0, 0, 0, 0, interval);
        _timer.IsEnabled = true;
        _timer.Start();
        _timer.Tick += new EventHandler(_timer_Tick);
    }

    void _timer_Tick(object sender, EventArgs e)
    {
        if (_index < _totalCount - 1)
            _index++;
        else
            _index = 0;

        this.Invalidate();
    }

    public override void OnRender(Microsoft.SPOT.Presentation.Media.DrawingContext dc)
    {
         dc.DrawImage(_bitmap,0, 0, _index * _width, 0, _width, _bitmap.Height);
         base.OnRender(dc);
    }

    private DispatcherTimer _timer;
    private Bitmap _bitmap;        
    private int _width, _index, _totalCount;
}