Skip to content

Commit

Permalink
Fix maxspeed parameter handling
Browse files Browse the repository at this point in the history
fixes: cc944b5: Possibility to choose baudrate

At least if you choose bluetooth as connection type, `raise_port_speed` in
`portChooser` gets unset instead of "No" or a valid baudrate and causes
trouble in the init function of the `ELM` class.

Fix this with a simple try except combo and adapt the following conditions
on maxspeed.
  • Loading branch information
jneuhauser committed Dec 23, 2020
1 parent bab56cd commit 0a08dbb
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions elm.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,6 @@ def __init__(self, portName, rate, adapter_type="STD", maxspeed="No"):
self.sim_mode = options.simulation_mode
self.portName = portName
self.adapter_type = adapter_type
if maxspeed == "No":
maxspeed = 0
else:
maxspeed = int(maxspeed)

if not options.simulation_mode:
self.port = Port(portName, speed, self.portTimeout)
Expand Down Expand Up @@ -603,15 +599,20 @@ def __init__(self, portName, rate, adapter_type="STD", maxspeed="No"):
rate = speed
break

if adapter_type == "OBDLINK" and maxspeed and not options.elm_failed and rate != 2000000:
try:
maxspeed = int(maxspeed)
except:
maxspeed = 0

if adapter_type == "OBDLINK" and maxspeed > 0 and not options.elm_failed and rate != 2000000:
print("OBDLink Connection OK, attempting full speed UART switch")
try:
self.raise_odb_speed(maxspeed)
except:
options.elm_failed = True
self.connectionStatus = False
print("Failed to switch to change OBDLink to " + str(maxspeed))
elif adapter_type == "STD_USB" and rate != 115200 and maxspeed:
elif adapter_type == "STD_USB" and rate != 115200 and maxspeed > 0:
print("ELM Connection OK, attempting high speed UART switch")
try:
self.raise_elm_speed(maxspeed)
Expand Down

0 comments on commit 0a08dbb

Please sign in to comment.