Re-connect without proper disconnect fails on Windows
This commit is contained in:
parent
781d1ca63a
commit
b05e88f9d1
2 changed files with 11 additions and 6 deletions
1
ecr.py
1
ecr.py
|
@ -392,7 +392,6 @@ class ECR(object):
|
||||||
# note: this only executes utils.detect_pt with the local ecrterm.
|
# note: this only executes utils.detect_pt with the local ecrterm.
|
||||||
from ecrterm.utils import detect_pt
|
from ecrterm.utils import detect_pt
|
||||||
result = detect_pt(silent=False, ecr=self, timeout=2)
|
result = detect_pt(silent=False, ecr=self, timeout=2)
|
||||||
self.transport.connect()
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def parse_str(self, s):
|
def parse_str(self, s):
|
||||||
|
|
16
utils.py
16
utils.py
|
@ -49,13 +49,19 @@ def detect_pt(device='/dev/ttyUSB0', timeout=2, silent=True,
|
||||||
def __detect_pt(port, timeout, ecr):
|
def __detect_pt(port, timeout, ecr):
|
||||||
e = ecr or ECR(port)
|
e = ecr or ECR(port)
|
||||||
# reconnect to have lower timeout
|
# reconnect to have lower timeout
|
||||||
|
e.transport.close()
|
||||||
e.transport.connect(timeout=timeout)
|
e.transport.connect(timeout=timeout)
|
||||||
errors = e.transmit(packets.StatusEnquiry())
|
errors = e.transmit(packets.StatusEnquiry())
|
||||||
if not errors:
|
try:
|
||||||
if isinstance(e.last.completion, packets.Completion):
|
if not errors:
|
||||||
return e.last.completion.fixed_values.get('sw-version', True) or True
|
if isinstance(e.last.completion, packets.Completion):
|
||||||
return True
|
return e.last.completion.fixed_values.get('sw-version', True) or True
|
||||||
return False
|
return True
|
||||||
|
return False
|
||||||
|
finally:
|
||||||
|
# Reset timeout
|
||||||
|
e.transport.close()
|
||||||
|
e.transport.connect()
|
||||||
if silent:
|
if silent:
|
||||||
try:
|
try:
|
||||||
return __detect_pt(device, timeout, ecr)
|
return __detect_pt(device, timeout, ecr)
|
||||||
|
|
Loading…
Reference in a new issue