Skip to content

Commit c4c4c01

Browse files
committed
Address comments in PR #650
1 parent 05d2216 commit c4c4c01

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

mbed/mbed_cdc.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11

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+
222
def mbed_cdc(port, reset=False, sterm=False, baudrate=9600, timeout= 10, print_term_header=True):
323
try:
424
from serial import Serial, SerialException
@@ -22,7 +42,8 @@ def cdc_reset(serial_instance):
2242
try:
2343
serial_instance.setBreak(False) # For Linux the following setBreak() is needed to release the reset signal on the target mcu.
2444
except:
25-
result = False
45+
return False
46+
return True
2647

2748
def cdc_term(serial_instance):
2849
term = miniterm.Miniterm(serial_instance, echo=True)
@@ -90,21 +111,21 @@ def input_handler():
90111
term.join()
91112
term.close()
92113

114+
return True
115+
93116

94117
result = False
95118
serial_port = get_instance(port, baudrate=baudrate, timeout=timeout)
96119
if serial_port:
97120
serial_port.reset_input_buffer()
98121
if reset:
99-
cdc_reset(serial_port)
100-
result = True
122+
result = cdc_reset(serial_port)
101123

102124
if sterm:
103125
if not serial_port.is_open:
104126
serial_port = get_instance(port, baudrate=baudrate, timeout=timeout)
105127
try:
106-
cdc_term(serial_port)
107-
result = True
128+
result = cdc_term(serial_port)
108129
except:
109130
pass
110131

0 commit comments

Comments
 (0)