gpt4 book ai didi

android - 无法向 BLE 外设 (ZL-RC04A) 设备发送数据

转载 作者:行者123 更新时间:2023-11-29 00:14:33 29 4
gpt4 key购买 nike

我正在尝试使用代码 fragment 写入数据。

- (void)peripheral:(CBPeripheral *)peripheral1 didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
// Again, we loop through the array, just in case.
for (CBCharacteristic *characteristic in service.characteristics) {

// And check if it's the right one
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_CHARACTERISTIC_UUID]]) {
NSString *payloadMessage = @"3N";
NSData *payload = [payloadMessage dataUsingEncoding:NSUTF8StringEncoding];
[_discoveredPeripheral discoverDescriptorsForCharacteristic:characteristic];
[_discoveredPeripheral writeValue:payload forCharacteristic:characteristic
type:CBCharacteristicWriteWithResponse];
[_discoveredPeripheral setNotifyValue:YES forCharacteristic:characteristic];

}
}

}

但是出现错误

 - (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(nullable NSError *)error
{

}

作为:错误域=CBATTErrorDomain代码=3“不允许写入。” UserInfo={NSLocalizedDescription=不允许写入。}

尽管 Android 也能正常工作。

最佳答案

如果您为特征使用了错误的写入类型,就会出现该错误(假定该特征毕竟是可写的)。向特征写入数据有两种类型:

  1. CBCharacteristicWriteWithResponse:在这种情况下,您将收到外围设备的确认数据包。您可以将其视为 TCP 数据包。

  2. CBCharacteristicWriteWithoutResponse:这是一种“即发即忘”的写入方式。您可以将其视为 UDP 数据包。

因此,请尝试使用 CBCharacteristicWriteWithoutResponse 而不是 CBCharacteristicWriteWithResponse。如果这不起作用,您可能必须检查您的特征是否可写。

关于android - 无法向 BLE 外设 (ZL-RC04A) 设备发送数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45592772/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com