我刚刚开始与 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")")
}
请指导我。
最佳答案
我已经找到了解决方案,如下。
此时我们在Carista设备中写入任何命令时都需要附加“\r\n”。因此,根据上面的问题,我们需要将 let ATZCommand = "ATZ"
替换为 let ATZCommand = "ATZ\r\n"
。
现在,我根据异常情况从 Carista 设备获得了准确的响应。
谢谢......:)
关于ios - 卡里斯塔 OBD ||与 iOS 设备的设备通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51743745/