From fbee2fd1fec7a56eff77f8b044e87b651d834564 Mon Sep 17 00:00:00 2001 From: Stefan Persson Date: Thu, 19 May 2011 15:21:27 +0000 Subject: [PATCH] Better cleanup in .NET sensor example. --- examples/dotnet/sensors/SensorPollWin/Program.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/dotnet/sensors/SensorPollWin/Program.cs b/examples/dotnet/sensors/SensorPollWin/Program.cs index e352b297..11a692b5 100644 --- a/examples/dotnet/sensors/SensorPollWin/Program.cs +++ b/examples/dotnet/sensors/SensorPollWin/Program.cs @@ -9,14 +9,17 @@ namespace SensorPollWin unsafe class Program { [DllImport("TelldusCore.dll")] - public static extern int tdTurnOn(int deviceId); + public static extern void tdInit(); + + [DllImport("TelldusCore.dll")] + public static extern void tdClose(); [DllImport("TelldusCore.dll")] public static extern int tdSensor(char* protocol, int protocolLength, char* model, int modelLength, int* id, int* dataTypes); [DllImport("TelldusCore.dll")] public static extern int tdSensorValue(char* protocol, char* model, int id, int dataType, char* value, int valueLength, int* timestamp); - + static unsafe void Main(string[] args) { int protocolstringsize = 20; @@ -27,7 +30,8 @@ namespace SensorPollWin IntPtr id = Marshal.AllocHGlobal(sizeof(int)); IntPtr dataType = Marshal.AllocHGlobal(sizeof(int)); Console.WriteLine("getting sensors"); - + + tdInit(); while (tdSensor(protocol, protocolstringsize, model, modelstringsize, (int*)id, (int*)dataType) == 0) { Console.WriteLine("Sensor: " + System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(protocol))) + " " + System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(model)))); @@ -52,6 +56,7 @@ namespace SensorPollWin Marshal.FreeHGlobal((IntPtr)model); Marshal.FreeHGlobal(id); Marshal.FreeHGlobal(dataType); + tdClose(); } private static string datify(int timestamp){