diff --git a/scheduler/DeviceHandler/Handler.cs b/scheduler/DeviceHandler/Handler.cs index 7ac633b9..5efabf15 100644 --- a/scheduler/DeviceHandler/Handler.cs +++ b/scheduler/DeviceHandler/Handler.cs @@ -24,16 +24,19 @@ namespace DeviceHandler private static extern int tdGetDeviceId(int value); [DllImport("TelldusCore.dll")] - private static extern string tdGetName(int value); + private static unsafe extern char* tdGetName(int value); [DllImport("TelldusCore.dll")] - private static extern string tdGetProtocol(int value); + private static unsafe extern char* tdGetProtocol(int value); [DllImport("TelldusCore.dll")] private static extern int tdGetNumberOfDevices(); [DllImport("TelldusCore.dll")] private static extern int tdClose(); + + [DllImport("TelldusCore.dll")] + private static unsafe extern void tdReleaseString(char* value); #endregion private List m_Devices = new List(); @@ -104,6 +107,38 @@ namespace DeviceHandler return result; } + /// + /// Get name for device, as a string + /// + /// + /// + private static unsafe string getName(int deviceId) + { + char* name = tdGetName(deviceId); + + string returnstring = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(name))); + + tdReleaseString(name); + return returnstring; + + } + + /// + /// Get protocol for device, as a string + /// + /// + /// + private static unsafe string getProtocol(int deviceId) + { + char* name = tdGetProtocol(deviceId); + + string returnstring = System.Text.Encoding.UTF8.GetString(System.Text.Encoding.Unicode.GetBytes(new string(name))); + + tdReleaseString(name); + return returnstring; + + } + /// /// Loads all known devices into a collection. /// @@ -119,8 +154,8 @@ namespace DeviceHandler { //Collect information from the driver. int deviceID = tdGetDeviceId(i); - string deviceName = tdGetName(deviceID); - string deviceProtocol = tdGetProtocol(deviceID); + string deviceName = getName(deviceID); + string deviceProtocol = getProtocol(deviceID); m_Devices.Add(new Device(deviceID, deviceName, deviceProtocol)); }