Re-connect without proper disconnect fails on Windows

This commit is contained in:
Raphael Michel 2016-11-18 12:50:52 +01:00
parent 781d1ca63a
commit b05e88f9d1
2 changed files with 11 additions and 6 deletions

1
ecr.py
View file

@ -392,7 +392,6 @@ class ECR(object):
# note: this only executes utils.detect_pt with the local ecrterm.
from ecrterm.utils import detect_pt
result = detect_pt(silent=False, ecr=self, timeout=2)
self.transport.connect()
return result
def parse_str(self, s):

View file

@ -49,13 +49,19 @@ def detect_pt(device='/dev/ttyUSB0', timeout=2, silent=True,
def __detect_pt(port, timeout, ecr):
e = ecr or ECR(port)
# reconnect to have lower timeout
e.transport.close()
e.transport.connect(timeout=timeout)
errors = e.transmit(packets.StatusEnquiry())
if not errors:
if isinstance(e.last.completion, packets.Completion):
return e.last.completion.fixed_values.get('sw-version', True) or True
return True
return False
try:
if not errors:
if isinstance(e.last.completion, packets.Completion):
return e.last.completion.fixed_values.get('sw-version', True) or True
return True
return False
finally:
# Reset timeout
e.transport.close()
e.transport.connect()
if silent:
try:
return __detect_pt(device, timeout, ecr)