Hallo zusammen,
ich bin ein großer Fan des Tinkerforge Baukastensystems. Außerdem programmiere ich fast ausschließlich in C#. Leider finde ich die C# API nicht besonders komfortabel, was wie ich denke auf die vielen Methoden mit „out“-Parametren zurückzuführen ist. Microsoft bzw. das C# Team haben das erkannt und mit .net 4.7 und C# Version 7 (Windows 10 Creators Update) das Problem behoben.
Daher möchte ich nun hier meine C# Plugin für .net 4.7 vorstellen. Diese Erweiterung fügt für alle Methoden aus der Tinkerfoge API für .net eine Methoden-Überschreibung hinzu. Es handelt sich um keine neue API sondern um eine API-Erweiterung. Es wird weiterhin die Basis-DLL benötigt.
Beispiel für C#:
var ipcon = new IPConnection(); // Create IP connection
var io = new BrickletIO4("h2R", ipcon); // Create device object
ipcon.Connect("localhost", 4223); // Connect to brickd
//Old Style
io.GetMonoflop(0, out byte value, out long time, out long timeRemaining);
Console.WriteLine("Remaining time: " + timeRemaining);
//New Style
Console.WriteLine("Remaining time: " + io.GetMonoflop(0).TimeRemaining);
ipcon.Disconnect();
Console.WriteLine("Press enter to exit...");
Console.ReadKey();
Beispiel VB.net:
Dim ipcon = New IPConnection
Dim io = New BrickletIO4("h2R", ipcon) ' Create device object
ipcon.Connect("localhost", 4223) ' Connect to brickd
'Old Style
Dim value As Byte
Dim time As Long
Dim timeRemaining As Long
io.GetMonoflop(0, value:=value, time:=time, timeRemaining:=timeRemaining)
Console.WriteLine("Remaining time: " + timeRemaining.ToString())
'New Style
Console.WriteLine("Remaining time: " + io.GetMonoflop(0).TimeRemaining.ToString())
ipcon.Disconnect()
Console.WriteLine("Press enter to exit...")
Console.ReadKey()
Ich kenne mich leider mit Mono nicht aus, daher kann ich nicht sagen, ob das kompatibel ist.
Fragen und Kommentare sind willkommen!
TinkerforgeNetPlus47.zip TinkerforgeNetPlus47.dll