brendan-w / python-OBD

OBD-II serial module for reading engine data
GNU General Public License v2.0
1.05k stars 369 forks source link

Request for FUEL_TYPE on Bi-Fuel car ends with NameError: name 'messages' is not defined #98

Closed jpvic closed 6 years ago

jpvic commented 6 years ago

Hi,

We did a test of following easy script on car that runs on petrol and CNG. It is original bi-fuel car produced by the car company ( CNG is not added afterwards).

`import obd obd.logger.setLevel(obd.logging.DEBUG)

ports = obd.scan_serial() print(ports)

connection = obd.OBD()

print("starting dual fuel")

FUEL_TYPE

c = obd.commands.FUEL_TYPE feedbackString = connection.query(c) print(feedbackString[0].data) `

error message

ssh://pi@192.168.29.189:22/usr/bin/python3 -u /home/pi/home/pi/obd/odb.py ['/dev/rfcomm0'] [obd.obd] ======================= python-OBD (v0.6.1) ======================= [obd.obd] Using scan_serial to select port [obd.obd] Available ports: ['/dev/rfcomm0'] [obd.obd] Attempting to use port: /dev/rfcomm0 [obd.elm327] Initializing ELM327: PORT=/dev/rfcomm0 BAUD=auto PROTOCOL=auto [obd.elm327] Response from baud 38400: b'' [obd.elm327] Response from baud 9600: b'?\r\r>?\r\r>' [obd.elm327] Choosing baud 9600 [obd.elm327] write: b'ATZ\r\n' [obd.elm327] wait: 1 seconds [obd.elm327] read: b'\r\rELM327 v1.5\r\r>' [obd.elm327] write: b'ATE0\r\n' [obd.elm327] read: b'ATE0\rOK\r\r>' [obd.elm327] write: b'ATH1\r\n' [obd.elm327] read: b'OK\r\r>' [obd.elm327] write: b'ATL0\r\n' [obd.elm327] read: b'OK\r\r>' [obd.elm327] write: b'ATSP0\r\n' [obd.elm327] read: b'OK\r\r>' [obd.elm327] write: b'0100\r\n' [obd.elm327] read: b'SEARCHING...\r7E9 06 41 00 98 18 00 01 \r7E8 06 41 00 BE 3E A8 13 \r\r>' [obd.elm327] write: b'ATDPN\r\n' [obd.elm327] read: b'A6\r\r>' [obd.protocols.protocol] map ECU 0 --> ENGINE [obd.protocols.protocol] map ECU 1 --> TRANSMISSION [obd.elm327] Connected Successfully: PORT=/dev/rfcomm0 BAUD=9600 PROTOCOL=6 [obd.obd] querying for supported commands [obd.obd] Sending command: b'0100': Supported PIDs [01-20] [obd.elm327] write: b'01002\r\n' [obd.elm327] read: b'7E9 06 41 00 98 18 00 01 \r7E8 06 41 00 BE 3E A8 13 \r\r>' [obd.obd] Sending command: b'0120': Supported PIDs [21-40] [obd.elm327] write: b'01202\r\n' [obd.elm327] read: b'7E9 06 41 20 00 00 00 01 \r7E8 06 41 20 80 07 B0 11 \r\r>' [obd.obd] Sending command: b'0140': Supported PIDs [41-60] [obd.elm327] write: b'01402\r\n' [obd.elm327] read: b'7E9 06 41 40 C0 80 00 00 \r7E8 06 41 40 FE D0 84 01 \r\r>' [obd.obd] Sending command: b'0600': Supported MIDs [01-20] [obd.elm327] write: b'0600\r\n' [obd.elm327] read: b'7E8 06 46 00 C0 00 00 01 \r\r>' [obd.obd] finished querying with 85 commands supported [obd.obd] =================================================================== starting dual fuel [obd.obd] Sending command: b'0151': Fuel Type [obd.elm327] write: b'01512\r\n' [obd.elm327] read: b'7E8 03 41 51 0D \r\r>' Traceback (most recent call last): File "/home/pi/home/pi/obd/odb.py", line 72, in feedbackString = connection.query(c) File "/usr/local/lib/python3.5/dist-packages/obd/obd.py", line 265, in query return cmd(messages) # compute a response object File "/usr/local/lib/python3.5/dist-packages/obd/OBDCommand.py", line 97, in call r.value = self.decode(messages) File "/usr/local/lib/python3.5/dist-packages/obd/decoders.py", line 343, in fuel_type d = messages[0].data NameError: name 'messages' is not defined

Process finished with exit code 1

brendan-w commented 6 years ago

Fixed in 4336e20e3155b367d7450b180ceae5fdedd439e8, and unit tests were added.