Carista OBD | |设备与iOS设备的通信

Carista OBD | |设备与iOS设备的通信,ios,swift,core-bluetooth,obd-ii,Ios,Swift,Core Bluetooth,Obd Ii,我刚刚开始与Carista设备通信。我得到了所有的服务和特点。但当我写命令“ATZ”时,它会给出答案“ATZ” 我期望从设备得到的实际结果是“ATZELM327 v1.5” 这里我已经附上我的代码审查它 func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { guard let characteristics = servi

我刚刚开始与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设备获得了准确的异常响应


谢谢……)

实际上,附加
\r
就足够了。