This repository has been archived by the owner on Jan 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright (C) 2015-2019 Peter Magnusson <[email protected]> | ||
|
||
from platform import system | ||
from os import environ | ||
from serial.tools import list_ports | ||
|
||
|
||
def default_port(sysname=system()): | ||
"""This returns the default port used for different systems if SERIALPORT env variable is not set""" | ||
system_default = { | ||
'Windows': 'COM1', | ||
'Darwin': '/dev/tty.SLAB_USBtoUART' | ||
}.get(sysname, '/dev/ttyUSB0') | ||
# if SERIALPORT is set then don't even waste time detecting ports | ||
if 'SERIALPORT' not in environ: | ||
try: | ||
ports = list_ports.comports(include_links=False) | ||
if len(ports) == 1: | ||
return ports[0].device | ||
else: | ||
# clever guessing, sort of | ||
# vid/pid | ||
# 4292/60000 adafruit huzzah | ||
for p in ports: | ||
if p.vid == 4292 and p.pid == 60000: | ||
return p.device | ||
# use last port as fallback | ||
return ports[-1].device | ||
except Exception: | ||
pass | ||
|
||
return environ.get('SERIALPORT', system_default) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters