从obd elm327读取数据python-OBD

Reading datas from obd elm327 python-OBD

我想用 ELM327 通过 OBD2 记录数据,我是 Python 的新手。

我可以发送命令并得到响应。但我无法发送更多查询并获得响应,仅针对第一个命令,其余响应为 "None".

我的代码:

import obd, time


connection = obd.OBD(baudrate=38400, fast=True) # auto-connects to USB or RF port


while True:
    for i in commands_list:
        cmd1 = obd.commands.RPM       # select an OBD command (sensor)
        response1 = connection.query(cmd1) # send the command, and parse the response
        print(response1.value) # returns unit-bearing values thanks to Pint
        # connection.close()

        cmd2 = obd.commands.COOLANT_TEMP # select an OBD command (sensor)
        response2 = connection.query(cmd2) # send the command, and parse the response
        print(response2.value)
        # connection.close()
        time.sleep(0.5)

输出为:(发动机停止,点火)

0.0 revolutions_per_minute
None
0.0 revolutions_per_minute
None
0.0 revolutions_per_minute
None

预期输出:

0.0 revolutions_per_minute
91 degC
0.0 revolutions_per_minute
91 degC
0.0 revolutions_per_minute
91 degC

它可以在收到每个回复后关闭连接,但它真的很慢......我希望在最大之后收到回复。 1秒。最佳时间至少为 0.5 秒。

有人对此有想法或经验吗? 提前致谢。

解决方案是将快速模式设置为 false:

connection = obd.OBD(baudrate=38400, fast=False)

函数说明:

fast: Allows commands to be optimized before being sent to the car. Python-OBD currently makes two such optimizations:

Sends carriage returns to repeat the previous command. Appends a response limit to the end of the command, telling the adapter to return after it receives N responses (rather than waiting and eventually timing out). This feature can be enabled and disabled for individual commands. Disabling fast mode will guarantee that python-OBD outputs the unaltered command for every request.

来源:LINK