Jump to content

Updated .Net bindings


Recommended Posts



Been working with the Tinkerforge system as a prototyping platform for a commercial product. Very well designed and easy system to work with but the .Net bindings are tied to some legacy framework versions and quite 'ugly' with the requirement for 'out' variables etc.


I have just released a new set of bindings with three big updates.


Firstly there is full support for ValueTuple returns on all functions with full property naming.  It allows calls like


var result = imu.GetAllData();
var accel = result.Acceleration;
var angles = result.EulerAngle;


rather than having to deal with multiple 'out' variables. 


There is also a fully async version of every call implemented using the Async/Await pattern.  The IPConnection class implements all socket send and receive calls asynchronously and there are async overrides of each available call.  The combined effect is that the above example can be written as


var resultAsync = await imu.GetAllDataAsync();
var accel = resultAsync.Acceleration;
var angles = resultAsync.EulerAngle;


This code is properly async and not just wrapping synchronous calls in Task.Run().


The last addition is the use of Reactive.Linq and a full set of extension methods to allow the use of IObservable on every brick or bricklet callback.  RX Extensions allow a composable and functional approach to streams of data.


Time shifting of sequences, buffering, throttling and all sorts of manipulations become very easy with a Linq based approach.  The underlying callback event is converted to an IObservable and the disposal of event handlers is all handled automatically.


The example below subscribes to a stream of data coming from the imu but it's 'throttled' to only produce data every 500 milliseconds regardless of the incoming rate from the brick.


    .Subscribe(async v =>
        Console.WriteLine($"Heading: {v.Heading}");
        await Log.WriteAsync($"Roll: {v.Roll}");


The nuget package is available at https://www.nuget.org/packages/FiftyOneNorth.Tinkerforge/ (FiftyOneNorth.Tinkerforge)


The complete set of bricks and bricklets are covered and I will try and maintain compatibility with future releases.  Keen to hear other's experiences and hope it's useful to someone




Steve Hayles

Fifty One North Ltd


Link to comment
Share on other sites

Sweet, looks good!


The design of the C# bindings is indeed quite old by now and it shows in the API. We try to always maintain backwards compatibility, so it often is hard to add new programming language features over time.


Maybe it would make sense to have some kind of C# bindings 2.0 and maintain the old C# bindings for legacy applications for a while.

Link to comment
Share on other sites



I don't want to 'pollute' your bindings in any way and at present my library is built as a combination of a modified "generate_csharp_bindings.py" python script and then a T4 template to generate all the extension methods.


This could all be done entirely within the current python framework but it's a much bigger change.  Maybe a completely separate "generate_csharp_bindings_V2.py" script with the original untouched would be the way to go ?

Link to comment
Share on other sites

Great move to go to .Net Core, it's the future !


My bindings work very well in a .Net Core environment and I am currently running them on a Raspberry PI to great effect.  I have a custom RPI image running with the .Net Core run-time built in and my next move was to look at the Red Brick and try and do the same there but if you are considering it then I am sure you will do a better job.





Link to comment
Share on other sites

  • 3 months later...

Updated to version 1.0.6 with following improvements


Added Laser Range Finder Bricklet 2.0

Added Hall Effect Bricklet 2.0

Added Segment Display 4x7 Bricklet 2.0

Added E-Paper 296x128 Bricklet

Added Laser Range Finder Bricklet 2.0

Added Piezo Speaker 2.0

Added Linear Poti Bricklet 2.0

Added Joystick Bricklet 2.0

Added RGB LED Bricklet 2.0



Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...