From cbae792dbe493ad0836b55c32680500c1764c116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 17 Feb 2013 17:47:06 +0100 Subject: [PATCH] Added logging to file on top of to stdout, temperature parsing now can cope with negative temperature (shouldn't normally occur but seems to happen with buggy firmware), added option to wait for "start" response from printer firmware before switching to state "operational" (defaults to previous behaviour) --- octoprint/server.py | 10 +++++++++- octoprint/settings.py | 6 ++++-- octoprint/util/comm.py | 13 ++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/octoprint/server.py b/octoprint/server.py index 6c38e67..737435d 100644 --- a/octoprint/server.py +++ b/octoprint/server.py @@ -377,6 +377,14 @@ def initLogging(): "level": "DEBUG", "formatter": "simple", "stream": "ext://sys.stdout" + }, + "file": { + "class": "logging.handlers.TimedRotatingFileHandler", + "level": "DEBUG", + "formatter": "simple", + "when": "D", + "backupCount": "1", + "filename": os.path.join(settings().getBaseFolder("logs"), "octoprint.log") } }, "loggers": { @@ -386,7 +394,7 @@ def initLogging(): }, "root": { "level": "INFO", - "handlers": ["console"] + "handlers": ["console", "file"] } } logging.config.dictConfig(config) diff --git a/octoprint/settings.py b/octoprint/settings.py index d23994c..eae685d 100644 --- a/octoprint/settings.py +++ b/octoprint/settings.py @@ -36,10 +36,12 @@ old_default_settings = { "folder": { "uploads": None, "timelapse": None, - "timelapse_tmp": None + "timelapse_tmp": None, + "logs": None }, "feature": { - "gCodeVisualizer": True + "gCodeVisualizer": True, + "waitForStartOnConnect": False }, } diff --git a/octoprint/util/comm.py b/octoprint/util/comm.py index dd257c9..c8f8d8d 100644 --- a/octoprint/util/comm.py +++ b/octoprint/util/comm.py @@ -62,7 +62,7 @@ class VirtualPrinter(): self.lastTempAt = time.time() self.bedTemp = 1.0 self.bedTargetTemp = 1.0 - + def write(self, data): if self.readList is None: return @@ -314,6 +314,7 @@ class MachineCom(object): #Start monitoring the serial port. timeout = time.time() + 5 tempRequestTimeout = timeout + startSeen = not settings().getBoolean(["feature", "waitForStartOnConnect"]) while True: line = self._readline() if line == None: @@ -334,9 +335,9 @@ class MachineCom(object): self._errorValue = line[6:] self._changeState(self.STATE_ERROR) if ' T:' in line or line.startswith('T:'): - self._temp = float(re.search("[0-9\.]*", line.split('T:')[1]).group(0)) + self._temp = float(re.search("-?[0-9\.]*", line.split('T:')[1]).group(0)) if ' B:' in line: - self._bedTemp = float(re.search("[0-9\.]*", line.split(' B:')[1]).group(0)) + self._bedTemp = float(re.search("-?[0-9\.]*", line.split(' B:')[1]).group(0)) self._callback.mcTempUpdate(self._temp, self._bedTemp, self._targetTemp, self._bedTargetTemp) #If we are waiting for an M109 or M190 then measure the time we lost during heatup, so we can remove that time from our printing time estimate. if not 'ok' in line and self._heatupWaitStartTime != 0: @@ -384,9 +385,11 @@ class MachineCom(object): else: self._testingBaudrate = False elif self._state == self.STATE_CONNECTING: - if line == '': + if line == '' and startSeen: self._sendCommand("M105") - elif 'ok' in line: + elif 'start' in line: + startSeen = True + elif 'ok' in line and startSeen: self._changeState(self.STATE_OPERATIONAL) elif time.time() > timeout: self.close()