1
1
2
+ #!/usr/bin/env python2
3
+
4
+ # Copyright (c) 2016 ARM Limited, All Rights Reserved
5
+ # SPDX-License-Identifier: Apache-2.0
6
+
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+
10
+ # You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an
14
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
15
+ # either express or implied.
16
+
17
+
18
+ # pylint: disable=too-many-arguments, too-many-locals, too-many-branches, too-many-lines, line-too-long,
19
+ # pylint: disable=too-many-nested-blocks, too-many-public-methods, too-many-instance-attributes, too-many-statements
20
+ # pylint: disable=invalid-name, missing-docstring, bad-continuation
21
+
2
22
def mbed_cdc (port , reset = False , sterm = False , baudrate = 9600 , timeout = 10 , print_term_header = True ):
3
23
try :
4
24
from serial import Serial , SerialException
@@ -22,7 +42,8 @@ def cdc_reset(serial_instance):
22
42
try :
23
43
serial_instance .setBreak (False ) # For Linux the following setBreak() is needed to release the reset signal on the target mcu.
24
44
except :
25
- result = False
45
+ return False
46
+ return True
26
47
27
48
def cdc_term (serial_instance ):
28
49
term = miniterm .Miniterm (serial_instance , echo = True )
@@ -90,21 +111,21 @@ def input_handler():
90
111
term .join ()
91
112
term .close ()
92
113
114
+ return True
115
+
93
116
94
117
result = False
95
118
serial_port = get_instance (port , baudrate = baudrate , timeout = timeout )
96
119
if serial_port :
97
120
serial_port .reset_input_buffer ()
98
121
if reset :
99
- cdc_reset (serial_port )
100
- result = True
122
+ result = cdc_reset (serial_port )
101
123
102
124
if sterm :
103
125
if not serial_port .is_open :
104
126
serial_port = get_instance (port , baudrate = baudrate , timeout = timeout )
105
127
try :
106
- cdc_term (serial_port )
107
- result = True
128
+ result = cdc_term (serial_port )
108
129
except :
109
130
pass
110
131
0 commit comments