Get protocol and get name now supports the new kind of string from telldus-core.
This commit is contained in:
parent
95a5b60337
commit
9fafbc0634
1 changed files with 39 additions and 4 deletions
|
@ -24,16 +24,19 @@ namespace DeviceHandler
|
||||||
private static extern int tdGetDeviceId(int value);
|
private static extern int tdGetDeviceId(int value);
|
||||||
|
|
||||||
[DllImport("TelldusCore.dll")]
|
[DllImport("TelldusCore.dll")]
|
||||||
private static extern string tdGetName(int value);
|
private static unsafe extern char* tdGetName(int value);
|
||||||
|
|
||||||
[DllImport("TelldusCore.dll")]
|
[DllImport("TelldusCore.dll")]
|
||||||
private static extern string tdGetProtocol(int value);
|
private static unsafe extern char* tdGetProtocol(int value);
|
||||||
|
|
||||||
[DllImport("TelldusCore.dll")]
|
[DllImport("TelldusCore.dll")]
|
||||||
private static extern int tdGetNumberOfDevices();
|
private static extern int tdGetNumberOfDevices();
|
||||||
|
|
||||||
[DllImport("TelldusCore.dll")]
|
[DllImport("TelldusCore.dll")]
|
||||||
private static extern int tdClose();
|
private static extern int tdClose();
|
||||||
|
|
||||||
|
[DllImport("TelldusCore.dll")]
|
||||||
|
private static unsafe extern void tdReleaseString(char* value);
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private List<Device> m_Devices = new List<Device>();
|
private List<Device> m_Devices = new List<Device>();
|
||||||
|
@ -104,6 +107,38 @@ namespace DeviceHandler
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get name for device, as a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="deviceId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get protocol for device, as a string
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="deviceId"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Loads all known devices into a collection.
|
/// Loads all known devices into a collection.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -119,8 +154,8 @@ namespace DeviceHandler
|
||||||
{
|
{
|
||||||
//Collect information from the driver.
|
//Collect information from the driver.
|
||||||
int deviceID = tdGetDeviceId(i);
|
int deviceID = tdGetDeviceId(i);
|
||||||
string deviceName = tdGetName(deviceID);
|
string deviceName = getName(deviceID);
|
||||||
string deviceProtocol = tdGetProtocol(deviceID);
|
string deviceProtocol = getProtocol(deviceID);
|
||||||
|
|
||||||
m_Devices.Add(new Device(deviceID, deviceName, deviceProtocol));
|
m_Devices.Add(new Device(deviceID, deviceName, deviceProtocol));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue