首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在BluetoothAddress中查找本地蓝牙适配器的32 32Feet C#

在BluetoothAddress中查找本地蓝牙适配器的32 32Feet C#
EN

Stack Overflow用户
提问于 2016-12-18 03:26:02
回答 1查看 2.2K关注 0票数 0

我正在尝试使用Pair bluetooth devices to a computer with 32feet .NET Bluetooth library中我的案例的代码示例

在这篇文章中,xmashallax提到了本地mac地址。为了得到本地地址,我正在尝试这个-

代码语言:javascript
复制
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 contextErrorCode: AddressNotAvailable中出错了

你能建议怎样才能得到当前本地个人电脑的mac地址呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-12-29 10:37:58

为其他可能面临类似情况的人发布这一答案。

基本上,要创建蓝牙端点,需要适配器的有效蓝牙mac地址。要获得本地机器的本地蓝牙mac地址,只需使用

代码语言:javascript
复制
BluetoothRadio.PrimaryRadio.LocalAddress

因此,需要将上述代码更改为

代码语言:javascript
复制
  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;
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41205182

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档