|
@@ -38,7 +38,8 @@ class Device(object): |
|
|
try: |
|
|
try: |
|
|
self._device.read_line() |
|
|
self._device.read_line() |
|
|
except util.CommError, err: |
|
|
except util.CommError, err: |
|
|
self.stop() |
|
|
|
|
|
|
|
|
#self.stop() |
|
|
|
|
|
pass |
|
|
|
|
|
|
|
|
time.sleep(0.01) |
|
|
time.sleep(0.01) |
|
|
|
|
|
|
|
@@ -226,6 +227,9 @@ class SerialDevice(Device): |
|
|
|
|
|
|
|
|
self.on_close() |
|
|
self.on_close() |
|
|
|
|
|
|
|
|
|
|
|
def close_reader(self): |
|
|
|
|
|
self._read_thread.stop() |
|
|
|
|
|
|
|
|
def write(self, data): |
|
|
def write(self, data): |
|
|
try: |
|
|
try: |
|
|
self._device.write(data) |
|
|
self._device.write(data) |
|
@@ -234,6 +238,9 @@ class SerialDevice(Device): |
|
|
else: |
|
|
else: |
|
|
self.on_write(data) |
|
|
self.on_write(data) |
|
|
|
|
|
|
|
|
|
|
|
def read(self): |
|
|
|
|
|
return self._device.read(1) |
|
|
|
|
|
|
|
|
def read_line(self, timeout=0.0): |
|
|
def read_line(self, timeout=0.0): |
|
|
start_time = time.time() |
|
|
start_time = time.time() |
|
|
got_line = False |
|
|
got_line = False |
|
@@ -260,11 +267,7 @@ class SerialDevice(Device): |
|
|
|
|
|
|
|
|
if timeout > 0 and time.time() - start_time > timeout: |
|
|
if timeout > 0 and time.time() - start_time > timeout: |
|
|
break |
|
|
break |
|
|
|
|
|
|
|
|
time.sleep(0.01) |
|
|
|
|
|
except serial.SerialException, err: |
|
|
except serial.SerialException, err: |
|
|
self.close() |
|
|
|
|
|
|
|
|
|
|
|
raise util.CommError('Error reading from AD2SERIAL device: {0}'.format(str(err))) |
|
|
raise util.CommError('Error reading from AD2SERIAL device: {0}'.format(str(err))) |
|
|
else: |
|
|
else: |
|
|
if got_line: |
|
|
if got_line: |
|
|