C# 获取异常读取异步错误:“quot;手柄无效。”;对于xamarin形式的BLE
我正在尝试用Xamarin表单实现一个可扩展的应用程序。但是读取操作给了我异常,即使我授予了在外围设备中读取的权限 {Plugin.BLE.Abstractions.Exceptions.CharacteristicReadException:读取 异步错误:错误域=CBATTErrorDomain代码=1“句柄为 无效。“UserInfo={NSLocalizedDescription=句柄无效。} 这是我的密码C# 获取异常读取异步错误:“quot;手柄无效。”;对于xamarin形式的BLE,c#,ios,xamarin.forms,bluetooth-lowenergy,C#,Ios,Xamarin.forms,Bluetooth Lowenergy,我正在尝试用Xamarin表单实现一个可扩展的应用程序。但是读取操作给了我异常,即使我授予了在外围设备中读取的权限 {Plugin.BLE.Abstractions.Exceptions.CharacteristicReadException:读取 异步错误:错误域=CBATTErrorDomain代码=1“句柄为 无效。“UserInfo={NSLocalizedDescription=句柄无效。} 这是我的密码 private async Task<string> Process
private async Task<string> ProcessDeviceInformationService(IService deviceInfoService)
{
try
{
await adapter.ConnectToDeviceAsync(device);
var sb = new StringBuilder("Getting information from Device Information service: \n");
var characteristics = deviceInfoService.GetCharacteristicsAsync();
var characteristic = await deviceInfoService.GetCharacteristicAsync(Guid.Parse("00002B0F-0000-1000-8000-00805F9B34FB"));
try
{
if (characteristic != null)
{
var sbnew = new StringBuilder("BLE Characteristics\n");
byte[] senddata = Encoding.UTF8.GetBytes(string.IsNullOrEmpty(SendMessageLabel.Text) ? "12" : SendMessageLabel.Text);
MainThread.BeginInvokeOnMainThread(async () =>
{
characteristic.ValueUpdated += (o, args) =>
{
var bytes = characteristic.Value;
};
await characteristic.WriteAsync(senddata);
string str = Encoding.UTF8.GetString(senddata);
sbnew.AppendLine($"Characteristics found on this device: {string.Join(", ", str.ToString())}");
CharactericsLabel.Text = sbnew.ToString();
}
}
catch (Exception ex)
{
//return ex.Message;
DisplayAlert("Notice", ex.Message.ToString(), "OK");
}
我使用的是characteristic sampleText。我使用的是Plugin.Ble2.0.1最新版本和iOS 14.0版本。我不知道如何解决这个问题。有任何建议。Hi,你能分享一下项目中使用的蓝牙nuget软件包吗?@JuniorJiang MSFT我使用的是Plugin.Ble2.0.1最新版本。好的,外围设备也是iOS设备?@JuniorJiang-MSFT不,这是android。哦,这很奇怪。如果这是一个问题,你可以在中作为一个问题提交,然后作者会知道并检查它。
// Current Time characteristic
BluetoothGattCharacteristic currentTime = new BluetoothGattCharacteristic(CURRENT_TIME,
//Read-only characteristic, supports notifications
BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY | BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE,
BluetoothGattCharacteristic.PERMISSION_READ | BluetoothGattCharacteristic.PROPERTY_WRITE);
BluetoothGattDescriptor configDescriptor = new BluetoothGattDescriptor(CLIENT_CONFIG,
//Read/write descriptor
BluetoothGattDescriptor.PERMISSION_READ | BluetoothGattDescriptor.PERMISSION_WRITE);
currentTime.addDescriptor(configDescriptor);
// Local Time Information characteristic
BluetoothGattCharacteristic localTime = new BluetoothGattCharacteristic(LOCAL_TIME_INFO,
//Read-only characteristic
BluetoothGattCharacteristic.PROPERTY_READ,
BluetoothGattCharacteristic.PERMISSION_READ);
BluetoothGattCharacteristic sampleText = new BluetoothGattCharacteristic(SAMPLE_TEXT,
//Read-only characteristic
BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE | BluetoothGattCharacteristic.PROPERTY_READ | BluetoothGattCharacteristic.PROPERTY_NOTIFY,
BluetoothGattCharacteristic.PERMISSION_WRITE | BluetoothGattCharacteristic.PERMISSION_READ);