python-OBD icon indicating copy to clipboard operation
python-OBD copied to clipboard

Multiple available ports fails auto connection

Open Rockybilly opened this issue 9 years ago • 1 comments

I discovered when there are more than a single available port, the connection fails. In this example I have COM2 opened and waiting for the obd to connect. COM3 is also active and has no relation to obd. As you will see, the program first tries to connect COM2, even though it succeeds, it continues to try ports as it tries to connect COM3, therefore the COM2 connection also fails. Giving COM2 manually solves this, so an issue with auto connection is confirmed. Here is the output log.

[obd.obd] ======================= python-OBD (v0.6.1) 
=======================
[obd.obd] Using scan_serial to select port
[obd.obd] Available ports: ['\\.\\COM2', '\\.\\COM3']
[obd.obd] Attempting to use port: \.\COM2
[obd.elm327] Initializing ELM327: PORT=\.\COM2 BAUD=auto PROTOCOL=auto
[obd.elm327] Response from baud 38400: '\r?\r>'
[obd.elm327] Choosing baud 38400
[obd.elm327] write: 'ATZ\r\n'
[obd.elm327] wait: 1 seconds
[obd.elm327] read: b'\r\nELM327 v1.3a OBDGPSLogger\r\n>'
[obd.elm327] write: 'ATE0\r\n'
[obd.elm327] read: b'ATE0\r\n\r\nOK\r\n>'
[obd.elm327] write: 'ATH1\r\n'
[obd.elm327] read: b'\r\nOK\r\n>'
[obd.elm327] write: 'ATL0\r\n'
[obd.elm327] read: b'\rOK\r>'
[obd.elm327] write: 'ATSP0\r\n'
[obd.elm327] read: b'\rOK\r>'
[obd.elm327] write: '0100\r\n'
[obd.elm327] wait: 2 seconds
[obd.elm327] read: b'\r41 00 88 19 80 00 21\r>'
[obd.elm327] write: 'ATDPN\r\n'
[obd.elm327] read: b'\r0\r>'
[obd.elm327] ELM responded with unknown protocol. Trying them one-by-one
[obd.elm327] write: 'ATTP6\r\n'
[obd.elm327] read: b'\rOK\r>'
[obd.elm327] write: '0100\r\n'
[obd.elm327] read: b'\r7E8 06 41 00 88 19 80 00 21\r>'
[obd.protocols.protocol] map ECU 0 --> ENGINE
[obd.elm327] Connected Successfully: PORT=\.\COM2 BAUD=38400 PROTOCOL=6
[obd.obd] Attempting to use port: \.\COM3
[obd.elm327] Initializing ELM327: PORT=\.\COM3 BAUD=auto PROTOCOL=auto
Program hangs here.

Rockybilly avatar Nov 10 '16 12:11 Rockybilly

I haven't used this with multiple COM ports, so I don't have first-hand experience with this.

Lines 82 & 83 of obd.py should catch when the port is connected, and break out of the for...loop when using auto connect. The only two ways I can think of to fix it are to move lines 82-83 above line 80, or wrap the whole for...loop in a while statement:

while self.interface.status() != OBDStatus.ELM_CONNECTED:  //EDIT: forgot 'self'
   for port in portnames:

Brendan may chime in with a better explanation or solution. He obviously knows his code better than me.

sommersoft avatar Nov 12 '16 05:11 sommersoft