2014-10-17 52 views
0

我正在iOS中开发核心蓝牙应用程序。我有智能手表设备,并连接到我所开发的应用程序,旨在能够从中发现服务和特性,当我试图读取表信息的目的得到错误如下iOS:将命令发送到外设并从中接收响应

Bluetooth_iph[2688:614669] Did discover peripheral. peripheral: <CBPeripheral: 0x17daf4d0, 
    identifier = D675EA0B-1342-0C74-9D3D-98CAFA478985, name = BLEDEVICE, state = connecting> 
    rssi: -51, UUID: <CFUUID 0x17d96e80> D675EA0B-1342-0C74-9D3D-98CAFA478985  
    advertisementData: { 
kCBAdvDataIsConnectable = 1; 
kCBAdvDataLocalName = "BLEDEVICE"; 
kCBAdvDataServiceUUIDs =  (
    8880 
); 
kCBAdvDataTxPowerLevel = 7; 

    } 
2014-10-17 10:06:13.695 Bluetooth_iph[2688:614669] WARNING: No service found 
2014-10-17 10:06:18.353 Bluetooth_iph[2688:614669] Peripheral Connected 
2014-10-17 10:06:18.354 Bluetooth_iph[2688:614669] started time is 10:06:10 17-10-14 
2014-10-17 10:06:18.354 Bluetooth_iph[2688:614669] Scanning stopped 
2014-10-17 10:06:18.485 Bluetooth_iph[2688:614669] Found a Device Manufacturer Name 
2014-10-17 10:06:18.541 Bluetooth_iph[2688:614669] Error updating value for characteristic 
8881 error: Reading is not permitted. 

2014-10-17 10:06:18.601 Bluetooth_iph[2688:614669] Error updating value for characteristic 
8881 error: Reading is not permitted. 

2014-10-17 10:06:18.662 Bluetooth_iph[2688:614669] Error updating value for characteristic 
8881 error: Reading is not permitted. 

而对于发现我写下的服务的特征。

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService: 
    (CBService 
*)service error:(NSError *)error 

    { 
    if (error) 
    { 
    NSLog(@"Discovered characteristics for %@ with error: %@", service.UUID, [error 
    localizedDescription]); 
    return; 
    } 


    if([service.UUID isEqual:[CBUUID UUIDWithString:@"8880"]]) 
    { 
    for (CBCharacteristic * characteristic in service.characteristics) 
    { 
     /* Read manufacturer name */ 
     if([characteristic.UUID isEqual:[CBUUID UUIDWithString:@"8881"]]) 
     { 
      [_discoveredPeripheral readValueForCharacteristic:characteristic]; 
      NSLog(@"Found a Device Manufacturer Name Characteristic - Read manufacturer 
     name"); 
     } 
    } 
    } 

    if ([service.UUID isEqual:[CBUUID UUIDWithString:CBUUIDGenericAccessProfileString]]) 
    { 
    for (CBCharacteristic *characteristic in service.characteristics) 
    { 
     /* Read device name */ 
     if([characteristic.UUID isEqual:[CBUUID UUIDWithString:CBUUIDDeviceNameString]]) 
     { 
      [_discoveredPeripheral readValueForCharacteristic:characteristic]; 
      NSLog(@"Found a Device Name Characteristic - Read device name"); 
     } 
    } 
    } 
    } 

并为特征

- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic: 
    (CBCharacteristic *)characteristic error:(NSError *)error 
{ 
if (error) 
    { 
    NSLog(@"Error updating value for characteristic %@ error: %@", characteristic.UUID, 
    [error localizedDescription]); 
    return; 
    } 
} 

由于更新值的目标新的iOS开发我的要求是我不得不放弃一些要求的BLE装置,所以应该做出回应,回应我应该在得到iOS应用以上代码代表我的知识。如果可能,请通过代码或其他示例帮助我。

回答

0

您应该检查CBCharacteristicproperties属性 - 它会告诉您可以对特征做些什么。从您收到的消息不支持此特性 - 您只能写信给它,或者如果要将信息发送到中央服务器,那么您可能必须使用通知或指示(CBCharacteristicPropertyNotify和/或CBCharacteristicPropertyIndicate设置在properties)。

如果是这种情况,那么您需要使用[peripheral setNotifyValue:YES forCharacteristic:characteristic];当设备具有此特性的新数据时,它将调用peripheral:didUpdateNotificationStateForCharacteristic:error:委托方法。

+0

是的,您需要制造商提供的文档说明如何与设备沟通 – Paulw11 2014-10-17 09:14:33

+0

他们向我提供了一些信息,如START_BYTE_LEN = 1; COMMAND_ID_LEN = 1; SUB_TYPE_LEN = 1; CRC_LEN = 2; NO_SUBTYPE = 0x00; FIRST_BYTE = 0x01 GET_VERSION = 0x4a;并要求我通过使用这些命令发送命令,并且您将得到来自BLE设备的响应。我尝试了很多,我没有发现任何信息就足以获取数据。如果是的话如何得到,请帮助我 – iosdeveloper 2014-10-17 09:27:30

+0

好的,但你需要知道哪个特性写入,你需要的命令字节和子类型等 – Paulw11 2014-10-17 09:28:48

相关问题