首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BLE和ELM327 (CAN)

BLE和ELM327 (CAN)
EN

Stack Overflow用户
提问于 2021-05-12 13:59:37
回答 1查看 64关注 0票数 0

我需要通过移动应用程序控制汽车安全(车门打开/关闭)。我正在使用ELM 327适配器和BLE,我通过BLE连接到设备并读取服务的特征,但是我应该发送哪个命令以及向哪个服务打开/关闭警报?

代码语言:javascript
复制
import UIKit
    import CoreBluetooth

    class ViewController: UIViewController {

        private var centralManager: CBCentralManager!
        private var peripheral: CBPeripheral!
        
        override func viewDidLoad() {
            super.viewDidLoad()
            
            centralManager = CBCentralManager(delegate: self, queue: nil)
        }


    }

extension ViewController: CBPeripheralDelegate, CBCentralManagerDelegate {
        func centralManagerDidUpdateState(_ central: CBCentralManager) {
            print("Central state update")
            if central.state != .poweredOn {
                print("Central is not powered on")
            } else {
                centralManager.scanForPeripherals(withServices: nil, options: nil)
            }
        }
        
        func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {

            guard peripheral.name == "OBDBLE" else {return}
            print(peripheral.identifier)
            
            self.centralManager.stopScan()
            self.peripheral = peripheral
            self.peripheral.delegate = self
            self.centralManager.connect(self.peripheral, options: nil)
        }
        
        func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
            guard peripheral == self.peripheral else {return}
            print("Connected to your Particle Board")
            peripheral.discoverServices(nil)
        }
        
        func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
            guard let services = peripheral.services else {return}
            print("didDiscoverServices")
            for service in services {
                print(service)
                peripheral.discoverCharacteristics(nil, for: service)
            }
        }
        
        func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
            guard let characteristics = service.characteristics else {return}
            print("didDiscoverCharacteristicsFor: \(service.uuid)")
            for characteristic in characteristics {
                print(characteristic)
            }
        }
    }
EN

回答 1

Stack Overflow用户

发布于 2021-10-27 15:11:02

这个问题更适合在https://mechanics.stackexchange.com这样的论坛上,因为它不是关于编程的,而是关于OBD2的。

也就是说,无论如何你都不能通过OBD2做到这一点。OBD2专为废气排放诊断而设计,虽然您可以使用非标准PID访问更多传感器,但警报等关键设施希望不会通过通用OBD2插座暴露。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67498056

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档