nixpkgs/pkgs/applications/misc/octoprint/0002-Try-to-create-connection-several-times-if-printer-is.patch
2016-02-17 17:01:01 +03:00

58 lines
2.3 KiB
Diff

From b99fc3fd012765c5b3d8ac7a3f64762af5121b4a Mon Sep 17 00:00:00 2001
From: Nikolay Amiantov <ab@fmap.me>
Date: Wed, 17 Feb 2016 15:47:34 +0300
Subject: [PATCH 2/2] Try to create connection several times if printer is not
yet available
---
octoprint_m3dfio/__init__.py | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/octoprint_m3dfio/__init__.py b/octoprint_m3dfio/__init__.py
index 9f59768..e7d97eb 100644
--- a/octoprint_m3dfio/__init__.py
+++ b/octoprint_m3dfio/__init__.py
@@ -3421,8 +3421,16 @@ class M3DFioPlugin(
# Set updated port
currentPort = self.getPort()
- # Re-connect
- connection = serial.Serial(currentPort, currentBaudrate)
+ # Re-connect; wait for the device to be available
+ connection = None
+ for i in range(1, 5):
+ try:
+ connection = serial.Serial(currentPort, currentBaudrate)
+ break
+ except OSError:
+ time.sleep(1)
+ if connection is None:
+ raise Exception("Couldn't reconnect to the printer")
# Check if getting EEPROM was successful
if self.getEeprom(connection) :
@@ -6799,8 +6807,19 @@ class M3DFioPlugin(
# Set state to connecting
comm_instance._log("Connecting to: " + str(port))
+ # Create a connection
+ connection = None
+ for i in range(1, 5):
+ try:
+ connection = serial.Serial(str(port), baudrate)
+ # If printer has just power-cycled it may not yet be ready
+ except OSError:
+ time.sleep(1)
+ if connection is None:
+ raise Exception("Couldn't reconnect to the printer")
+
# Return connection
- return serial.Serial(str(port), baudrate)
+ return connection
# Disable sleep
def disableSleep(self) :
--
2.7.0