kisshexuxia
2017-06-12 07:40
采纳率: 50%
浏览 7.1k

win10 下winform调用 ble低耗能蓝牙接口

winform调用 ble低耗能蓝牙接口 InTheHand.Net.Personal.dll不支持ble低耗能蓝牙

用WIN10自带的await BluetoothLEDevice.FromIdAsyn没有反应

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Windows.Devices.Bluetooth;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        private BluetoothLEDevice bluetoothLeDevice = null;
        public Form1()
        {
            InitializeComponent();
        }


        private async void ConnectButton_Click()
        {
            try
            {
                // BT_Code: BluetoothLEDevice.FromIdAsync must be called from a UI thread because it may prompt for consent.
                                bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync("BluetoothLE#BluetoothLEb8:86:87:f6:1e:a5-78:a5:04:91:db:fc");
            }
            catch (Exception ex) when ((uint)ex.HResult == 0x800710df)
            {
                // ERROR_DEVICE_NOT_AVAILABLE because the Bluetooth radio is not on.
            }
        }

        private  void button1_Click(object sender, EventArgs e)
        {
            ConnectButton_Click();
        }
    }
}

4条回答 默认 最新

相关推荐 更多相似问题