2017-02-13 1 views
2

저는 현재 CoreBluetooth가 장착 된 BLE 장치를 사용하고 있습니다. CBCentralManagerDelegate을 통해 기기를 찾고 기기와 연결할 수 있습니다.특성 값을 읽는 방법?

서비스의 특성을 찾고 싶을 때 올바른 uuid를 얻을 수 있지만 특성 값은 nil입니다. 어떤 아이디어? Bluetooth SIG

enter image description here

에 따라

func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { 
    if error != nil { 
     print("ERROR DISCOVERING CHARACTERISTICS: \(error?.localizedDescription)") 
     return 
    } 
    if let characteristics = service.characteristics { 

     for characteristic in characteristics { 
      print("--------------------------------------------") 
      print("Characteristic UUID: \(characteristic.uuid)") 
      print("Characteristic isNotifying: \(characteristic.isNotifying)") 
      print("Characteristic properties: \(characteristic.properties)") 
      print("Characteristic descriptors: \(characteristic.descriptors)") 
      print("Characteristic value: \(characteristic.value)") 
     } 
    } 
} 

------------------------------------------------------------------- 
Characteristic UUID: FA01 
Characteristic isNotifying: false 
Characteristic properties: CBCharacteristicProperties(rawValue: 26) 
Characteristic descriptors: nil 
Characteristic value: nil 

속성에 대한 또 다른 질문은, nRFConnectread, write, notify을 보여줍니다 이유. 그러나 실제로 특성의 올바른 가치를 얻습니다. 특성

enter image description here

+2

읽기 요청을하고 'didUpdateValue'CBPeripheralDelegate 메소드에 콜백을받을 때까지이 값은 0이됩니다. – Paulw11

+0

발견했을 때'func readValue (특성 : CBCharacteristic)'를 호출하십시오. 또는 setNotify (char에 사용할 수있는 경우). – Larme

+0

그것은 작동합니다. 속성은 어때? – WeiJay

답변

0

판독 값. swift 4

관련 문제