windows BLE编程 net winform 连接蓝牙4.0--新手补充

windows BLE编程 net winform 连接蓝牙4.0--新手补充


本文是对一些新手想通过pc访问ble蓝牙的一些补充帮助新手跳坑。
首先 我用的是win10 vs2019 .net4.6
重点文章先看–转自: https://www.cnblogs.com/webtojs/p/9675956.html#!comments
这里写的很详细,可以引用他的dll,也可以自己编写,(如果自己编写using Windows.Devices.Bluetooth;提示做错误的话请仔细看下面的评论),下面是我的问from调用方式:

public partial class Form1 : Form
    {
        BluetoothLECode bluetooth;
        string BluetoothLE = "";
        public Form1()
        {
            InitializeComponent();
            BluetoothLE= System.Configuration.ConfigurationManager.AppSettings["BluetoothLE"];
            string _serviceGuid = "0000ffe0-0000-1000-8000-00805f9b34fb";//蓝牙服务的uuid;
            string _writeCharacteristicGuid = "0000ffe1-0000-1000-8000-00805f9b34fb";//蓝牙写的uuid;
            string _notifyCharacteristicGuid = "0000ffe1-0000-1000-8000-00805f9b34fb";//蓝牙读的uuid;

            bluetooth = new BluetoothLECode(_serviceGuid, _writeCharacteristicGuid, _notifyCharacteristicGuid);
            bluetooth.ValueChanged += Bluetooth_ValueChanged;
        }
  
        private void Bluetooth_ValueChanged(MsgType type, string str, byte[] data)
        {
             Console.WriteLine(str);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bluetooth.StartBleDeviceWatcher();
        }

        private async void OnBLEAdded()
        {
            await bluetooth.SelectDeviceFromIdAsync("a8:e2:c1:63:46:de");//蓝牙设备MAC地址
        }
    }

其中那三个uuid不知道也没有关系可以通过安卓的一个小程序获取,具体可以看这个网址:https://www.jianshu.com/p/d991f0fdec63
用Android Studio创一个小软件(如果不会写文章的最后有一个git地址可以参考),文章中会提到怎么获取uuid,将uuid放入对应的代码中程序就可以运行读取数据了。

  • 7
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值