diff options
author | Guillaume Seguin <guillaume@segu.in> | 2013-06-06 00:00:25 +0400 |
---|---|---|
committer | Guillaume Seguin <guillaume@segu.in> | 2013-06-06 00:00:25 +0400 |
commit | a1fbee425f36cd9c4a26ca97d6b8b883f85d4c12 (patch) | |
tree | bc8d14f437dc2eaa01f30b329b6595789852359f /printcore.py | |
parent | 126720a5a72ec8e8e8ba231ad4887ee49d0ccb6f (diff) |
Disconnect Pronterface after 4 write failures
Diffstat (limited to 'printcore.py')
-rwxr-xr-x | printcore.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/printcore.py b/printcore.py index 12cd7a9..aa07354 100755 --- a/printcore.py +++ b/printcore.py @@ -70,6 +70,7 @@ class printcore(): self.sentlines = {} self.log = deque(maxlen = 10000) self.sent = [] + self.writefailures = 0 self.tempcb = None #impl (wholeline) self.recvcb = None #impl (wholeline) self.sendcb = None #impl (wholeline) @@ -134,6 +135,7 @@ class printcore(): is_serial = False except: pass + self.writefailures = 0 if not is_serial: self.printer_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.timeout = 0.25 @@ -502,12 +504,16 @@ class printcore(): try: self.printer.write(str(command + "\n")) self.printer.flush() + self.writefailures = 0 except socket.error as e: print "Can't write to printer (disconnected?) (Socket error {0}): {1}".format(e.errno, e.strerror) + self.writefailures += 1 except SerialException as e: print "Can't write to printer (disconnected?) (SerialException): {0}".format(e) + self.writefailures += 1 except RuntimeError as e: print "Socket connection broken, disconnected. ({0}): {1}".format(e.errno, e.strerror) + self.writefailures += 1 if __name__ == '__main__': baud = 115200 |