Made autodetection more robust and fixed it not running if a preset for a baudrate existed
Thanks @Salandora
This commit is contained in:
parent
6e1e869851
commit
fcdb556f3b
5 changed files with 30 additions and 21 deletions
|
|
@ -29,7 +29,7 @@ class VirtualPrinter():
|
|||
self.outgoing = Queue.Queue()
|
||||
self.buffered = Queue.Queue(maxsize=settings().getInt(["devel", "virtualPrinter", "commandBuffer"]))
|
||||
|
||||
for item in ['start\n', 'Marlin: Virtual Marlin!\n', '\x80\n', 'SD card ok\n']: # no sd card as default startup scenario
|
||||
for item in ['start\n', 'Marlin: Virtual Marlin!\n', '\x80\n', 'SD card ok\n']:
|
||||
self.outgoing.put(item)
|
||||
|
||||
self.currentExtruder = 0
|
||||
|
|
|
|||
|
|
@ -759,16 +759,16 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
|||
oldState = self._state
|
||||
|
||||
# forward relevant state changes to gcode manager
|
||||
if self._comm is not None and oldState == self._comm.STATE_PRINTING:
|
||||
if oldState == comm.MachineCom.STATE_PRINTING:
|
||||
if self._selectedFile is not None:
|
||||
if state == self._comm.STATE_OPERATIONAL:
|
||||
if state == comm.MachineCom.STATE_OPERATIONAL:
|
||||
self._fileManager.log_print(FileDestinations.SDCARD if self._selectedFile["sd"] else FileDestinations.LOCAL, self._selectedFile["filename"], time.time(), self._comm.getPrintTime(), True, self._printerProfileManager.get_current_or_default()["id"])
|
||||
elif state == self._comm.STATE_CLOSED or state == self._comm.STATE_ERROR or state == self._comm.STATE_CLOSED_WITH_ERROR:
|
||||
elif state == comm.MachineCom.STATE_CLOSED or state == comm.MachineCom.STATE_ERROR or state == comm.MachineCom.STATE_CLOSED_WITH_ERROR:
|
||||
self._fileManager.log_print(FileDestinations.SDCARD if self._selectedFile["sd"] else FileDestinations.LOCAL, self._selectedFile["filename"], time.time(), self._comm.getPrintTime(), False, self._printerProfileManager.get_current_or_default()["id"])
|
||||
self._analysisQueue.resume() # printing done, put those cpu cycles to good use
|
||||
elif self._comm is not None and state == self._comm.STATE_PRINTING:
|
||||
elif state == comm.MachineCom.STATE_PRINTING:
|
||||
self._analysisQueue.pause() # do not analyse files while printing
|
||||
elif state == self._comm.STATE_CLOSED or state == self._comm.STATE_CLOSED_WITH_ERROR:
|
||||
elif state == comm.MachineCom.STATE_CLOSED or state == comm.MachineCom.STATE_CLOSED_WITH_ERROR:
|
||||
if self._comm is not None:
|
||||
self._comm = None
|
||||
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@ def connectionCommand():
|
|||
printerProfile = None
|
||||
if "port" in data.keys():
|
||||
port = data["port"]
|
||||
if port not in connection_options["ports"]:
|
||||
if port not in connection_options["ports"] and port != "AUTO":
|
||||
return make_response("Invalid port: %s" % port, 400)
|
||||
if "baudrate" in data.keys():
|
||||
baudrate = data["baudrate"]
|
||||
if baudrate not in connection_options["baudrates"]:
|
||||
if baudrate not in connection_options["baudrates"] and baudrate != 0:
|
||||
return make_response("Invalid baudrate: %d" % baudrate, 400)
|
||||
if "printerProfile" in data.keys():
|
||||
printerProfile = data["printerProfile"]
|
||||
|
|
|
|||
|
|
@ -113,8 +113,8 @@ $(function() {
|
|||
if (self.isErrorOrClosed()) {
|
||||
var data = {
|
||||
"command": "connect",
|
||||
"port": self.selectedPort(),
|
||||
"baudrate": self.selectedBaudrate(),
|
||||
"port": self.selectedPort() || "AUTO",
|
||||
"baudrate": self.selectedBaudrate() || 0,
|
||||
"printerProfile": self.selectedPrinter(),
|
||||
"autoconnect": self.settings.serial_autoconnect()
|
||||
};
|
||||
|
|
|
|||
|
|
@ -781,8 +781,12 @@ class MachineCom(object):
|
|||
if not self._openSerial():
|
||||
return
|
||||
|
||||
try_hello = not settings().getBoolean(["feature", "waitForStartOnConnect"])
|
||||
|
||||
self._log("Connected to: %s, starting monitor" % self._serial)
|
||||
if self._baudrate == 0:
|
||||
self._serial.timeout = 0.01
|
||||
try_hello = False
|
||||
self._log("Starting baud rate detection")
|
||||
self._changeState(self.STATE_DETECT_BAUDRATE)
|
||||
else:
|
||||
|
|
@ -794,8 +798,11 @@ class MachineCom(object):
|
|||
startSeen = False
|
||||
supportRepetierTargetTemp = settings().getBoolean(["feature", "repetierTargetTemp"])
|
||||
|
||||
connection_timeout = settings().getFloat(["serial", "timeout", "connection"])
|
||||
detection_timeout = settings().getFloat(["serial", "timeout", "detection"])
|
||||
|
||||
# enqueue an M105 first thing
|
||||
if not settings().getBoolean(["feature", "waitForStartOnConnect"]):
|
||||
if try_hello:
|
||||
self._sendCommand("M110")
|
||||
self._clear_to_send.set()
|
||||
|
||||
|
|
@ -1009,22 +1016,19 @@ class MachineCom(object):
|
|||
### Baudrate detection
|
||||
if self._state == self.STATE_DETECT_BAUDRATE:
|
||||
if line == '' or time.time() > self._timeout:
|
||||
if len(self._baudrateDetectList) < 1:
|
||||
self.close()
|
||||
self._errorValue = "No more baudrates to test, and no suitable baudrate found."
|
||||
self._changeState(self.STATE_ERROR)
|
||||
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
|
||||
elif self._baudrateDetectRetry > 0:
|
||||
if self._baudrateDetectRetry > 0:
|
||||
self._serial.timeout = detection_timeout
|
||||
self._baudrateDetectRetry -= 1
|
||||
self._serial.write('\n')
|
||||
self._log("Baudrate test retry: %d" % (self._baudrateDetectRetry))
|
||||
self._sendCommand("M110")
|
||||
self._clear_to_send.set()
|
||||
else:
|
||||
elif len(self._baudrateDetectList) > 0:
|
||||
baudrate = self._baudrateDetectList.pop(0)
|
||||
try:
|
||||
self._serial.baudrate = baudrate
|
||||
self._serial.timeout = settings().getFloat(["serial", "timeout", "detection"])
|
||||
if self._serial.timeout != connection_timeout:
|
||||
self._serial.timeout = connection_timeout
|
||||
self._log("Trying baudrate: %d" % (baudrate))
|
||||
self._baudrateDetectRetry = 5
|
||||
self._timeout = get_new_timeout("communication")
|
||||
|
|
@ -1033,6 +1037,11 @@ class MachineCom(object):
|
|||
self._clear_to_send.set()
|
||||
except:
|
||||
self._log("Unexpected error while setting baudrate: %d %s" % (baudrate, get_exception_string()))
|
||||
else:
|
||||
self.close()
|
||||
self._errorValue = "No more baudrates to test, and no suitable baudrate found."
|
||||
self._changeState(self.STATE_ERROR)
|
||||
eventManager().fire(Events.ERROR, {"error": self.getErrorString()})
|
||||
elif 'start' in line or 'ok' in line:
|
||||
self._onConnected()
|
||||
self._clear_to_send.set()
|
||||
|
|
@ -1197,7 +1206,6 @@ class MachineCom(object):
|
|||
self._log("Connecting to: %s" % (p))
|
||||
programmer.connect(p)
|
||||
serial_obj = programmer.leaveISP()
|
||||
break
|
||||
except ispBase.IspError as (e):
|
||||
self._log("Error while connecting to %s: %s" % (p, str(e)))
|
||||
except:
|
||||
|
|
@ -1228,7 +1236,8 @@ class MachineCom(object):
|
|||
# connect to regular serial port
|
||||
self._log("Connecting to: %s" % port)
|
||||
if baudrate == 0:
|
||||
serial_obj = serial.Serial(str(port), 115200, timeout=read_timeout, writeTimeout=10000, parity=serial.PARITY_ODD)
|
||||
baudrates = baudrateList()
|
||||
serial_obj = serial.Serial(str(port), 115200 if 115200 in baudrates else baudrates[0], timeout=read_timeout, writeTimeout=10000, parity=serial.PARITY_ODD)
|
||||
else:
|
||||
serial_obj = serial.Serial(str(port), baudrate, timeout=read_timeout, writeTimeout=10000, parity=serial.PARITY_ODD)
|
||||
serial_obj.close()
|
||||
|
|
|
|||
Loading…
Reference in a new issue