NETMF Blocks – Like Legos, but software

Microsoft’s TPL and TPL Dataflow are great new libraries for .Net. But, as normal, NETMF will not have these great new features because of limited space and lack of generics (at least for some time). Even so, the new Block structures such as BufferBlock, ActionBlock, and TransformBlock are such useful constructs that we should at least have the option to use them in NETMF. Wait, we are coders… Why not code these up ourselves? Turns out, we can. It will not be cheap, because we need a lot of base function to even get started, such as Task, a TaskScheduler, ConcurrentQueue, and others. I am guessing a “small” limited library will be 40K or more. On a device where we ~may have 60K free, that is a lot of real-estate. However, we will do it anyway, as these devices are getting more resources all the time as the hardware water level rises each year.

Another reason I feel it important to have this in our toolbox is Robotics and the problems we space we face on embedded systems. Let’s face it, even if you are just reading a temperature sensor and logging results, you’re doing robotics. If you are actually doing robotics, you are quickly faces with issues of threading and coordination (e.g. locks, threads, others). Reading and writing multiple sensors and motors gets us into threading pretty quickly. This is the reason things products Microsoft’s CCR and Robotics Studio was created to address. As one would expect, NETMF is pretty light on libraries and abstractions. So unless we want to invent boiler plate code for each project, we need to create our own abstractions anyway. So let’s leverage those patterns and bring some down to the NETMF.

I will try to write a blog post for each of the new blocks as I finish them and then bring it all together into a single library and see where it ends up. Embedded developers will probably pass out, but we will do it anyway because we can J

We will get started next time with BufferBlock. This makes sense because all other blocks will use BufferBlock. Here is a sneak peek:

public static void BufferBlockTest()
    BufferBlock bb = new BufferBlock();
    for (int i = 0; i < 10; i++)
    for (int i = 0; i < 10; i++)
        Debug.Print(“BB: “ + bb.Take().ToString());

Looking forward to next time.

BTW – If anyone knows a way to correctly format source code from Word let me know. I tried the WordPress “sourcecode” tags, but does not work. I don’t understand why this is such a hard problem. MS Writer can’t get it right either.


This entry was posted in .Net Micro Framework, C#. Bookmark the permalink.