forked from roflson/pyobd
-
Notifications
You must be signed in to change notification settings - Fork 48
/
obd_utils.py
48 lines (45 loc) · 1.56 KB
/
obd_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import serial
import platform
def scanSerial():
"""scan for available ports. return a list of serial names"""
available = []
for i in range(256):
try: #scan standart ttyS*
s = serial.Serial(i)
available.append(s.portstr)
s.close() # explicit close 'cause of delayed GC in java
except serial.SerialException:
pass
for i in range(256):
try: #scan USB ttyACM
s = serial.Serial("/dev/ttyACM"+str(i))
available.append(s.portstr)
s.close() # explicit close 'cause of delayed GC in java
except serial.SerialException:
pass
for i in range(256):
try:
s = serial.Serial("/dev/ttyUSB"+str(i))
available.append(s.portstr)
s.close() # explicit close 'cause of delayed GC in java
except serial.SerialException:
pass
for i in range(256):
try:
s = serial.Serial("/dev/ttyd"+str(i))
available.append(s.portstr)
s.close() # explicit close 'cause of delayed GC in java
except serial.SerialException:
pass
# ELM-USB shows up as /dev/tty.usbmodemXXXX, where XXXX is a changing hex string
# on connection; so we have to search through all 64K options
if len(platform.mac_ver()[0])!=0: #search only on MAC
for i in range (65535):
extension = hex(i).replace("0x","", 1)
try:
s = serial.Serial("/dev/tty.usbmodem"+extension)
available.append(s.portstr)
s.close()
except serial.SerialException:
pass
return available