我正在尝试使用Pair bluetooth devices to a computer with 32feet .NET Bluetooth library中我的案例的代码示例
在这篇文章中,xmashallax提到了本地mac地址。为了得到本地地址,我正在尝试这个-
public static BluetoothAddress GetBTMacAddress()
{
var nics = NetworkInterface.GetAllNetworkInterfaces();
foreach (NetworkInterface nic in nics)
{
// Only consider Bluetooth network interfaces
if (nic.NetworkInterfaceType != NetworkInterfaceType.FastEthernetFx &&
nic.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 && nic.Description.Contains("Bluetooth"))
{
return new BluetoothEndPoint(nic.GetPhysicalAddress().GetAddressBytes(), BluetoothService.SerialPort);
}
}
return null;
}我在"The requested address is not valid in its context“ErrorCode: AddressNotAvailable中出错了
你能建议怎样才能得到当前本地个人电脑的mac地址呢?
发布于 2016-12-29 10:37:58
为其他可能面临类似情况的人发布这一答案。
基本上,要创建蓝牙端点,需要适配器的有效蓝牙mac地址。要获得本地机器的本地蓝牙mac地址,只需使用
BluetoothRadio.PrimaryRadio.LocalAddress因此,需要将上述代码更改为
public static BluetoothAddress GetBTMacAddress()
{
BluetoothRadio myRadio = BluetoothRadio.PrimaryRadio;
if (myRadio == null)
{
// Console.WriteLine("No radio hardware or unsupported software stack");
return null;
}
return myRadio.LocalAddress;
}https://stackoverflow.com/questions/41205182
复制相似问题