Automatic detection of port on upload (resolve #15)

This commit is contained in:
Ivan Kravets
2014-10-03 19:47:34 +03:00
parent 1c4b97c2f2
commit 024be2e094
2 changed files with 15 additions and 4 deletions

View File

@ -5,6 +5,7 @@ Release History
---------
* Fixed bug with order for includes in conversation from INO/PDE to CPP
* Automatic detection of port on upload (`issue #15 <https://github.com/ivankravets/platformio/issues/15>`_)
0.7.0 (2014-09-24)

View File

@ -11,7 +11,7 @@ from time import sleep
from SCons.Script import (AlwaysBuild, Builder, COMMAND_LINE_TARGETS, Default,
DefaultEnvironment, Exit)
from platformio.util import reset_serialport
from platformio.util import get_serialports, reset_serialport
env = DefaultEnvironment()
@ -164,9 +164,19 @@ AlwaysBuild(uploadeep)
is_uptarget = (set(["upload", "uploadlazy", "uploadeep"]) &
set(COMMAND_LINE_TARGETS))
if is_uptarget and not env.subst("$UPLOAD_PORT"):
Exit("Please specify environment 'upload_port' or use global "
"--upload-port option.")
if is_uptarget:
# try autodetect upload port
if "UPLOAD_PORT" not in env:
for item in get_serialports():
if "VID:PID" in item['hwid']:
print ("Auto-detected UPLOAD_PORT: %s" % item['port'])
env['UPLOAD_PORT'] = item['port']
break
if "UPLOAD_PORT" not in env:
Exit("Please specify environment 'upload_port' or use global "
"--upload-port option.")
#
# Setup default targets