从obd elm327 pythonOBD读取数据

2024-05-15 00:10:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用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)

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

^{pr2}$

预期产出:

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

这是一个工作与关闭连接后,得到每个回应,但它真的很慢。。。我想在最长1秒后得到回复。最佳值至少为0.5秒

有人对此有什么想法或经验吗? 提前谢谢。在


Tags: theto命令truetimeconnectioncommandcommands
1条回答
网友
1楼 · 发布于 2024-05-15 00:10:29

解决方案是将快速模式设置为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

相关问题 更多 >

    热门问题