Better cleanup in .NET sensor example.
This commit is contained in:
parent
f096faf367
commit
fbee2fd1fe
1 changed files with 8 additions and 3 deletions
|
@ -9,7 +9,10 @@ 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);
|
||||
|
@ -28,6 +31,7 @@ namespace SensorPollWin
|
|||
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){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue