【发布时间】:2018-08-08 09:55:11
【问题描述】:
我刚刚开始与 Carista 设备通信。我得到了所有的服务和特征。但是当我写命令“ATZ”时,它会给出“ATZ”的答案。
我期望从设备得到的实际结果是“ATZELM327 v1.5”
这里我附上了我的代码审查。
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
guard let characteristics = service.characteristics else { return }
for characteristic in characteristics {
print(characteristic)
caristaPeripheral.setNotifyValue(true, for: characteristic)
let ATZCommand = "ATZ"
let ATZBytes = ATZCommand.data(using: .utf8)
caristaPeripheral.writeValue(ATZBytes!, for: characteristic, type: .withResponse)
}
}
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
let string = String(data: characteristic.value!, encoding: .utf8)
print("CBCharacteristic : \(characteristic.uuid) ====> \(string ?? "none")")
}
请指导我。
【问题讨论】:
标签: ios swift core-bluetooth obd-ii