如何从UWP应用连接BLE设备? (Windows 10或Windows 10 Mobile)

时间:2019-05-29 12:41:36

标签: c# xamarin uwp

我已经创建了一个示例,用于从UWP应用连接BLE设备。

我做了以下步骤,

  • 创建的用于使用设备信息获取所有可用设备的命令。
  • 从设备列表中连接设备。连接代码如下,

        //Id= "BluetoothLE#BluetoothLE58:00:e3:45:9c:4c-3c:15:c2:c4:46:71:be"
        bluetoothDevice = await BluetoothLEDevice.FromIdAsync(Id);
        if (bluetoothDevice != null)
        {
            bluetoothDevice.ConnectionStatusChanged += (s, e) =>
            {
                if (s.ConnectionStatus == BluetoothConnectionStatus.Connected)
                {
                    state.Connected = true;
                    ConnectionStateChanged?.Invoke(this, state);
                }
                else if (s.ConnectionStatus == BluetoothConnectionStatus.Disconnected)
                {
                    state.Connected = false;
                    ConnectionStateChanged?.Invoke(this, state);
                }
            };
            //SetupMLDP();
        }
    

我已经调用了此方法,但是从未调用ConnectionStateChanged方法。 我想念什么?如果您知道的话,请告诉我。

0 个答案:

没有答案