ios - 卡里斯塔 OBD ||与 iOS 设备的设备通信

标签 ios swift core-bluetooth obd-ii

我刚刚开始与 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")")

}

请指导我。

最佳答案

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

现在,我根据异常情况从 Carista 设备获得了准确的响应。

谢谢......:)

关于ios - 卡里斯塔 OBD ||与 iOS 设备的设备通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51743745/

相关文章:

ios - 扫描蓝牙时serviceUUIDs是什么意思?

ios - 视口(viewport)背景图像小偏移

ios - 具有 UIButton 名称的 For 循环

swift - 为什么来自 UIImagePickerController 的图像有时会被错误地裁剪?

ios - String 到 NSDate 反之亦然,然后到 UILabel

ios - 我可以使用 CBPairingAgent unpairPeer : to remove the bluetooth device from paired

ios - 在 UITableViewCell 和 UITableView 之间添加 NSLayoutContraint

ios - 我如何扩展具有 appDidEnterBackground 依赖项的 NSOperationQueue?

ios - 如何使用 JSONDecoder 将 Int 解码为 String?

支持 HID 的蓝牙 USB 智能加密狗