8000 tools/pyboard.py: Support opening serial port in exclusive mode. by dpgeorge · Pull Request #7141 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

tools/pyboard.py: Support opening serial port in exclusive mode. #7141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading< 8000 /span>
Diff view
Diff view
22 changes: 18 additions & 4 deletions tools/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# The MIT License (MIT)
#
# Copyright (c) 2014-2019 Damien P. George
# Copyright (c) 2014-2021 Damien P. George
# Copyright (c) 2017 Paul Sokolovsky
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down Expand Up @@ -252,7 +252,9 @@ def inWaiting(self):


class Pyboard:
def __init__(self, device, baudrate=115200, user="micro", password="python", wait=0):
def __init__(
self, device, baudrate=115200, user="micro", password="python", wait=0, exclusive=True
):
self.use_raw_paste = True
if device.startswith("exec:"):
self.serial = ProcessToSerial(device[len("exec:") :])
Expand All @@ -264,10 +266,15 @@ def __init__(self, device, baudrate=115200, user="micro", password="python", wai
else:
import serial

# Set options, and exclusive if pyserial supports it
serial_kwargs = {"baudrate": baudrate, "interCharTimeout": 1}
if serial.__version__ >= "3.3":
serial_kwargs["exclusive"] = exclusive

delayed = False
for attempt in range(wait + 1):
try:
self.serial = serial.Serial(device, baudrate=baudrate, interCharTimeout=1)
self.serial = serial.Serial(device, **serial_kwargs)
break
except (OSError, IOError): # Py2 and Py3 have different errors
if wait == 0:
Expand Down Expand Up @@ -650,6 +657,11 @@ def main():
action="store_true",
help="Do not follow the output after running the scripts.",
)
group.add_argument(
"--no-exclusive",
action="store_true",
help="Do not try to open the serial device for exclusive access.",
)
cmd_parser.add_argument(
"-f",
"--filesystem",
Expand All @@ -662,7 +674,9 @@ def main():

# open the connection to the pyboard
try:
pyb = Pyboard(args.device, args.baudrate, args.user, args.password, args.wait)
pyb = Pyboard(
args.device, args.baudrate, args.user, args.password, args.wait, not args.no_exclusive
)
except PyboardError as er:
print(er)
sys.exit(1)
Expand Down
0