如何在 Windows 桌面应用程序中通过低功耗蓝牙发送数组?
How to send array via Bluetooth Low Energy in Windows Desktop APP?
我在 Windows 桌面应用程序中通过 BLE 与我的 arduino 通信时遇到了巨大的麻烦。我确实知道我必须在我的应用程序中启用 WinRT API 才能访问 GATT 并使用 win 8.1 等(我遵循了本教程 https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications)。从这一点上我不明白如何与我的设备通信。
所以我为设备 (adafruit nrf8001) 设置了以下值:
串口服务UUID:6E400001-B5A3-F393-E0A9-E50E24DCCA9E
TX特征UUID:6E400002-B5A3-F393-E0A9-E50E24DCCA9E
RX特征UUID:6E400003-B5A3-F393-E0A9-E50E24DCCA9E
如何向设备发送一个简单的数组或更简单的一个简单的 ASCII 值?在 iOS 和 android 上,我找到了很多示例,但不是 windows 桌面应用程序...
如果有人能提供帮助,将非常高兴!
菲尔
编辑:我认为这应该可以完成工作......但应用程序在最后一点崩溃:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
using Windows.Devices.Enumeration;
using Windows.UI.Xaml;
namespace LucidMobileCCproto
{
public partial class LucidMIControlPanel : Form
{
GattDeviceService service2 = null;
private async void Discover_Click(object sender, EventArgs e)
{
var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")), null);
GattDeviceService Service = await GattDeviceService.FromIdAsync(Services[0].Id);
//Check Service Name
textBox1.Text = "Using service: " + Services[0].Name;
GattReliableWriteTransaction gattTransaction = new GattReliableWriteTransaction(); //Orientation on MSDN Article
GattCharacteristic gattCharacteristic = Service.GetCharacteristics(new Guid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"))[0];
//Check Characteristic
textBox2.Text = Convert.ToString(gattCharacteristic.CharacteristicProperties);
//initialize Buffer
var writer = new Windows.Storage.Streams.DataWriter();
writer.WriteByte(2);
gattTransaction.WriteValue(gattCharacteristic, writer.DetachBuffer());
//Programm Crashes here
GattCommunicationStatus status = await gattTransaction.CommitAsync();
}
}
崩溃:Exception:Thrown:"The attribute cannot be written. (Exception from HRESULT: 0x80650003)" (System.Exception)
抛出了 System.Exception:"The attribute cannot be written. (Exception from HRESULT: 0x80650003)"
哇,我花了几个小时才得到解决方案:
我只需要添加写入选项(我也删除了可靠写入)
private async void Discover_Click(object sender, EventArgs e)
{
var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")));
GattDeviceService Service = await GattDeviceService.FromIdAsync(Services[0].Id);
GattCharacteristic gattCharacteristic = Service.GetCharacteristics(new Guid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"))[0];
var writer = new DataWriter();
writer.WriteString("#FF00FF");
var res = await gattCharacteristic.WriteValueAsync(writer.DetachBuffer(), GattWriteOption.WriteWithoutResponse);
}
我在 Windows 桌面应用程序中通过 BLE 与我的 arduino 通信时遇到了巨大的麻烦。我确实知道我必须在我的应用程序中启用 WinRT API 才能访问 GATT 并使用 win 8.1 等(我遵循了本教程 https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications)。从这一点上我不明白如何与我的设备通信。
所以我为设备 (adafruit nrf8001) 设置了以下值:
串口服务UUID:6E400001-B5A3-F393-E0A9-E50E24DCCA9E TX特征UUID:6E400002-B5A3-F393-E0A9-E50E24DCCA9E RX特征UUID:6E400003-B5A3-F393-E0A9-E50E24DCCA9E
如何向设备发送一个简单的数组或更简单的一个简单的 ASCII 值?在 iOS 和 android 上,我找到了很多示例,但不是 windows 桌面应用程序...
如果有人能提供帮助,将非常高兴!
菲尔 编辑:我认为这应该可以完成工作......但应用程序在最后一点崩溃:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Windows.Devices.Bluetooth.GenericAttributeProfile;
using Windows.Devices.Enumeration;
using Windows.UI.Xaml;
namespace LucidMobileCCproto
{
public partial class LucidMIControlPanel : Form
{
GattDeviceService service2 = null;
private async void Discover_Click(object sender, EventArgs e)
{
var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")), null);
GattDeviceService Service = await GattDeviceService.FromIdAsync(Services[0].Id);
//Check Service Name
textBox1.Text = "Using service: " + Services[0].Name;
GattReliableWriteTransaction gattTransaction = new GattReliableWriteTransaction(); //Orientation on MSDN Article
GattCharacteristic gattCharacteristic = Service.GetCharacteristics(new Guid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"))[0];
//Check Characteristic
textBox2.Text = Convert.ToString(gattCharacteristic.CharacteristicProperties);
//initialize Buffer
var writer = new Windows.Storage.Streams.DataWriter();
writer.WriteByte(2);
gattTransaction.WriteValue(gattCharacteristic, writer.DetachBuffer());
//Programm Crashes here
GattCommunicationStatus status = await gattTransaction.CommitAsync();
}
}
崩溃:Exception:Thrown:"The attribute cannot be written. (Exception from HRESULT: 0x80650003)" (System.Exception) 抛出了 System.Exception:"The attribute cannot be written. (Exception from HRESULT: 0x80650003)"
哇,我花了几个小时才得到解决方案:
我只需要添加写入选项(我也删除了可靠写入)
private async void Discover_Click(object sender, EventArgs e)
{
var Services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(GattDeviceService.GetDeviceSelectorFromUuid(new Guid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E")));
GattDeviceService Service = await GattDeviceService.FromIdAsync(Services[0].Id);
GattCharacteristic gattCharacteristic = Service.GetCharacteristics(new Guid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E"))[0];
var writer = new DataWriter();
writer.WriteString("#FF00FF");
var res = await gattCharacteristic.WriteValueAsync(writer.DetachBuffer(), GattWriteOption.WriteWithoutResponse);
}