Jump to content
stevehayles

Updated .Net bindings

Recommended Posts

Hi,

 

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.

 

imu.WhenOrientation()
    .Sample(TimeSpan.FromMilliseconds(500))
    .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

 

Thanks,

 

Steve Hayles

Fifty One North Ltd

 

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Hi,

 

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 ?

Share this post


Link to post
Share on other sites

Yes, we would make a complete separate v2 version. We also would like to add .NET Core support if we do a major update of the C# bindings. For that we would have to exchange some of the internals with .NET Core compatible stuff too.

Share this post


Link to post
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.

 

 

 

 

Share this post


Link to post
Share on other sites

Updated to version 1.0.2 with following improvements

 

Improved callback/continuous callback documentation

 

Add RemoveCalibration function to Air Quality Bricklet API

Share this post


Link to post
Share on other sites

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

 

https://www.nuget.org/packages/FiftyOneNorth.Tinkerforge/1.0.6

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
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...