paneldue: attempt reconnect if disconnected due to error
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
59e58226ff
commit
119b0bf60c
|
@ -35,9 +35,10 @@ class SerialConnection:
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.busy = False
|
self.busy = False
|
||||||
self.pending_lines = []
|
self.pending_lines = []
|
||||||
|
self.attempting_connect = True
|
||||||
self.ioloop.spawn_callback(self._connect)
|
self.ioloop.spawn_callback(self._connect)
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self, reconnect=False):
|
||||||
if self.connected:
|
if self.connected:
|
||||||
if self.fd is not None:
|
if self.fd is not None:
|
||||||
self.ioloop.remove_handler(self.fd)
|
self.ioloop.remove_handler(self.fd)
|
||||||
|
@ -45,7 +46,11 @@ class SerialConnection:
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.ser.close()
|
self.ser.close()
|
||||||
self.ser = None
|
self.ser = None
|
||||||
|
self.partial_input = b""
|
||||||
logging.info("PanelDue Disconnected")
|
logging.info("PanelDue Disconnected")
|
||||||
|
if reconnect and not self.attempting_connect:
|
||||||
|
self.attempting_connect = True
|
||||||
|
self.ioloop.call_later(1., self._connect)
|
||||||
|
|
||||||
async def _connect(self):
|
async def _connect(self):
|
||||||
start_time = connect_time = time.time()
|
start_time = connect_time = time.time()
|
||||||
|
@ -71,11 +76,12 @@ class SerialConnection:
|
||||||
self.fd, self._handle_incoming, IOLoop.READ | IOLoop.ERROR)
|
self.fd, self._handle_incoming, IOLoop.READ | IOLoop.ERROR)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
logging.info("PanelDue Connected")
|
logging.info("PanelDue Connected")
|
||||||
|
self.attempting_connect = False
|
||||||
|
|
||||||
def _handle_incoming(self, fd, events):
|
def _handle_incoming(self, fd, events):
|
||||||
if events & IOLoop.ERROR:
|
if events & IOLoop.ERROR:
|
||||||
logging.info("PanelDue Connection Error")
|
logging.info("PanelDue Connection Error")
|
||||||
self.disconnect()
|
self.disconnect(reconnect=True)
|
||||||
return
|
return
|
||||||
# Process incoming data using same method as gcode.py
|
# Process incoming data using same method as gcode.py
|
||||||
try:
|
try:
|
||||||
|
@ -85,7 +91,7 @@ class SerialConnection:
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
# possibly an error, disconnect
|
# possibly an error, disconnect
|
||||||
self.disconnect()
|
self.disconnect(reconnect=True)
|
||||||
logging.info("serial_display: No data received, disconnecting")
|
logging.info("serial_display: No data received, disconnecting")
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -132,7 +138,7 @@ class SerialConnection:
|
||||||
else:
|
else:
|
||||||
logging.exception(
|
logging.exception(
|
||||||
"Error writing data, closing serial connection")
|
"Error writing data, closing serial connection")
|
||||||
self.disconnect()
|
self.disconnect(reconnect=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue