Commit a1fbee42 authored by Guillaume Seguin's avatar Guillaume Seguin

Disconnect Pronterface after 4 write failures

parent 126720a5
...@@ -70,6 +70,7 @@ class printcore(): ...@@ -70,6 +70,7 @@ class printcore():
self.sentlines = {} self.sentlines = {}
self.log = deque(maxlen = 10000) self.log = deque(maxlen = 10000)
self.sent = [] self.sent = []
self.writefailures = 0
self.tempcb = None #impl (wholeline) self.tempcb = None #impl (wholeline)
self.recvcb = None #impl (wholeline) self.recvcb = None #impl (wholeline)
self.sendcb = None #impl (wholeline) self.sendcb = None #impl (wholeline)
...@@ -134,6 +135,7 @@ class printcore(): ...@@ -134,6 +135,7 @@ class printcore():
is_serial = False is_serial = False
except: except:
pass pass
self.writefailures = 0
if not is_serial: if not is_serial:
self.printer_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.printer_tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.timeout = 0.25 self.timeout = 0.25
...@@ -502,12 +504,16 @@ class printcore(): ...@@ -502,12 +504,16 @@ class printcore():
try: try:
self.printer.write(str(command + "\n")) self.printer.write(str(command + "\n"))
self.printer.flush() self.printer.flush()
self.writefailures = 0
except socket.error as e: except socket.error as e:
print "Can't write to printer (disconnected?) (Socket error {0}): {1}".format(e.errno, e.strerror) print "Can't write to printer (disconnected?) (Socket error {0}): {1}".format(e.errno, e.strerror)
self.writefailures += 1
except SerialException as e: except SerialException as e:
print "Can't write to printer (disconnected?) (SerialException): {0}".format(e) print "Can't write to printer (disconnected?) (SerialException): {0}".format(e)
self.writefailures += 1
except RuntimeError as e: except RuntimeError as e:
print "Socket connection broken, disconnected. ({0}): {1}".format(e.errno, e.strerror) print "Socket connection broken, disconnected. ({0}): {1}".format(e.errno, e.strerror)
self.writefailures += 1
if __name__ == '__main__': if __name__ == '__main__':
baud = 115200 baud = 115200
......
...@@ -1229,6 +1229,12 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1229,6 +1229,12 @@ class PronterWindow(MainWindow, pronsole.pronsole):
string += _(" Z: %.3f mm") % self.curlayer string += _(" Z: %.3f mm") % self.curlayer
wx.CallAfter(self.statusbar.SetStatusText, string) wx.CallAfter(self.statusbar.SetStatusText, string)
wx.CallAfter(self.gviz.Refresh) wx.CallAfter(self.gviz.Refresh)
if self.p.online:
if self.p.writefailures >= 4:
print _("Disconnecting after 4 failed writes.")
self.status_thread = None
self.disconnect()
return
if self.monitor and self.p.online: if self.monitor and self.p.online:
if self.sdprinting: if self.sdprinting:
self.p.send_now("M27") self.p.send_now("M27")
...@@ -1614,7 +1620,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -1614,7 +1620,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.predisconnect_queueindex = self.p.queueindex self.predisconnect_queueindex = self.p.queueindex
self.predisconnect_layer = self.curlayer self.predisconnect_layer = self.curlayer
def disconnect(self, event): def disconnect(self, event = None):
print _("Disconnected.") print _("Disconnected.")
if self.p.printing or self.p.paused or self.paused: if self.p.printing or self.p.paused or self.paused:
self.store_predisconnect_state() self.store_predisconnect_state()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment