【问题标题】:Carista OBD || device communications with iOS DeviceCarista OBD ||与 iOS 设备的设备通信
【发布时间】: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


    【解决方案1】:

    我找到了解决方案,如下所示。 此时我们在 Carista 设备中写入任何命令时,都需要附加“\r\n”。因此,根据上述问题,我们需要将let ATZCommand = "ATZ" 替换为let ATZCommand = "ATZ\r\n"

    现在我得到了 Carista 设备的准确响应。

    谢谢....:)

    【讨论】:

    • 其实加\r就够了。
    猜你喜欢
    • 2015-05-19
    • 1970-01-01
    • 2014-09-27
    • 1970-01-01
    • 2012-12-19
    • 2021-07-11
    • 2011-12-08
    • 1970-01-01
    相关资源
    最近更新 更多