rendered paste body public static string GetBluetoothPortName(BluetoothAddress deviceaddress)
{
string portname = string.Empty;
long l_deviceaddress = deviceaddress.ToInt64();
using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(@"\Software\Microsoft\Bluetooth\Serial\Ports"))
{
foreach (string s_address in rk.GetSubKeyNames())
{
long address = long.Parse(s_address, System.Globalization.NumberStyles.AllowHexSpecifier);
if (address == l_deviceaddress)
{
using (RegistryKey thisrk = rk.OpenSubKey(s_address))
{
portname = (string)thisrk.GetValue("Port", string.Empty);
}
break;
}
}
}
return portname.TrimEnd(new char[] { '\0', '\n', '\r' });
}