【问题标题】:Auto determine the bluetooth device is OBD or not?自动判断蓝牙设备是不是OBD?
【发布时间】:2016-05-20 07:29:52
【问题描述】:

目前我正在开发 OBDII。在蓝牙发现连接obd时,我如何确定哪个设备是obd,哪个设备是普通蓝牙设备。因为我想自动将我的应用程序与obd连接。

obd设备有什么共同特征可以帮助我确定这是OBD设备吗?

我正在尝试按照 name 配对 obd 设备的代码。

//Register receiver for bluetooth discovery
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {

    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();

        if (BluetoothAdapter.ACTION_DISCOVERY_STARTED.equals(action)) {
            //discovery starts, we can show progress dialog or perform other tasks
        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            //discovery finishes, dismiss progress dialog
        } else if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            //bluetooth device found for pair
            try {
// Here I want to know device is obd or not?
                BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
                //Make pair of obd device as per name:
                if (device != null && !device.getName().equals("")) {
                    LogUtils.LOGE("NEW DEVICE", device.getName());
                    if (device.getName().equals(OBD_DEVICE_NAME_ONE) ||
                            device.getName().equals(OBD_DEVICE_NAME_TWO) ||
                            device.getName().equals(OBD_DEVICE_NAME_THREE)) {
                        pairDevice(device);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
};

//Send pairing request to OBD Device
private void pairDevice(BluetoothDevice device) {
    try {
        Method method = device.getClass().getMethod("createBond", (Class[]) null);
        method.invoke(device, (Object[]) null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

将OBD设备与名称配对后,它将自动连接并正常工作。

【问题讨论】:

    标签: android android-studio bluetooth obd-ii


    【解决方案1】:

    找出答案的唯一好方法是连接并发送:

    ATI

    这将返回一个ID,它始终包含 ELM327。

    【讨论】:

      猜你喜欢
      • 2012-04-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-20
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2014-05-05
      相关资源
      最近更新 更多