简体   繁体   English

尝试订阅CBCharacteristic时,不允许写入错误

[英]Writing is not permitted error when attempting to subscribe to CBCharacteristic

I'm developing an App that communicates with a Bluetooth LE device and so I'm using CoreBluetooth to do this. 我正在开发一个与Bluetooth LE设备进行通信的应用程序,因此我正在使用CoreBluetooth来做到这一点。

The peripheral I'm using exposes 1 service which has two characteristics a serial port FIFO characteristic which supports indication/notification/write/write no response; 我正在使用的外围设备公开了一项服务,该服务具有两个特征,一个串行FIFO特征,该特征支持指示/通知/写/写无响应; and a serial port credit characteristic which supports write. 以及支持写操作的串行端口信用特性。

From my reading I gather that the characteristic that I need to subscribe to is the FIFO one but when I call [_connectedPeripheral setNotifyValue:YES forCharacteristic:characteristic]; 从我的阅读中,我了解到我需要订阅的特征是FIFO,但是当我调用[_connectedPeripheral setNotifyValue:YES forCharacteristic:characteristic]; I get a Writing is not permitted error. 我收到Writing is not permitted错误。

I checked the characteristic's properties and it has the Read , WriteWithoutResponse , Notify , and Indicate properties. 我检查了特征的属性,它具有ReadWriteWithoutResponseNotifyIndicate属性。

This is the first time I've used CoreBluetooth and I'm a bit of a bluetooth noob so it's probably something obvious I've overlooked but any help would be much appreciated. 这是我第一次使用CoreBluetooth,而且我有点像蓝牙菜鸟,所以我可能忽略了这很明显的事情,但是任何帮助将不胜感激。

EDIT: Here's the code: 编辑:这是代码:

#define SDL440S_SERVICE @"2456E1B9-26E2-8F83-E744-F34F01E9D701"
#define SDL440S_CHARACTERISTIC @"2456E1B9-26E2-8F83-E744-F34F01E9D703"

- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral
{
    NSLog(@"Did connect %@", peripheral.name);
    // _connectedPeripheral is a property...
    if (_connectedPeripheral != peripheral) {
        _connectedPeripheral = peripheral;
    }
    _connectedPeripheral.delegate = self;
    [_connectedPeripheral discoverServices:@[[CBUUID UUIDWithString:SDL440S_SERVICE]]];
}

#pragma mark - <CBPeripheralManager>

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error
{
    if (peripheral == _connectedPeripheral) {
        for (CBService *service in _connectedPeripheral.services) {
            if ([service.UUID.UUIDString isEqualToString:SDL440S_SERVICE]) {
                [_connectedPeripheral discoverCharacteristics:@[[CBUUID UUIDWithString:SDL440S_CHARACTERISTIC]] forService:service];
            }
        }
    }
}

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error
{
    for (CBCharacteristic *characteristic in service.characteristics) {
        if ([characteristic.UUID.UUIDString isEqualToString:SDL440S_CHARACTERISTIC]) {
            // Subsribe to characteristic
            [_connectedPeripheral setNotifyValue:YES forCharacteristic:characteristic];
        }
    }
}

// Getting values

- (void)peripheral:(CBPeripheral *)peripheral didUpdateNotificationStateForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error
{
    if (error) {
        NSLog(@"Error changing note state for char: %@.\nError: %@", characteristic, error.localizedDescription);
    }
}

For future reference if anyone comes across this problem, it was to do with the device's credit characteristic. 供将来参考,如果有人遇到此问题,则与设备的信用特征有关。

The service which I was interested in exposed two characteristics a credit characteristic and a FIFO characteristic. 我感兴趣的服务暴露了两个特性: 信用特性和FIFO特性。 (I understand that a credit characteristic is standard issue.) The problem was that I had to write the maximum amount of data that i wanted to receive to the credit characteristic before i could then receive and write data to the FIFO characteristic. (我知道信用特征是标准问题。)问题是,我必须先将要接收的最大数据量写入信用特征,然后才能接收数据并将其写入FIFO特征。

Ie: 即:

unsigned char buf[1] = {/*relevant data here...*/};
NSData *data = [NSData dataWithBytes:buf length:1];
[peripheral writeValue:data forCharacteristic:creditCharacteristic type:CBCharacteristicWriteWithoutResponse]; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 撰写CBC特色的问题 - Issue in writing CBCharacteristic 初始化CBCharacteristic时是否可以设置初始值? - Is it possible to set an initial value when initializing CBCharacteristic? 不允许iOS集中书写 - iOS central writing is not permitted 如果CBCharacteristic的isNotifying为YES,peripheral:didUpdateValueForCharacteristic:error:是否会传递错误? - Will peripheral:didUpdateValueForCharacteristic:error: ever pass an error if the CBCharacteristic's isNotifying is YES? 尝试取消UILocalNotification时出错 - Error when attempting to cancel a UILocalNotification iOS:写入描述符不允许写入 - iOS: Writing is not permitted for write descriptor Opentok-iOS:尝试订阅流时超时。 错误域= OTSubscriberErrorDomain代码= 1542 - Opentok-iOS : Timed out while attempting to subscribe to the stream. Error Domain=OTSubscriberErrorDomain Code=1542 尝试使用 FileManager 复制文件时出错:不允许操作 - Error when trying to copy a file with FileManager: Operation not permitted 尝试为CoreData属性分配NSOrderedSet时出错 - Error when attempting to assign CoreData property an NSOrderedSet 尝试使用 FileManager 移动项目时出错 - Error when attempting to move item using FileManager
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM