且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法从OBD 2读取数据

更新时间:2023-01-24 08:54:32

尽管BLE本身是标准化的,但BLE中没有针对OBD2服务的官方标准.为了使用多个适配器,您的应用程序应包含适当的设备扫描.

Although BLE itself is standardized, there is no official standard for OBD2 services in BLE. In order to work with multiple adapters, your application should incorporate a proper device scan.

要执行此操作,您可以探测设备,连接到找到的所有内容,然后启动服务扫描并遍历所有服务及其特征.

For this to work, you probe for devices, connect to everything that you find, then launch a service scan and iterate through all services and their characteristics.

如果找到可写的特征,那么它将是您可以写入的通道.如果您发现可读的特征,那么它将是从中读取信息的渠道.这不一定会导致两个特征,某些适配器在读取和写入时都使用相同的特征.

If you find a characteristic that is writable, then this will be the channel where you can write to. If you find a characteristic that is readable, then this will be channel where to read from. This will not necessarily lead to two characteristics, some adapters use the same for both reading and writing.

使用符合您期望的第一个服务,然后尝试发送ATZ\r\n(或在传输级别上支持的任何内容),并查看这是否是有效的OBD2适配器响应.

Use the first service that meet your expectations, then try to send an ATZ\r\n (or whatever you support on transport level) and see whether this is a valid OBD2 adapter response.

这样,您无需预先知道服务UUID,就可以使您的应用程序与大多数BLE适配器一起使用.

That way you don't need to know the service UUID up front and can make your application work with most BLE adapters.

(当然,您可以记住下一次的服务UUID,因此,除非用户告知您,否则您无需再次进行探测.)

(Of course, you can remember the service UUID for next time, so you don't have to probe again unless the user tells you to.)