-
Notifications
You must be signed in to change notification settings - Fork 3
/
__init__.py
30 lines (27 loc) · 926 Bytes
/
__init__.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
import logging
import sys
import os.path
try:
import serial
except ImportError:
me = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0,os.path.join(me,'pyserial26'))
logging.getLogger(__name__).info("Using local copy of pyserial")
import serial
def get_ports():
try:
from serial.tools import list_ports
ports = [p[0] for p in list_ports.comports()]
except ImportError:
#pyserial 2.6 or older
ports = [serial.device(i) for i in range(5)]
if os.name == "posix":
for device in ["/dev/ttyUSB%d" % i for i in range(5)]:
if os.path.exists(device):
ports.append(device)
for device in ["/dev/ttyACM%d" % i for i in range(5)]:
if os.path.exists(device):
ports.append(device)
return ports
def get_speeds():
return [9600, 19200, 38400, 57600, 115200]