UWA项目中向BGX220P BLE设备发送AT命令遇Unreachable错误求助
UWA项目中使用Windows.Devices.Bluetooth向BGX220P发送AT命令返回Unreachable错误
环境与设备信息
- 开发环境:Visual Studio + C#,UWA应用
- BLE库:Windows.Devices.Bluetooth标准库
- 外围设备:内置BGX220P BLE模块,支持Data-up模式(可收集多台IoT设备数据并转发至中央设备)
通信机制
- 中央设备→外围设备:通过RX特征写入数据
- 外围设备→中央设备:通过TX特征推送数据(监听
ValueChanged事件接收)
问题现象
- 向RX特征写入任意AT命令(例如
ATI)时,返回Unreachable错误,无法触发Data-up模式 - 写入普通字节指令(如设置缓冲区大小)时,可正常完成写入操作
相关代码
发送AT命令的方法
private async Task SendATCommandAsync(string command) { command += "\r\n"; // 添加命令终止符 var data = System.Text.Encoding.UTF8.GetBytes(command); await rxCharacteristic.WriteValueAsync(data.AsBuffer()); }
BLE服务与特征初始化代码
try { var result = await bleDevice.GetGattServicesAsync(); if (result.Status == GattCommunicationStatus.Success) { var services = result.Services; var service = services.FirstOrDefault(s => s.Uuid == serviceUuid); if (service != null) { var characteristicsResult = await service.GetCharacteristicsAsync(); if (characteristicsResult.Status == GattCommunicationStatus.Success) { var characteristics = characteristicsResult.Characteristics; rxCharacteristic = characteristics.FirstOrDefault(c => c.Uuid == rxCharacteristicUuid); txCharacteristic = characteristics.FirstOrDefault(c => c.Uuid == txCharacteristicUuid); // 注册特征值变化事件 txCharacteristic.ValueChanged += TxCharacteristic_ValueChanged; // 启用Notify await txCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync( GattClientCharacteristicConfigurationDescriptorValue.Notify); rxCharacteristic.ProtectionLevel = GattProtectionLevel.EncryptionRequired; await SendATCommandAsync("ATI"); // 测试AT命令 } } } } catch (Exception ex) { // 异常处理逻辑 }
补充说明
当前使用官方BluetoothLE示例方案处理BLE设备的扫描与连接流程,可提供更多调试信息或细节。
内容的提问来源于stack exchange,提问作者cdaskal22
相关产品推荐
相关产品推荐

