Skip to content
This repository
branch: fpgas
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 35 lines (30 sloc) 0.784 kb
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
from glob import glob
from serial.tools import list_ports

from detect import LINUX, WINDOWS

def find_udev(check, product_id):
ports = []
if LINUX:
try:
import pyudev

context = pyudev.Context()
for device in context.list_devices(subsystem='tty', ID_MODEL=product_id):
if check(device.device_node):
ports.append(device.device_node)
except ImportError:
pass
return ports

def find_serial_by_id(check, product_id):
ports = []
if LINUX:
for port in glob('/dev/serial/by-id/*' + product_id + '*'):
if check(port):
ports.append(port)
return ports

def find_com_ports(check):
ports = []
if WINDOWS:
com_ports = [p[0] for p in list_ports.comports()].sort()
for port in com_ports:
if check(port, False):
ports.append(port)
return ports
Something went wrong with that request. Please try again.