4
4
#
5
5
# The MIT License (MIT)
6
6
#
7
- # Copyright (c) 2014-2019 Damien P. George
7
+ # Copyright (c) 2014-2021 Damien P. George
8
8
# Copyright (c) 2017 Paul Sokolovsky
9
9
#
10
10
# Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -252,7 +252,9 @@ def inWaiting(self):
252
252
253
253
254
254
class Pyboard :
255
- def __init__ (self , device , baudrate = 115200 , user = "micro" , password = "python" , wait = 0 ):
255
+ def __init__ (
256
+ self , device , baudrate = 115200 , user = "micro" , password = "python" , wait = 0 , exclusive = True
257
+ ):
256
258
self .use_raw_paste = True
257
259
if device .startswith ("exec:" ):
258
260
self .serial = ProcessToSerial (device [len ("exec:" ) :])
@@ -264,10 +266,15 @@ def __init__(self, device, baudrate=115200, user="micro", password="python", wai
264
266
else :
265
267
import serial
266
268
269
+ # Set options, and exclusive if pyserial supports it
270
+ serial_kwargs = {"baudrate" : baudrate , "interCharTimeout" : 1 }
271
+ if serial .__version__ >= "3.3" :
272
+ serial_kwargs ["exclusive" ] = exclusive
273
+
267
274
delayed = False
268
275
for attempt in range (wait + 1 ):
269
276
try :
270
- self .serial = serial .Serial (device , baudrate = baudrate , interCharTimeout = 1 )
277
+ self .serial = serial .Serial (device , ** serial_kwargs )
271
278
break
272
279
except (OSError , IOError ): # Py2 and Py3 have different errors
273
280
if wait == 0 :
@@ -650,6 +657,11 @@ def main():
650
657
action = "store_true" ,
651
658
help = "Do not follow the output after running the scripts." ,
652
659
)
660
+ group .add_argument (
661
+ "--no-exclusive" ,
662
+ action = "store_true" ,
663
+ help = "Do not try to open the serial device for exclusive access." ,
664
+ )
653
665
cmd_parser .add_argument (
654
666
"-f" ,
655
667
"--filesystem" ,
@@ -662,7 +674,9 @@ def main():
662
674
663
675
# open the connection to the pyboard
664
676
try :
665
- pyb = Pyboard (args .device , args .baudrate , args .user , args .password, args .wait )
677
+ pyb = Pyboard (
678
+ args .device , args .baudrate , args .user , args .password , args .wait , not args .no_exclusive
679
+ )
666
680
except PyboardError as er :
667
681
print (er )
668
682
sys .exit (1 )
0 commit comments