使用:视窗10,C#.NET 2015年社区,UWP任务结束[C#UWP]
我试着去建立一个Windows的普及,应用程序,对我有BLE装置PC。
什么已经在工作是枚举附近的设备,与选定的一个配对,并获得像电池级和固件修订信息。
现在的问题是,当我试图让一个自定义的服务,我的任务结束,因为一个“System.Exception的”在.GetGattService
System.Exception.Message:从“找不到元素(例外。 HRESULT:0x80070490)”
System.Exception.Stack: “在Windows.Devices.Bluetooth.BluetoothLEDevice.GetGattService(GUID serviceUuid个)\ r \ n在SettingsCs.Settings.d__23.MoveNext()”
这是不工作的代码:
private async Task<SettingsReturn> writeSettingTransition(BluetoothLEDevice device, byte[] byteSettings)
{
//Check if device is available
if (device != null)
{
Guid SERVICE_CUSTOM = new Guid("7e0bc6be-8271-4f5a-a126-c24220e6250c");
GattDeviceService service = device.GetGattService(SERVICE_CUSTOM);
//Check if service is available
if (service == null)
{
return SettingsReturn.INIT_ERROR;
}
GattCharacteristic characteristic = service.GetCharacteristics(BLETestApp.CHAR_SETTINGS)[0];
//Check if characteristic is available
if (characteristic == null)
{
return SettingsReturn.INIT_ERROR;
}
var writer = new DataWriter();
writer.WriteBytes(byteSettings);
var buffer = writer.DetachBuffer();
await characteristic.WriteValueAsync(buffer);//********
bool success = characteristic.CharacteristicProperties.HasFlag(GattCharacteristicProperties.Write);
if (success == true)
{
// Take care of the 8 bit byte for the counter (max = 255 (unsigned))
if (TRANSACTION_ID > 250)
{
TRANSACTION_ID = 0;
}
else
{
// Count TANSACTION_ID one up
TRANSACTION_ID++;
}
return SettingsReturn.OK;
}
else
{
return SettingsReturn.WRITE_ERROR;
}
}
else
{
return SettingsReturn.INIT_ERROR;
}
}
我希望somenone能帮助我或告诉我我做错了什么。
你能编辑你的文章并添加异常详情(消息和堆栈跟踪)吗? –
@PedroLamas对不起,我忘了。现在添加细节。 –
您是否设置了必要的功能?您可能需要检查[this](https://docs.microsoft.com/en-us/uwp/schemas/appxpackage/how-to-specify-device-capabilities-for-bluetooth) –