2014-10-17 62 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

相關問題