From fbe2b5617036f00568940476b06e38f638ef6ae8 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 21 Sep 2015 16:09:03 +0200 Subject: [PATCH 01/35] laser position halt debuging --- src/octoprint/plugins/svgtogcode/__init__.py | 10 ++-- src/octoprint/util/comm_acc.py | 49 ++++++++++++-------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/octoprint/plugins/svgtogcode/__init__.py b/src/octoprint/plugins/svgtogcode/__init__.py index b859f04c..954aa226 100644 --- a/src/octoprint/plugins/svgtogcode/__init__.py +++ b/src/octoprint/plugins/svgtogcode/__init__.py @@ -239,7 +239,7 @@ class SvgToGcodePlugin(octoprint.plugin.SlicerPlugin, less=["less/svgtogcode.less"], css=["css/svgtogcode.css", "css/mrbeam.css"] ) - + ##~~ SettingsPlugin API def on_settings_save(self, data): @@ -267,7 +267,7 @@ class SvgToGcodePlugin(octoprint.plugin.SlicerPlugin, intensity = min(max(data["defaultIntensity"], 1), 1000) s.set(["defaultIntensity"], intensity) if "defaultFeedrate" in data and data["defaultFeedrate"]: - feedrate = max(1,data["defaultFeedrate"]) + feedrate = max(1,data["defaultFeedrate"]) s.set(["defaultFeedrate"], feedrate) if "svgDPI" in data and data["svgDPI"]: s.set(["svgDPI"], data["svgDPI"]) @@ -353,8 +353,10 @@ class SvgToGcodePlugin(octoprint.plugin.SlicerPlugin, converter_path = homedir+"/mrbeam-inkscape-ext" hostname = socket.gethostname() - if("Bucanero" in hostname): + if("Bucanero" in hostname): converter_path = '/home/teja/workspace/mrbeam-inkscape-ext' + elif("denkbrett" in hostname): + converter_path = '/home/flo/mrbeam/git/mrbeam-inkscape-ext' import sys sys.path.append(converter_path) @@ -399,7 +401,7 @@ class SvgToGcodePlugin(octoprint.plugin.SlicerPlugin, self._svgtogcode_logger.info("-" * 40) -# ## shell call +# ## shell call # engine_settings = self._convert_to_engine(profile_path) # # from os.path import expanduser diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 2646e13d..758bd837 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -257,6 +257,15 @@ class MachineCom(object): if self._state == newState: return + if newState == self.STATE_PRINTING: + self._temperature_timer.cancel() + self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) + self._temperature_timer.start() + else: + self._temperature_timer.cancel() + self._temperature_timer = RepeatedTimer(0.2, self._poll_temperature, run_first=True) + self._temperature_timer.start() + if newState == self.STATE_CLOSED or newState == self.STATE_CLOSED_WITH_ERROR: if settings().get(["feature", "sdSupport"]): self._sdFileList = False @@ -1367,7 +1376,7 @@ class MachineCom(object): def _onConnected(self, nextState): self._serial.timeout = settings().getFloat(["serial", "timeout", "communication"]) #self._temperature_timer = RepeatedTimer(lambda: get_interval("temperature"), self._poll_temperature, run_first=True) - self._temperature_timer = RepeatedTimer(0.2, self._poll_temperature, run_first=True) + self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) self._temperature_timer.start() if(nextState == None): @@ -1978,35 +1987,35 @@ class MachineCom(object): # line example: # try: - idx_mx_begin = line.index('MPos:') + 5 - idx_mx_end = line.index('.', idx_mx_begin) + 2 - idx_my_begin = line.index(',', idx_mx_end) + 1 - idx_my_end = line.index('.', idx_my_begin) + 2 - idx_mz_begin = line.index(',', idx_my_end) + 1 - idx_mz_end = line.index('.', idx_mz_begin) + 2 + #idx_mx_begin = line.index('MPos:') + 5 + #idx_mx_end = line.index('.', idx_mx_begin) + 2 + #idx_my_begin = line.index(',', idx_mx_end) + 1 + #idx_my_end = line.index('.', idx_my_begin) + 2 + #idx_mz_begin = line.index(',', idx_my_end) + 1 + #idx_mz_end = line.index('.', idx_mz_begin) + 2 idx_wx_begin = line.index('WPos:') + 5 idx_wx_end = line.index('.', idx_wx_begin) + 2 idx_wy_begin = line.index(',', idx_wx_end) + 1 idx_wy_end = line.index('.', idx_wy_begin) + 2 - idx_wz_begin = line.index(',', idx_wy_end) + 1 - idx_wz_end = line.index('.', idx_wz_begin) + 2 + #idx_wz_begin = line.index(',', idx_wy_end) + 1 + #idx_wz_end = line.index('.', idx_wz_begin) + 2 - idx_intensity_begin = line.index('S:', idx_wz_end) + 2 - idx_intensity_end = line.index(',', idx_intensity_begin) + #idx_intensity_begin = line.index('S:', idx_wz_end) + 2 + #idx_intensity_end = line.index(',', idx_intensity_begin) - idx_laserstate_begin = line.index('laser ', idx_intensity_end) + 6 - idx_laserstate_end = line.index(':', idx_laserstate_begin) + #idx_laserstate_begin = line.index('laser ', idx_intensity_end) + 6 + #idx_laserstate_end = line.index(':', idx_laserstate_begin) payload = { - "mx": line[idx_mx_begin:idx_mx_end], - "my": line[idx_my_begin:idx_my_end], - "mz": line[idx_mz_begin:idx_mz_end], + #"mx": line[idx_mx_begin:idx_mx_end], + #"my": line[idx_my_begin:idx_my_end], + #"mz": line[idx_mz_begin:idx_mz_end], "wx": line[idx_wx_begin:idx_wx_end], - "wy": line[idx_wy_begin:idx_wy_end], - "wz": line[idx_wz_begin:idx_wz_end], - "laser": line[idx_laserstate_begin:idx_laserstate_end], - "intensity": line[idx_intensity_begin:idx_intensity_end] + "wy": line[idx_wy_begin:idx_wy_end], + #"wz": line[idx_wz_begin:idx_wz_end], + #"laser": line[idx_laserstate_begin:idx_laserstate_end], + #"intensity": line[idx_intensity_begin:idx_intensity_end] } eventManager().fire(Events.RT_STATE, payload) except ValueError: From 906fd54c41e5b2a02bafe7aba2c5aaaae0c953a0 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 21 Sep 2015 16:36:24 +0200 Subject: [PATCH 02/35] debug bug fix :) --- src/octoprint/util/comm_acc.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 758bd837..ad8d553f 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -261,10 +261,13 @@ class MachineCom(object): self._temperature_timer.cancel() self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) self._temperature_timer.start() - else: + elif newState == self.STATE_OPERATIONAL: self._temperature_timer.cancel() self._temperature_timer = RepeatedTimer(0.2, self._poll_temperature, run_first=True) self._temperature_timer.start() + else: + if self._temperature_timer != None: + self._temperature_timer.cancel() if newState == self.STATE_CLOSED or newState == self.STATE_CLOSED_WITH_ERROR: if settings().get(["feature", "sdSupport"]): From 8f144accf443d745f848239c70f41551261b12c3 Mon Sep 17 00:00:00 2001 From: Teja Date: Wed, 23 Sep 2015 11:45:23 +0200 Subject: [PATCH 03/35] added todo comments --- src/octoprint/plugins/svgtogcode/__init__.py | 2 +- src/octoprint/util/comm_acc.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/octoprint/plugins/svgtogcode/__init__.py b/src/octoprint/plugins/svgtogcode/__init__.py index 954aa226..41db0b16 100644 --- a/src/octoprint/plugins/svgtogcode/__init__.py +++ b/src/octoprint/plugins/svgtogcode/__init__.py @@ -344,7 +344,7 @@ class SvgToGcodePlugin(octoprint.plugin.SlicerPlugin, if not machinecode_path: path, _ = os.path.splitext(model_path) machinecode_path = path + ".gco" - + self._svgtogcode_logger.info("### Slicing %s to %s using profile stored at %s" % (model_path, machinecode_path, profile_path)) ## direct call diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ad8d553f..b6f616be 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -885,6 +885,8 @@ class MachineCom(object): pathToGrblHex = cwd + "/../grbl/grbl.hex" import subprocess + # TODO check if avrdude is installed. + # TODO log in logfile as well, not only to the serial monitor (use self._logger.info()... ) params = ["avrdude", "-patmega328p", "-carduino", "-b" + str(self._baudrate), "-P" + str(self._port), "-D", "-Uflash:w:" + pathToGrblHex] returnCode = subprocess.call(params) From 6fd68e0df0f25001bcf271d442ae5a201a9e41ff Mon Sep 17 00:00:00 2001 From: make-ing Date: Wed, 23 Sep 2015 13:26:30 +0200 Subject: [PATCH 04/35] changed detail information image display from percent to horizontal and vertical mm --- .../plugins/svgtogcode/static/js/working_area.js | 6 ++++-- src/octoprint/templates/mrbeam_index.jinja2 | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/octoprint/plugins/svgtogcode/static/js/working_area.js b/src/octoprint/plugins/svgtogcode/static/js/working_area.js index 671f52dd..14a35df1 100644 --- a/src/octoprint/plugins/svgtogcode/static/js/working_area.js +++ b/src/octoprint/plugins/svgtogcode/static/js/working_area.js @@ -317,11 +317,13 @@ $(function(){ var endIdx = transform.local.indexOf(',', startIdx); var rot = parseFloat(transform.local.substring(startIdx, endIdx)) || 0; // if(!rot) rot = 0; // avoid NaN - var scale = (Math.pow(transform.localMatrix.a,2) + Math.pow(transform.localMatrix.b,2)) * 100; + var horizontal = self.px2mm(bbox.x2 - bbox.x); + var vertical = self.px2mm(bbox.y2 - bbox.y); var id = svg.attr('id'); var label_id = id.substr(0, id.indexOf('-')); $('#'+label_id+' .translation').text(tx.toFixed(1) + ',' + ty.toFixed(1)); - $('#'+label_id+' .scale').text(scale.toFixed(1) + '%'); + $('#'+label_id+' .horizontal').text(horizontal.toFixed() + 'mm'); + $('#'+label_id+' .vertical').text(vertical.toFixed() + 'mm'); $('#'+label_id+' .rotation').text(rot.toFixed(1) + '°'); }; diff --git a/src/octoprint/templates/mrbeam_index.jinja2 b/src/octoprint/templates/mrbeam_index.jinja2 index e070d684..657ce2aa 100644 --- a/src/octoprint/templates/mrbeam_index.jinja2 +++ b/src/octoprint/templates/mrbeam_index.jinja2 @@ -127,7 +127,7 @@ -
@@ -216,8 +216,10 @@
0,0 - - 100% + + 0mm + + 0mm From 53ad23046123d7f3802f161b2fbf033c17604519 Mon Sep 17 00:00:00 2001 From: make-ing Date: Wed, 23 Sep 2015 14:08:00 +0200 Subject: [PATCH 05/35] changed from eventManager to callback.on_comm_pos_update --- src/octoprint/printer/standard.py | 12 +++++------ .../static/js/app/viewmodels/printerstate.js | 1 + src/octoprint/util/comm_acc.py | 20 +++++++++++-------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index 8fec480d..b0827966 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -867,13 +867,13 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): def _add_position_data(self, MPos, WPos): if MPos is None or WPos is None: - MPosString = WPosString = "-" - else: - MPosString = "X: %.4f Y: %.4f Z: %.4f" % ( MPos[0], MPos[1], MPos[2] ) - WPosString = "X: %.4f Y: %.4f Z: %.4f" % ( WPos[0], WPos[1], WPos[2] ) + MPos = WPos = [0, 0, 0] + #else: + #MPosString = "X: %.4f Y: %.4f Z: %.4f" % ( MPos[0], MPos[1], MPos[2] ) + #WPosString = "X: %.4f Y: %.4f Z: %.4f" % ( WPos[0], WPos[1], WPos[2] ) - self._stateMonitor.setWorkPosition(WPosString) - self._stateMonitor.setMachinePosition(MPosString) + self._stateMonitor.setWorkPosition(WPos) + self._stateMonitor.setMachinePosition(MPos) class StateMonitor(object): diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 6afebfc2..65a79df5 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -123,6 +123,7 @@ $(function() { self._processProgressData(data.progress); self._processZData(data.currentZ); self._processBusyFiles(data.busyFiles); + self.currentPos({x: data.workPosition[0], y: data.workPosition[1]}); }; self._processStateData = function(data) { var prevPaused = self.isPaused(); diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ad8d553f..4a13f10a 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -266,7 +266,7 @@ class MachineCom(object): self._temperature_timer = RepeatedTimer(0.2, self._poll_temperature, run_first=True) self._temperature_timer.start() else: - if self._temperature_timer != None: + if self._temperature_timer is not None: self._temperature_timer.cancel() if newState == self.STATE_CLOSED or newState == self.STATE_CLOSED_WITH_ERROR: @@ -1990,10 +1990,10 @@ class MachineCom(object): # line example: # try: - #idx_mx_begin = line.index('MPos:') + 5 - #idx_mx_end = line.index('.', idx_mx_begin) + 2 - #idx_my_begin = line.index(',', idx_mx_end) + 1 - #idx_my_end = line.index('.', idx_my_begin) + 2 + idx_mx_begin = line.index('MPos:') + 5 + idx_mx_end = line.index('.', idx_mx_begin) + 2 + idx_my_begin = line.index(',', idx_mx_end) + 1 + idx_my_end = line.index('.', idx_my_begin) + 2 #idx_mz_begin = line.index(',', idx_my_end) + 1 #idx_mz_end = line.index('.', idx_mz_begin) + 2 @@ -2011,8 +2011,8 @@ class MachineCom(object): #idx_laserstate_end = line.index(':', idx_laserstate_begin) payload = { - #"mx": line[idx_mx_begin:idx_mx_end], - #"my": line[idx_my_begin:idx_my_end], + "mx": line[idx_mx_begin:idx_mx_end], + "my": line[idx_my_begin:idx_my_end], #"mz": line[idx_mz_begin:idx_mz_end], "wx": line[idx_wx_begin:idx_wx_end], "wy": line[idx_wy_begin:idx_wy_end], @@ -2020,7 +2020,8 @@ class MachineCom(object): #"laser": line[idx_laserstate_begin:idx_laserstate_end], #"intensity": line[idx_intensity_begin:idx_intensity_end] } - eventManager().fire(Events.RT_STATE, payload) + self._callback.on_comm_pos_update([mx, my, 0], [wx, wy, 0]) + #eventManager().fire(Events.RT_STATE, payload) except ValueError: pass @@ -2129,6 +2130,9 @@ class MachineComPrintCallback(object): def on_comm_force_disconnect(self): pass + def on_comm_pos_update(self, MPos, WPos): + pass + ### Printing file information classes ################################################################################## class PrintingFileInformation(object): From 2b3ebaf14d49da4f41c3c67e1d38b64a6dd1f2da Mon Sep 17 00:00:00 2001 From: make-ing Date: Wed, 23 Sep 2015 14:37:34 +0200 Subject: [PATCH 06/35] fixed null bug --- src/octoprint/static/js/app/viewmodels/printerstate.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 65a79df5..08da2bc7 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -123,7 +123,14 @@ $(function() { self._processProgressData(data.progress); self._processZData(data.currentZ); self._processBusyFiles(data.busyFiles); - self.currentPos({x: data.workPosition[0], y: data.workPosition[1]}); + self._processWPosData(data.workPosition); + }; + self._processWPosData = function(data) { + if (data == null) { + self.currentPos({x: 0, y: 0}); + } else { + self.currentPos({x: data.workPosition[0], y: data.workPosition[1]}); + } }; self._processStateData = function(data) { var prevPaused = self.isPaused(); From a9da7b8b209e8fcb59b89e3cc2b704a843aae2b3 Mon Sep 17 00:00:00 2001 From: make-ing Date: Wed, 23 Sep 2015 14:51:39 +0200 Subject: [PATCH 07/35] string to int bug fix --- src/octoprint/util/comm_acc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ea067020..67ab7283 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -885,7 +885,7 @@ class MachineCom(object): pathToGrblHex = cwd + "/../grbl/grbl.hex" import subprocess - # TODO check if avrdude is installed. + # TODO check if avrdude is installed. # TODO log in logfile as well, not only to the serial monitor (use self._logger.info()... ) params = ["avrdude", "-patmega328p", "-carduino", "-b" + str(self._baudrate), "-P" + str(self._port), "-D", "-Uflash:w:" + pathToGrblHex] returnCode = subprocess.call(params) @@ -2022,7 +2022,7 @@ class MachineCom(object): #"laser": line[idx_laserstate_begin:idx_laserstate_end], #"intensity": line[idx_intensity_begin:idx_intensity_end] } - self._callback.on_comm_pos_update([mx, my, 0], [wx, wy, 0]) + self._callback.on_comm_pos_update(int([line[idx_mx_begin:idx_mx_end]), int(line[idx_my_begin:idx_my_end]), 0], [int(line[idx_wx_begin:idx_wx_end]), int(line[idx_wy_begin:idx_wy_end]), 0]) #eventManager().fire(Events.RT_STATE, payload) except ValueError: pass From 563a85ac7e3d4e5fbcb97c9c4ef2d1bc7a546e0f Mon Sep 17 00:00:00 2001 From: make-ing Date: Wed, 23 Sep 2015 15:25:23 +0200 Subject: [PATCH 08/35] paranthesis bug fix --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 67ab7283..7865d2ee 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -2022,7 +2022,7 @@ class MachineCom(object): #"laser": line[idx_laserstate_begin:idx_laserstate_end], #"intensity": line[idx_intensity_begin:idx_intensity_end] } - self._callback.on_comm_pos_update(int([line[idx_mx_begin:idx_mx_end]), int(line[idx_my_begin:idx_my_end]), 0], [int(line[idx_wx_begin:idx_wx_end]), int(line[idx_wy_begin:idx_wy_end]), 0]) + self._callback.on_comm_pos_update([int(line[idx_mx_begin:idx_mx_end]), int(line[idx_my_begin:idx_my_end]), 0], [int(line[idx_wx_begin:idx_wx_end]), int(line[idx_wy_begin:idx_wy_end]), 0]) #eventManager().fire(Events.RT_STATE, payload) except ValueError: pass From c5aa726155013d2eb13e36e1c33f5163cb89edec Mon Sep 17 00:00:00 2001 From: make-ing Date: Wed, 23 Sep 2015 16:42:49 +0200 Subject: [PATCH 09/35] fixed position update bug and display horizontal and vertical bug --- .gitignore | 1 + .../svgtogcode/static/js/working_area.js | 4 ++-- .../static/js/app/viewmodels/printerstate.js | 2 +- src/octoprint/templates/mrbeam_index.jinja2 | 5 ++--- src/octoprint/util/comm_acc.py | 18 +++++++++++------- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index f6e2d3c9..94d88beb 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ OctoPrint.egg-info /nbproject/ .directory .project +out/ diff --git a/src/octoprint/plugins/svgtogcode/static/js/working_area.js b/src/octoprint/plugins/svgtogcode/static/js/working_area.js index 14a35df1..df3b1351 100644 --- a/src/octoprint/plugins/svgtogcode/static/js/working_area.js +++ b/src/octoprint/plugins/svgtogcode/static/js/working_area.js @@ -317,8 +317,8 @@ $(function(){ var endIdx = transform.local.indexOf(',', startIdx); var rot = parseFloat(transform.local.substring(startIdx, endIdx)) || 0; // if(!rot) rot = 0; // avoid NaN - var horizontal = self.px2mm(bbox.x2 - bbox.x); - var vertical = self.px2mm(bbox.y2 - bbox.y); + var horizontal = self.px2mm((bbox.x2 - bbox.x) * globalScale); + var vertical = self.px2mm((bbox.y2 - bbox.y) * globalScale); var id = svg.attr('id'); var label_id = id.substr(0, id.indexOf('-')); $('#'+label_id+' .translation').text(tx.toFixed(1) + ',' + ty.toFixed(1)); diff --git a/src/octoprint/static/js/app/viewmodels/printerstate.js b/src/octoprint/static/js/app/viewmodels/printerstate.js index 08da2bc7..1ceacb01 100644 --- a/src/octoprint/static/js/app/viewmodels/printerstate.js +++ b/src/octoprint/static/js/app/viewmodels/printerstate.js @@ -129,7 +129,7 @@ $(function() { if (data == null) { self.currentPos({x: 0, y: 0}); } else { - self.currentPos({x: data.workPosition[0], y: data.workPosition[1]}); + self.currentPos({x: data[0], y: data[1]}); } }; self._processStateData = function(data) { diff --git a/src/octoprint/templates/mrbeam_index.jinja2 b/src/octoprint/templates/mrbeam_index.jinja2 index 657ce2aa..514f78ad 100644 --- a/src/octoprint/templates/mrbeam_index.jinja2 +++ b/src/octoprint/templates/mrbeam_index.jinja2 @@ -216,13 +216,12 @@
0,0 + +
0mm 0mm - - -
Design exceeds the working area. diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 7865d2ee..3378bfe6 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -2012,17 +2012,21 @@ class MachineCom(object): #idx_laserstate_begin = line.index('laser ', idx_intensity_end) + 6 #idx_laserstate_end = line.index(':', idx_laserstate_begin) - payload = { - "mx": line[idx_mx_begin:idx_mx_end], - "my": line[idx_my_begin:idx_my_end], + #payload = { + #"mx": line[idx_mx_begin:idx_mx_end], + #"my": line[idx_my_begin:idx_my_end], #"mz": line[idx_mz_begin:idx_mz_end], - "wx": line[idx_wx_begin:idx_wx_end], - "wy": line[idx_wy_begin:idx_wy_end], + #"wx": line[idx_wx_begin:idx_wx_end], + #"wy": line[idx_wy_begin:idx_wy_end], #"wz": line[idx_wz_begin:idx_wz_end], #"laser": line[idx_laserstate_begin:idx_laserstate_end], #"intensity": line[idx_intensity_begin:idx_intensity_end] - } - self._callback.on_comm_pos_update([int(line[idx_mx_begin:idx_mx_end]), int(line[idx_my_begin:idx_my_end]), 0], [int(line[idx_wx_begin:idx_wx_end]), int(line[idx_wy_begin:idx_wy_end]), 0]) + #} + mx = int(float(line[idx_mx_begin:idx_mx_end])) + my = int(float(line[idx_my_begin:idx_my_end])) + wx = int(float(line[idx_wx_begin:idx_wx_end])) + wy = int(float(line[idx_wy_begin:idx_wy_end])) + self._callback.on_comm_pos_update([mx, my, 0], [wx, wy, 0]) #eventManager().fire(Events.RT_STATE, payload) except ValueError: pass From ea20be6601488721e999969a16a88a40bbde9c82 Mon Sep 17 00:00:00 2001 From: make-ing Date: Wed, 23 Sep 2015 18:53:00 +0200 Subject: [PATCH 10/35] changed position output to float --- src/octoprint/util/comm_acc.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 3378bfe6..3505458a 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -2022,10 +2022,10 @@ class MachineCom(object): #"laser": line[idx_laserstate_begin:idx_laserstate_end], #"intensity": line[idx_intensity_begin:idx_intensity_end] #} - mx = int(float(line[idx_mx_begin:idx_mx_end])) - my = int(float(line[idx_my_begin:idx_my_end])) - wx = int(float(line[idx_wx_begin:idx_wx_end])) - wy = int(float(line[idx_wy_begin:idx_wy_end])) + mx = float(line[idx_mx_begin:idx_mx_end]) + my = float(line[idx_my_begin:idx_my_end]) + wx = float(line[idx_wx_begin:idx_wx_end]) + wy = float(line[idx_wy_begin:idx_wy_end]) self._callback.on_comm_pos_update([mx, my, 0], [wx, wy, 0]) #eventManager().fire(Events.RT_STATE, payload) except ValueError: From c75bd69eb4d146387c208b341b78339ad28af28e Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 24 Sep 2015 10:30:40 +0200 Subject: [PATCH 11/35] added horizontal and vertical ui label --- src/octoprint/templates/mrbeam_index.jinja2 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/octoprint/templates/mrbeam_index.jinja2 b/src/octoprint/templates/mrbeam_index.jinja2 index 514f78ad..0e9d5384 100644 --- a/src/octoprint/templates/mrbeam_index.jinja2 +++ b/src/octoprint/templates/mrbeam_index.jinja2 @@ -242,11 +242,12 @@
0,0 - - 100% - - +
+ + 0mm + + 0mm
Design exceeds the working area. From 2f387c55cc6957302d2f191d86b4c6a034ad8dad Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 24 Sep 2015 10:56:07 +0200 Subject: [PATCH 12/35] fixed wrong class bug --- src/octoprint/templates/mrbeam_index.jinja2 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/templates/mrbeam_index.jinja2 b/src/octoprint/templates/mrbeam_index.jinja2 index 0e9d5384..5d454b5b 100644 --- a/src/octoprint/templates/mrbeam_index.jinja2 +++ b/src/octoprint/templates/mrbeam_index.jinja2 @@ -245,9 +245,9 @@
- 0mm + 0mm - 0mm + 0mm
Design exceeds the working area. From 156ac00f52cf6491fe47a36f15bce5206cb321e6 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 24 Sep 2015 11:31:57 +0200 Subject: [PATCH 13/35] img id bug fix --- src/octoprint/plugins/svgtogcode/static/js/working_area.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/plugins/svgtogcode/static/js/working_area.js b/src/octoprint/plugins/svgtogcode/static/js/working_area.js index df3b1351..b4888f54 100644 --- a/src/octoprint/plugins/svgtogcode/static/js/working_area.js +++ b/src/octoprint/plugins/svgtogcode/static/js/working_area.js @@ -414,7 +414,7 @@ $(function(){ newImg.transformable(); newImg.ftDisableRotate(); newImg.ftRegisterCallback(self.svgTransformUpdate); - file.id = previewId; + file.id = id; file.previewId = previewId; file.url = url; file.subtype = "bitmap"; From 8eb3fd3029182e5ca1d2581e7128c47d5d64d3b1 Mon Sep 17 00:00:00 2001 From: Teja Date: Thu, 24 Sep 2015 12:19:46 +0200 Subject: [PATCH 14/35] support for /debug commands --- src/octoprint/static/js/app/viewmodels/terminal.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/octoprint/static/js/app/viewmodels/terminal.js b/src/octoprint/static/js/app/viewmodels/terminal.js index 45a3a254..b244bf8c 100644 --- a/src/octoprint/static/js/app/viewmodels/terminal.js +++ b/src/octoprint/static/js/app/viewmodels/terminal.js @@ -162,7 +162,8 @@ $(function() { } // var re = /^([gmt][0-9]+)(\s.*)?/; - var re = /^([gmtfs][0-9]+|\$[cinhgx#$]|[?~!])(.*)?/; // grbl style + // gcode words | $ commands | RT | /debug + var re = /^([gmtfs][0-9]+|\$[cinhgx#$]|[?~!]|\/)(.*)?/; // grbl style var commandMatch = command.match(re); if (commandMatch != null) { command = commandMatch[1].toUpperCase() + ((commandMatch[2] !== undefined) ? commandMatch[2] : ""); From 198f40e2d704cf35d04f7d4c2f763c20a8ca34e7 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 24 Sep 2015 14:05:11 +0200 Subject: [PATCH 15/35] added /toggleStatusReport command --- src/octoprint/util/comm_acc.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 3505458a..ce27b8cd 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -258,12 +258,13 @@ class MachineCom(object): return if newState == self.STATE_PRINTING: - self._temperature_timer.cancel() - self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) - self._temperature_timer.start() + if self._temperature_timer is not None: + self._temperature_timer.cancel() + self._temperature_timer = None elif newState == self.STATE_OPERATIONAL: - self._temperature_timer.cancel() - self._temperature_timer = RepeatedTimer(0.2, self._poll_temperature, run_first=True) + if self._temperature_timer is not None: + self._temperature_timer.cancel() + self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) self._temperature_timer.start() else: if self._temperature_timer is not None: @@ -427,6 +428,7 @@ class MachineCom(object): if self._temperature_timer is not None: try: self._temperature_timer.cancel() + self._temperature_timer = None except: pass @@ -474,6 +476,21 @@ class MachineCom(object): cmd = process_gcode_line(cmd) if not cmd: return + + if cmd[0] == "/": + if "toggleStatusReport" in cmd: + if self._temperature_timer is None: + self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) + self._temperature_timer.start() + else: + self._temperature_timer.cancel() + self._temperature_timer = None + else: + self._log("Command not Found!") + self._log("available commands are:") + self._log(" /toggleStatusReport") + return + eepromCmd = re.search("^\$[0-9]+=.+$", cmd) if(eepromCmd and self.isPrinting()): self._log("Warning: Configuration changes during print are not allowed!") @@ -1381,6 +1398,8 @@ class MachineCom(object): def _onConnected(self, nextState): self._serial.timeout = settings().getFloat(["serial", "timeout", "communication"]) #self._temperature_timer = RepeatedTimer(lambda: get_interval("temperature"), self._poll_temperature, run_first=True) + if self._temperature_timer is not None: + self._temperature_timer.cancel() self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) self._temperature_timer.start() From a0b43adc6123d3d0ae544abebb4ba237976c82e7 Mon Sep 17 00:00:00 2001 From: make-ing Date: Fri, 25 Sep 2015 10:03:26 +0200 Subject: [PATCH 16/35] change command test to only lowercase --- src/octoprint/util/comm_acc.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ce27b8cd..a72cbda0 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -478,7 +478,8 @@ class MachineCom(object): return if cmd[0] == "/": - if "toggleStatusReport" in cmd: + specialcmd = cmd[1:].lower() + if "togglestatusreport" in specialcmd: if self._temperature_timer is None: self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) self._temperature_timer.start() @@ -488,7 +489,7 @@ class MachineCom(object): else: self._log("Command not Found!") self._log("available commands are:") - self._log(" /toggleStatusReport") + self._log(" /togglestatusreport") return eepromCmd = re.search("^\$[0-9]+=.+$", cmd) From a1c40c7a41fcda20ccc3c82151800a0faddd28a2 Mon Sep 17 00:00:00 2001 From: make-ing Date: Fri, 25 Sep 2015 11:50:41 +0200 Subject: [PATCH 17/35] added setstatusfrequency special command --- src/octoprint/util/comm_acc.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index a72cbda0..73b0945f 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -486,10 +486,23 @@ class MachineCom(object): else: self._temperature_timer.cancel() self._temperature_timer = None + if "setstatusfreqency" in specialcmd: + data = specialcmd.split(' ') + try: + frequency = float(data[1]) + except: + self._log("No frequency setting found! Using 1 sec.") + frequency = 1 + if self._temperature_timer is not None: + self._temperature_timer.cancel() + + self._temperature_timer = RepeatedTimer(frequency, self._poll_temperature, run_first=True) + self._temperature_timer.start() else: self._log("Command not Found!") self._log("available commands are:") self._log(" /togglestatusreport") + self._log(" /setstatusfreqency ") return eepromCmd = re.search("^\$[0-9]+=.+$", cmd) From 4f00f2768ccb409882c5932fa884095a8344d5d9 Mon Sep 17 00:00:00 2001 From: make-ing Date: Mon, 28 Sep 2015 11:36:32 +0200 Subject: [PATCH 18/35] fixed if else bug in specialcommand handling --- src/octoprint/util/comm_acc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 73b0945f..504249c7 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -486,11 +486,11 @@ class MachineCom(object): else: self._temperature_timer.cancel() self._temperature_timer = None - if "setstatusfreqency" in specialcmd: + elif "setstatusfrequency" in specialcmd: data = specialcmd.split(' ') try: frequency = float(data[1]) - except: + except ValueError: self._log("No frequency setting found! Using 1 sec.") frequency = 1 if self._temperature_timer is not None: @@ -502,7 +502,7 @@ class MachineCom(object): self._log("Command not Found!") self._log("available commands are:") self._log(" /togglestatusreport") - self._log(" /setstatusfreqency ") + self._log(" /setstatusfrequency ") return eepromCmd = re.search("^\$[0-9]+=.+$", cmd) From 9aeacfee77f7ab8ba48837c062ba0c436baeabc6 Mon Sep 17 00:00:00 2001 From: Teja Date: Thu, 1 Oct 2015 10:54:43 +0200 Subject: [PATCH 19/35] commented out lots of 3d printing stuff. --- src/octoprint/util/comm_acc.py | 284 ++++++++++++++++----------------- 1 file changed, 142 insertions(+), 142 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ce27b8cd..b9fb028f 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -486,7 +486,7 @@ class MachineCom(object): self._temperature_timer.cancel() self._temperature_timer = None else: - self._log("Command not Found!") + self._log("Command not Found! %s" % cmd) self._log("available commands are:") self._log(" /toggleStatusReport") return @@ -986,7 +986,7 @@ class MachineCom(object): continue ##~~ Error handling - line = self._handleErrors(line) + #line = self._handleErrors(line) # GRBL Position update if self._grbl : @@ -1057,154 +1057,154 @@ class MachineCom(object): if("error:" in line): self.handle_grbl_error(line) - ##~~ SD file list - # if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing - if self._sdFileList and not "End file list" in line: - preprocessed_line = line.strip().lower() - fileinfo = preprocessed_line.rsplit(None, 1) - if len(fileinfo) > 1: - # we might have extended file information here, so let's split filename and size and try to make them a bit nicer - filename, size = fileinfo - try: - size = int(size) - except ValueError: - # whatever that was, it was not an integer, so we'll just use the whole line as filename and set size to None - filename = preprocessed_line - size = None - else: - # no extended file information, so only the filename is there and we set size to None - filename = preprocessed_line - size = None - - if valid_file_type(filename, "machinecode"): - if filter_non_ascii(filename): - self._logger.warn("Got a file from printer's SD that has a non-ascii filename (%s), that shouldn't happen according to the protocol" % filename) - else: - if not filename.startswith("/"): - # file from the root of the sd -- we'll prepend a / - filename = "/" + filename - self._sdFiles.append((filename, size)) - continue +# ##~~ SD file list +# # if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing +# if self._sdFileList and not "End file list" in line: +# preprocessed_line = line.strip().lower() +# fileinfo = preprocessed_line.rsplit(None, 1) +# if len(fileinfo) > 1: +# # we might have extended file information here, so let's split filename and size and try to make them a bit nicer +# filename, size = fileinfo +# try: +# size = int(size) +# except ValueError: +# # whatever that was, it was not an integer, so we'll just use the whole line as filename and set size to None +# filename = preprocessed_line +# size = None +# else: +# # no extended file information, so only the filename is there and we set size to None +# filename = preprocessed_line +# size = None +# +# if valid_file_type(filename, "machinecode"): +# if filter_non_ascii(filename): +# self._logger.warn("Got a file from printer's SD that has a non-ascii filename (%s), that shouldn't happen according to the protocol" % filename) +# else: +# if not filename.startswith("/"): +# # file from the root of the sd -- we'll prepend a / +# filename = "/" + filename +# self._sdFiles.append((filename, size)) +# continue ##~~ process oks if line.strip().startswith("ok") or (self.isPrinting() and supportWait and line.strip().startswith("wait")): self._clear_to_send.set() self._long_running_command = False - ##~~ Temperature processing - if ' T:' in line or line.startswith('T:') or ' T0:' in line or line.startswith('T0:') or ' B:' in line or line.startswith('B:'): - if not disable_external_heatup_detection and not line.strip().startswith("ok") and not self._heating: - self._logger.debug("Externally triggered heatup detected") - self._heating = True - self._heatupWaitStartTime = time.time() - self._processTemperatures(line) - self._callback.on_comm_temperature_update(self._temp, self._bedTemp) +# ##~~ Temperature processing +# if ' T:' in line or line.startswith('T:') or ' T0:' in line or line.startswith('T0:') or ' B:' in line or line.startswith('B:'): +# if not disable_external_heatup_detection and not line.strip().startswith("ok") and not self._heating: +# self._logger.debug("Externally triggered heatup detected") +# self._heating = True +# self._heatupWaitStartTime = time.time() +# self._processTemperatures(line) +# self._callback.on_comm_temperature_update(self._temp, self._bedTemp) +# +# elif supportRepetierTargetTemp and ('TargetExtr' in line or 'TargetBed' in line): +# matchExtr = self._regex_repetierTempExtr.match(line) +# matchBed = self._regex_repetierTempBed.match(line) +# +# if matchExtr is not None: +# toolNum = int(matchExtr.group(1)) +# try: +# target = float(matchExtr.group(2)) +# if toolNum in self._temp.keys() and self._temp[toolNum] is not None and isinstance(self._temp[toolNum], tuple): +# (actual, oldTarget) = self._temp[toolNum] +# self._temp[toolNum] = (actual, target) +# else: +# self._temp[toolNum] = (None, target) +# self._callback.on_comm_temperature_update(self._temp, self._bedTemp) +# except ValueError: +# pass +# elif matchBed is not None: +# try: +# target = float(matchBed.group(1)) +# if self._bedTemp is not None and isinstance(self._bedTemp, tuple): +# (actual, oldTarget) = self._bedTemp +# self._bedTemp = (actual, target) +# else: +# self._bedTemp = (None, target) +# self._callback.on_comm_temperature_update(self._temp, self._bedTemp) +# except ValueError: +# pass - elif supportRepetierTargetTemp and ('TargetExtr' in line or 'TargetBed' in line): - matchExtr = self._regex_repetierTempExtr.match(line) - matchBed = self._regex_repetierTempBed.match(line) +# #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 'ok' in line and self._heatupWaitStartTime: +# self._heatupWaitTimeLost = self._heatupWaitTimeLost + (time.time() - self._heatupWaitStartTime) +# self._heatupWaitStartTime = None +# self._heating = False - if matchExtr is not None: - toolNum = int(matchExtr.group(1)) - try: - target = float(matchExtr.group(2)) - if toolNum in self._temp.keys() and self._temp[toolNum] is not None and isinstance(self._temp[toolNum], tuple): - (actual, oldTarget) = self._temp[toolNum] - self._temp[toolNum] = (actual, target) - else: - self._temp[toolNum] = (None, target) - self._callback.on_comm_temperature_update(self._temp, self._bedTemp) - except ValueError: - pass - elif matchBed is not None: - try: - target = float(matchBed.group(1)) - if self._bedTemp is not None and isinstance(self._bedTemp, tuple): - (actual, oldTarget) = self._bedTemp - self._bedTemp = (actual, target) - else: - self._bedTemp = (None, target) - self._callback.on_comm_temperature_update(self._temp, self._bedTemp) - except ValueError: - pass - - #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 'ok' in line and self._heatupWaitStartTime: - self._heatupWaitTimeLost = self._heatupWaitTimeLost + (time.time() - self._heatupWaitStartTime) - self._heatupWaitStartTime = None - self._heating = False - - ##~~ SD Card handling - elif 'SD init fail' in line or 'volume.init failed' in line or 'openRoot failed' in line: - self._sdAvailable = False - self._sdFiles = [] - self._callback.on_comm_sd_state_change(self._sdAvailable) - elif 'Not SD printing' in line: - if self.isSdFileSelected() and self.isPrinting(): - # something went wrong, printer is reporting that we actually are not printing right now... - self._sdFilePos = 0 - self._changeState(self.STATE_OPERATIONAL) - elif 'SD card ok' in line and not self._sdAvailable: - self._sdAvailable = True - self.refreshSdFiles() - self._callback.on_comm_sd_state_change(self._sdAvailable) - elif 'Begin file list' in line: - self._sdFiles = [] - self._sdFileList = True - elif 'End file list' in line: - self._sdFileList = False - self._callback.on_comm_sd_files(self._sdFiles) - elif 'SD printing byte' in line and self.isSdPrinting(): - # answer to M27, at least on Marlin, Repetier and Sprinter: "SD printing byte %d/%d" - match = self._regex_sdPrintingByte.search(line) - self._currentFile.setFilepos(int(match.group(1))) - self._callback.on_comm_progress() - elif 'File opened' in line and not self._ignore_select: - # answer to M23, at least on Marlin, Repetier and Sprinter: "File opened:%s Size:%d" - match = self._regex_sdFileOpened.search(line) - if self._sdFileToSelect: - name = self._sdFileToSelect - self._sdFileToSelect = None - else: - name = match.group(1) - self._currentFile = PrintingSdFileInformation(name, int(match.group(2))) - elif 'File selected' in line: - if self._ignore_select: - self._ignore_select = False - elif self._currentFile is not None: - # final answer to M23, at least on Marlin, Repetier and Sprinter: "File selected" - self._callback.on_comm_file_selected(self._currentFile.getFilename(), self._currentFile.getFilesize(), True) - eventManager().fire(Events.FILE_SELECTED, { - "file": self._currentFile.getFilename(), - "origin": self._currentFile.getFileLocation() - }) - elif 'Writing to file' in line: - # anwer to M28, at least on Marlin, Repetier and Sprinter: "Writing to file: %s" - self._changeState(self.STATE_PRINTING) - self._clear_to_send.set() - line = "ok" - elif 'Done printing file' in line and self.isSdPrinting(): - # printer is reporting file finished printing - self._sdFilePos = 0 - self._callback.on_comm_print_job_done() - self._changeState(self.STATE_OPERATIONAL) - eventManager().fire(Events.PRINT_DONE, { - "file": self._currentFile.getFilename(), - "filename": os.path.basename(self._currentFile.getFilename()), - "origin": self._currentFile.getFileLocation(), - "time": self.getPrintTime() - }) - if self._sd_status_timer is not None: - try: - self._sd_status_timer.cancel() - except: - pass - elif 'Done saving file' in line: - self.refreshSdFiles() - elif 'File deleted' in line and line.strip().endswith("ok"): - # buggy Marlin version that doesn't send a proper \r after the "File deleted" statement, fixed in - # current versions - self._clear_to_send.set() +# ##~~ SD Card handling +# elif 'SD init fail' in line or 'volume.init failed' in line or 'openRoot failed' in line: +# self._sdAvailable = False +# self._sdFiles = [] +# self._callback.on_comm_sd_state_change(self._sdAvailable) +# elif 'Not SD printing' in line: +# if self.isSdFileSelected() and self.isPrinting(): +# # something went wrong, printer is reporting that we actually are not printing right now... +# self._sdFilePos = 0 +# self._changeState(self.STATE_OPERATIONAL) +# elif 'SD card ok' in line and not self._sdAvailable: +# self._sdAvailable = True +# self.refreshSdFiles() +# self._callback.on_comm_sd_state_change(self._sdAvailable) +# elif 'Begin file list' in line: +# self._sdFiles = [] +# self._sdFileList = True +# elif 'End file list' in line: +# self._sdFileList = False +# self._callback.on_comm_sd_files(self._sdFiles) +# elif 'SD printing byte' in line and self.isSdPrinting(): +# # answer to M27, at least on Marlin, Repetier and Sprinter: "SD printing byte %d/%d" +# match = self._regex_sdPrintingByte.search(line) +# self._currentFile.setFilepos(int(match.group(1))) +# self._callback.on_comm_progress() +# elif 'File opened' in line and not self._ignore_select: +# # answer to M23, at least on Marlin, Repetier and Sprinter: "File opened:%s Size:%d" +# match = self._regex_sdFileOpened.search(line) +# if self._sdFileToSelect: +# name = self._sdFileToSelect +# self._sdFileToSelect = None +# else: +# name = match.group(1) +# self._currentFile = PrintingSdFileInformation(name, int(match.group(2))) +# elif 'File selected' in line: +# if self._ignore_select: +# self._ignore_select = False +# elif self._currentFile is not None: +# # final answer to M23, at least on Marlin, Repetier and Sprinter: "File selected" +# self._callback.on_comm_file_selected(self._currentFile.getFilename(), self._currentFile.getFilesize(), True) +# eventManager().fire(Events.FILE_SELECTED, { +# "file": self._currentFile.getFilename(), +# "origin": self._currentFile.getFileLocation() +# }) +# elif 'Writing to file' in line: +# # anwer to M28, at least on Marlin, Repetier and Sprinter: "Writing to file: %s" +# self._changeState(self.STATE_PRINTING) +# self._clear_to_send.set() +# line = "ok" +# elif 'Done printing file' in line and self.isSdPrinting(): +# # printer is reporting file finished printing +# self._sdFilePos = 0 +# self._callback.on_comm_print_job_done() +# self._changeState(self.STATE_OPERATIONAL) +# eventManager().fire(Events.PRINT_DONE, { +# "file": self._currentFile.getFilename(), +# "filename": os.path.basename(self._currentFile.getFilename()), +# "origin": self._currentFile.getFileLocation(), +# "time": self.getPrintTime() +# }) +# if self._sd_status_timer is not None: +# try: +# self._sd_status_timer.cancel() +# except: +# pass +# elif 'Done saving file' in line: +# self.refreshSdFiles() +# elif 'File deleted' in line and line.strip().endswith("ok"): +# # buggy Marlin version that doesn't send a proper \r after the "File deleted" statement, fixed in +# # current versions +# self._clear_to_send.set() ##~~ Message handling elif line.strip() != '' \ From 3f61ebc29e8978c18063933b996c55ac8720fb3d Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 11:53:20 +0200 Subject: [PATCH 20/35] removed debugging output handling --- src/octoprint/util/comm_acc.py | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ad11c3c8..bb73a048 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -978,32 +978,32 @@ class MachineCom(object): if line.strip() is not "": self._timeout = get_new_timeout("communication") - ##~~ debugging output handling - if line.startswith("//"): - debugging_output = line[2:].strip() - if debugging_output.startswith("action:"): - action_command = debugging_output[len("action:"):].strip() - - if action_command == "pause": - self._log("Pausing on request of the printer...") - self.setPause(True) - elif action_command == "resume": - self._log("Resuming on request of the printer...") - self.setPause(False) - elif action_command == "disconnect": - self._log("Disconnecting on request of the printer...") - self._callback.on_comm_force_disconnect() - else: - for hook in self._printer_action_hooks: - self._printer_action_hooks[hook](self, line, action_command) - else: - continue + # ##~~ debugging output handling + # if line.startswith("//"): + # debugging_output = line[2:].strip() + # if debugging_output.startswith("action:"): + # action_command = debugging_output[len("action:"):].strip() + # + # if action_command == "pause": + # self._log("Pausing on request of the printer...") + # self.setPause(True) + # elif action_command == "resume": + # self._log("Resuming on request of the printer...") + # self.setPause(False) + # elif action_command == "disconnect": + # self._log("Disconnecting on request of the printer...") + # self._callback.on_comm_force_disconnect() + # else: + # for hook in self._printer_action_hooks: + # self._printer_action_hooks[hook](self, line, action_command) + # else: + # continue ##~~ Error handling #line = self._handleErrors(line) # GRBL Position update - if self._grbl : + if self._grbl: if(self._state == self.STATE_HOMING and 'ok' in line): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); From a61245a8b4ccbad31c0fe9d9b6de020f6ca9b1fc Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 16:54:59 +0200 Subject: [PATCH 21/35] a lot of changes in _monitor trying to reduce computational effort --- src/octoprint/util/comm_acc.py | 177 ++++++++++++++++----------------- 1 file changed, 88 insertions(+), 89 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index bb73a048..ab0c1a30 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1008,68 +1008,69 @@ class MachineCom(object): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); - # TODO check if "Alarm" is enough - if("Alarm lock" in line): - self._changeState(self.STATE_LOCKED) + #if 'MPos:' in line: + # # check movement + # if grblLastStatus == line: + # grblMoving = False + # else: + # grblMoving = True + # grblLastStatus = line + # self._update_grbl_pos(line) + + # TODO maybe better in _gcode_X_sent ... + if("Idle" in line and (self._state == self.STATE_LOCKED)): + self._changeState(self.STATE_OPERATIONAL) + + ## TODO check if "Alarm" is enough + #if("Alarm lock" in line): + # self._changeState(self.STATE_LOCKED) if("['$H'|'$X' to unlock]" in line): self._changeState(self.STATE_LOCKED) - # TODO maybe better in _gcode_X_sent ... - if("Idle" in line and (self._state == self.STATE_LOCKED) ): - self._changeState(self.STATE_OPERATIONAL) - - # TODO highly experimental. needs testing. - if("Hold" in line and self._state == self.STATE_PRINTING): - self._changeState(self.STATE_PAUSED) + ## TODO highly experimental. needs testing. + #if("Hold" in line and self._state == self.STATE_PRINTING): + # self._changeState(self.STATE_PAUSED) #if("Run" in line and self._state == self.STATE_PAUSED): # self._changeState(self.STATE_PRINTING) - if 'MPos:' in line: - # check movement - if grblLastStatus == line: - grblMoving = False - else: - grblMoving = True - grblLastStatus = line - self._update_grbl_pos(line) - if("ALARM: Hard/soft limit" in line): - errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" - self._log(errorMsg) - self._errorValue = errorMsg - eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) - self._openSerial() - self._changeState(self.STATE_CONNECTING) + #if("ALARM: Hard/soft limit" in line): + # errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" + # self._log(errorMsg) + # self._errorValue = errorMsg + # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + # eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) + # self._openSerial() + # self._changeState(self.STATE_CONNECTING) - if("Invalid gcode" in line and self._state == self.STATE_PRINTING): - # TODO Pause machine instead of resetting it. - errorMsg = line - self._log(errorMsg) - self._errorValue = errorMsg -# self._changeState(self.STATE_ERROR) - eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - self._openSerial() - self._changeState(self.STATE_CONNECTING) + #if("Invalid gcode" in line and self._state == self.STATE_PRINTING): + # # TODO Pause machine instead of resetting it. + # errorMsg = line + # self._log(errorMsg) + # self._errorValue = errorMsg +# # self._changeState(self.STATE_ERROR) + # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + # self._openSerial() + # self._changeState(self.STATE_CONNECTING) - if("Grbl" in line and self._state == self.STATE_PRINTING): - errorMsg = "Machine reset." - self._log(errorMsg) - self._errorValue = errorMsg - self._changeState(self.STATE_LOCKED) - eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + #if("Grbl" in line and self._state == self.STATE_PRINTING): + # errorMsg = "Machine reset." + # self._log(errorMsg) + # self._errorValue = errorMsg + # self._changeState(self.STATE_LOCKED) + # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - if("Grbl" in line): - versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) - if(versionMatch): - versionDict = versionMatch.groupdict() - self._writeGrblVersionToFile(versionDict) - if self._compareGrblVersion(versionDict) is False: - self._flashGrbl() + #if("Grbl" in line): + # versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) + # if(versionMatch): + # versionDict = versionMatch.groupdict() + # self._writeGrblVersionToFile(versionDict) + # if self._compareGrblVersion(versionDict) is False: + # self._flashGrbl() - if("error:" in line): - self.handle_grbl_error(line) + #if("error:" in line): + # self.handle_grbl_error(line) # ##~~ SD file list # # if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing @@ -1239,16 +1240,44 @@ class MachineCom(object): feedback_errors.append("_all") ##~~ Parsing for pause triggers - if pause_triggers and not self.isStreaming(): - if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: - self.setPause(True) - elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: - self.setPause(False) - elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: - self.setPause(not self.isPaused()) + #if pause_triggers and not self.isStreaming(): + # if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: + # self.setPause(True) + # elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: + # self.setPause(False) + # elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: + # self.setPause(not self.isPaused()) - ### Baudrate detection - if self._state == self.STATE_DETECT_BAUDRATE: + ### Printing + if self._state == self.STATE_PRINTING: + if "ok" in line or (supportWait and "wait" in line): + # a wait while printing means our printer's buffer ran out, probably due to some ok getting + # swallowed, so we treat it the same as an ok here teo take up communication again + if self._resendSwallowNextOk: + self._resendSwallowNextOk = False + + elif self._resendDelta is not None: + self._resendNextCommand() + + else: + if self._sendFromQueue(): + pass + elif not self.isSdPrinting(): + self._sendNext() + + elif line.lower().startswith("resend") or line.lower().startswith("rs"): + self._handleResendRequest(line) + + elif line == "" and time.time() > self._timeout: + if not self._long_running_command: + self._log("Communication timeout during printing, forcing a line") + self._sendCommand("?") + self._clear_to_send.set() + else: + self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") + + ## Baudrate detection + elif self._state == self.STATE_DETECT_BAUDRATE: if line == '' or time.time() > self._timeout: if self._baudrateDetectRetry > 0: self._serial.timeout = detection_timeout @@ -1286,8 +1315,6 @@ class MachineCom(object): self._onConnected(self.STATE_LOCKED) self._clear_to_send.set() - - ### Connection attempt elif self._state == self.STATE_CONNECTING: #line = self.__readline() @@ -1314,34 +1341,6 @@ class MachineCom(object): # resend -> start resend procedure from requested line elif line.lower().startswith("resend") or line.lower().startswith("rs"): self._handleResendRequest(line) - - ### Printing - elif self._state == self.STATE_PRINTING: - if line == "" and time.time() > self._timeout: - if not self._long_running_command: - self._log("Communication timeout during printing, forcing a line") - self._sendCommand("?") - self._clear_to_send.set() - else: - self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") - - if "ok" in line or (supportWait and "wait" in line): - # a wait while printing means our printer's buffer ran out, probably due to some ok getting - # swallowed, so we treat it the same as an ok here teo take up communication again - if self._resendSwallowNextOk: - self._resendSwallowNextOk = False - - elif self._resendDelta is not None: - self._resendNextCommand() - - else: - if self._sendFromQueue(): - pass - elif not self.isSdPrinting(): - self._sendNext() - - elif line.lower().startswith("resend") or line.lower().startswith("rs"): - self._handleResendRequest(line) except: self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:") From 29a85fec96c979435e51b45c30efdb7d033af260 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:19:45 +0200 Subject: [PATCH 22/35] deactivated timeout reset --- src/octoprint/util/comm_acc.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ab0c1a30..139e5fa7 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -975,8 +975,8 @@ class MachineCom(object): line = self._readline() if line is None: break - if line.strip() is not "": - self._timeout = get_new_timeout("communication") + # if line.strip() is not "": + # self._timeout = get_new_timeout("communication") # ##~~ debugging output handling # if line.startswith("//"): @@ -1268,13 +1268,13 @@ class MachineCom(object): elif line.lower().startswith("resend") or line.lower().startswith("rs"): self._handleResendRequest(line) - elif line == "" and time.time() > self._timeout: - if not self._long_running_command: - self._log("Communication timeout during printing, forcing a line") - self._sendCommand("?") - self._clear_to_send.set() - else: - self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") + # elif line == "" and time.time() > self._timeout: + # if not self._long_running_command: + # self._log("Communication timeout during printing, forcing a line") + # self._sendCommand("?") + # self._clear_to_send.set() + # else: + # self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") ## Baudrate detection elif self._state == self.STATE_DETECT_BAUDRATE: @@ -1323,9 +1323,9 @@ class MachineCom(object): # self._clear_to_send.set() elif " self._timeout: - print("TIMEOUT_CLOSE") - self.close() + # elif time.time() > self._timeout: + # print("TIMEOUT_CLOSE") + # self.close() ### Operational elif self._state == self.STATE_OPERATIONAL or self._state == self.STATE_PAUSED: From 5ecc0a1e90e8bb84f578241f87f97ca82d3c1087 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:42:47 +0200 Subject: [PATCH 23/35] Revert "removed debugging output handling" This reverts commit 3f61ebc29e8978c18063933b996c55ac8720fb3d. --- src/octoprint/util/comm_acc.py | 42 +++++++++++++++++----------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 139e5fa7..f6b2f400 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -978,32 +978,32 @@ class MachineCom(object): # if line.strip() is not "": # self._timeout = get_new_timeout("communication") - # ##~~ debugging output handling - # if line.startswith("//"): - # debugging_output = line[2:].strip() - # if debugging_output.startswith("action:"): - # action_command = debugging_output[len("action:"):].strip() - # - # if action_command == "pause": - # self._log("Pausing on request of the printer...") - # self.setPause(True) - # elif action_command == "resume": - # self._log("Resuming on request of the printer...") - # self.setPause(False) - # elif action_command == "disconnect": - # self._log("Disconnecting on request of the printer...") - # self._callback.on_comm_force_disconnect() - # else: - # for hook in self._printer_action_hooks: - # self._printer_action_hooks[hook](self, line, action_command) - # else: - # continue + ##~~ debugging output handling + if line.startswith("//"): + debugging_output = line[2:].strip() + if debugging_output.startswith("action:"): + action_command = debugging_output[len("action:"):].strip() + + if action_command == "pause": + self._log("Pausing on request of the printer...") + self.setPause(True) + elif action_command == "resume": + self._log("Resuming on request of the printer...") + self.setPause(False) + elif action_command == "disconnect": + self._log("Disconnecting on request of the printer...") + self._callback.on_comm_force_disconnect() + else: + for hook in self._printer_action_hooks: + self._printer_action_hooks[hook](self, line, action_command) + else: + continue ##~~ Error handling #line = self._handleErrors(line) # GRBL Position update - if self._grbl: + if self._grbl : if(self._state == self.STATE_HOMING and 'ok' in line): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); From ad745e067b4aeafe7bcedf6360b1b20974fecefd Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:47:56 +0200 Subject: [PATCH 24/35] remove changes --- src/octoprint/util/comm_acc.py | 180 +++++++++++++++++---------------- 1 file changed, 91 insertions(+), 89 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index f6b2f400..ace2e3c9 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -975,8 +975,8 @@ class MachineCom(object): line = self._readline() if line is None: break - # if line.strip() is not "": - # self._timeout = get_new_timeout("communication") + if line.strip() is not "": + self._timeout = get_new_timeout("communication") ##~~ debugging output handling if line.startswith("//"): @@ -1008,69 +1008,68 @@ class MachineCom(object): self._changeState(self.STATE_OPERATIONAL) self._onHomingDone(); - #if 'MPos:' in line: - # # check movement - # if grblLastStatus == line: - # grblMoving = False - # else: - # grblMoving = True - # grblLastStatus = line - # self._update_grbl_pos(line) - - # TODO maybe better in _gcode_X_sent ... - if("Idle" in line and (self._state == self.STATE_LOCKED)): - self._changeState(self.STATE_OPERATIONAL) - - ## TODO check if "Alarm" is enough - #if("Alarm lock" in line): - # self._changeState(self.STATE_LOCKED) + # TODO check if "Alarm" is enough + if("Alarm lock" in line): + self._changeState(self.STATE_LOCKED) if("['$H'|'$X' to unlock]" in line): self._changeState(self.STATE_LOCKED) - ## TODO highly experimental. needs testing. - #if("Hold" in line and self._state == self.STATE_PRINTING): - # self._changeState(self.STATE_PAUSED) + # TODO maybe better in _gcode_X_sent ... + if("Idle" in line and (self._state == self.STATE_LOCKED) ): + self._changeState(self.STATE_OPERATIONAL) + + # TODO highly experimental. needs testing. + if("Hold" in line and self._state == self.STATE_PRINTING): + self._changeState(self.STATE_PAUSED) #if("Run" in line and self._state == self.STATE_PAUSED): # self._changeState(self.STATE_PRINTING) + if 'MPos:' in line: + # check movement + if grblLastStatus == line: + grblMoving = False + else: + grblMoving = True + grblLastStatus = line + self._update_grbl_pos(line) - #if("ALARM: Hard/soft limit" in line): - # errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" - # self._log(errorMsg) - # self._errorValue = errorMsg - # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - # eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) - # self._openSerial() - # self._changeState(self.STATE_CONNECTING) + if("ALARM: Hard/soft limit" in line): + errorMsg = "Machine Limit Hit. Please reset the machine and do a homing cycle" + self._log(errorMsg) + self._errorValue = errorMsg + eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + eventManager().fire(Events.LIMITS_HIT, {"error": self.getErrorString()}) + self._openSerial() + self._changeState(self.STATE_CONNECTING) - #if("Invalid gcode" in line and self._state == self.STATE_PRINTING): - # # TODO Pause machine instead of resetting it. - # errorMsg = line - # self._log(errorMsg) - # self._errorValue = errorMsg -# # self._changeState(self.STATE_ERROR) - # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - # self._openSerial() - # self._changeState(self.STATE_CONNECTING) + if("Invalid gcode" in line and self._state == self.STATE_PRINTING): + # TODO Pause machine instead of resetting it. + errorMsg = line + self._log(errorMsg) + self._errorValue = errorMsg +# self._changeState(self.STATE_ERROR) + eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + self._openSerial() + self._changeState(self.STATE_CONNECTING) - #if("Grbl" in line and self._state == self.STATE_PRINTING): - # errorMsg = "Machine reset." - # self._log(errorMsg) - # self._errorValue = errorMsg - # self._changeState(self.STATE_LOCKED) - # eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) + if("Grbl" in line and self._state == self.STATE_PRINTING): + errorMsg = "Machine reset." + self._log(errorMsg) + self._errorValue = errorMsg + self._changeState(self.STATE_LOCKED) + eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) - #if("Grbl" in line): - # versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) - # if(versionMatch): - # versionDict = versionMatch.groupdict() - # self._writeGrblVersionToFile(versionDict) - # if self._compareGrblVersion(versionDict) is False: - # self._flashGrbl() + if("Grbl" in line): + versionMatch = re.search("Grbl (?P.+?)(_(?P[0-9a-f]{7})(?P-dirty)?)? \[.+\]", line) + if(versionMatch): + versionDict = versionMatch.groupdict() + self._writeGrblVersionToFile(versionDict) + if self._compareGrblVersion(versionDict) is False: + self._flashGrbl() - #if("error:" in line): - # self.handle_grbl_error(line) + if("error:" in line): + self.handle_grbl_error(line) # ##~~ SD file list # # if we are currently receiving an sd file list, each line is just a filename, so just read it and abort processing @@ -1240,44 +1239,17 @@ class MachineCom(object): feedback_errors.append("_all") ##~~ Parsing for pause triggers - #if pause_triggers and not self.isStreaming(): - # if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: - # self.setPause(True) - # elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: - # self.setPause(False) - # elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: - # self.setPause(not self.isPaused()) - ### Printing - if self._state == self.STATE_PRINTING: - if "ok" in line or (supportWait and "wait" in line): - # a wait while printing means our printer's buffer ran out, probably due to some ok getting - # swallowed, so we treat it the same as an ok here teo take up communication again - if self._resendSwallowNextOk: - self._resendSwallowNextOk = False + if pause_triggers and not self.isStreaming(): + if "enable" in pause_triggers.keys() and pause_triggers["enable"].search(line) is not None: + self.setPause(True) + elif "disable" in pause_triggers.keys() and pause_triggers["disable"].search(line) is not None: + self.setPause(False) + elif "toggle" in pause_triggers.keys() and pause_triggers["toggle"].search(line) is not None: + self.setPause(not self.isPaused()) - elif self._resendDelta is not None: - self._resendNextCommand() - - else: - if self._sendFromQueue(): - pass - elif not self.isSdPrinting(): - self._sendNext() - - elif line.lower().startswith("resend") or line.lower().startswith("rs"): - self._handleResendRequest(line) - - # elif line == "" and time.time() > self._timeout: - # if not self._long_running_command: - # self._log("Communication timeout during printing, forcing a line") - # self._sendCommand("?") - # self._clear_to_send.set() - # else: - # self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") - - ## Baudrate detection - elif self._state == self.STATE_DETECT_BAUDRATE: + ### Baudrate detection + if self._state == self.STATE_DETECT_BAUDRATE: if line == '' or time.time() > self._timeout: if self._baudrateDetectRetry > 0: self._serial.timeout = detection_timeout @@ -1315,6 +1287,8 @@ class MachineCom(object): self._onConnected(self.STATE_LOCKED) self._clear_to_send.set() + + ### Connection attempt elif self._state == self.STATE_CONNECTING: #line = self.__readline() @@ -1341,6 +1315,34 @@ class MachineCom(object): # resend -> start resend procedure from requested line elif line.lower().startswith("resend") or line.lower().startswith("rs"): self._handleResendRequest(line) + + ### Printing + elif self._state == self.STATE_PRINTING: + if line == "" and time.time() > self._timeout: + if not self._long_running_command: + self._log("Communication timeout during printing, forcing a line") + self._sendCommand("?") + self._clear_to_send.set() + else: + self._logger.debug("Ran into a communication timeout, but a command known to be a long runner is currently active") + + if "ok" in line or (supportWait and "wait" in line): + # a wait while printing means our printer's buffer ran out, probably due to some ok getting + # swallowed, so we treat it the same as an ok here teo take up communication again + if self._resendSwallowNextOk: + self._resendSwallowNextOk = False + + elif self._resendDelta is not None: + self._resendNextCommand() + + else: + if self._sendFromQueue(): + pass + elif not self.isSdPrinting(): + self._sendNext() + + elif line.lower().startswith("resend") or line.lower().startswith("rs"): + self._handleResendRequest(line) except: self._logger.exception("Something crashed inside the serial connection loop, please report this in OctoPrint's bug tracker:") From d5e4a5f4aef861cd3379ecf3350a6c77d4d42fd2 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 17:59:56 +0200 Subject: [PATCH 25/35] added disconnect special command and added yappi to profile while loop --- src/octoprint/util/comm_acc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ace2e3c9..e88efcf5 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -4,6 +4,9 @@ __author__ = "Gina Häußge based on work by David Braam" __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" +### DEBUGING START +import yappi +### DEBUG END import os import glob @@ -498,6 +501,8 @@ class MachineCom(object): self._temperature_timer = RepeatedTimer(frequency, self._poll_temperature, run_first=True) self._temperature_timer.start() + elif "disconnect" in specialcmd: + self.close() else: self._log("Command not Found! %s" % cmd) self._log("available commands are:") @@ -970,6 +975,8 @@ class MachineCom(object): self._sendCommand("?") self._clear_to_send.set() + yappi.start() + while self._monitoring_active: try: line = self._readline() @@ -1353,6 +1360,8 @@ class MachineCom(object): eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) self._log("Connection closed, closing down monitor") + yappi.get_func_stats().print_all() + def _process_registered_message(self, line, feedback_matcher, feedback_controls, feedback_errors): feedback_match = feedback_matcher.search(line) if feedback_match is None: From 23cab00b36beedf0e6df1eb71d038a43bd002803 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 18:21:18 +0200 Subject: [PATCH 26/35] yappi output to /tmp/yappi --- src/octoprint/util/comm_acc.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index e88efcf5..00956321 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1359,8 +1359,7 @@ class MachineCom(object): self._changeState(self.STATE_ERROR) eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) self._log("Connection closed, closing down monitor") - - yappi.get_func_stats().print_all() + yappi.get_func_stats().print_all(out=open("/tmp/yappi", 'w')) def _process_registered_message(self, line, feedback_matcher, feedback_controls, feedback_errors): feedback_match = feedback_matcher.search(line) From e4931acaa6c2b486371ede8667b0cc39e14021f6 Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 18:31:47 +0200 Subject: [PATCH 27/35] removed yappi --- src/octoprint/util/comm_acc.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 00956321..ca4f4954 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -4,10 +4,6 @@ __author__ = "Gina Häußge based on work by David Braam" __license__ = "GNU Affero General Public License http://www.gnu.org/licenses/agpl.html" __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" -### DEBUGING START -import yappi -### DEBUG END - import os import glob import time @@ -975,8 +971,6 @@ class MachineCom(object): self._sendCommand("?") self._clear_to_send.set() - yappi.start() - while self._monitoring_active: try: line = self._readline() @@ -1359,7 +1353,6 @@ class MachineCom(object): self._changeState(self.STATE_ERROR) eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) self._log("Connection closed, closing down monitor") - yappi.get_func_stats().print_all(out=open("/tmp/yappi", 'w')) def _process_registered_message(self, line, feedback_matcher, feedback_controls, feedback_errors): feedback_match = feedback_matcher.search(line) From 4793ec0e543b9439052b1b632035a72a5cef5e9c Mon Sep 17 00:00:00 2001 From: make-ing Date: Thu, 1 Oct 2015 18:46:13 +0200 Subject: [PATCH 28/35] added cProfile --- src/octoprint/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index 67baa4f7..8e9c4cca 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -3,6 +3,10 @@ import sys from octoprint.daemon import Daemon from octoprint.server import Server +### DEBUG START +import cProfile +### DEBUG END + #~~ version from ._version import get_versions @@ -81,4 +85,7 @@ def main(): octoprint.run() if __name__ == "__main__": - main() + ### DEBUG START + cProfile.run('main()', '/tmp/profilestats') + ### DEBUG END + #main() From adce7b877d027a1815d1569f8a6edeabbedb3891 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 09:50:10 +0200 Subject: [PATCH 29/35] removed cprofile --- src/octoprint/__init__.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/octoprint/__init__.py b/src/octoprint/__init__.py index 8e9c4cca..67baa4f7 100644 --- a/src/octoprint/__init__.py +++ b/src/octoprint/__init__.py @@ -3,10 +3,6 @@ import sys from octoprint.daemon import Daemon from octoprint.server import Server -### DEBUG START -import cProfile -### DEBUG END - #~~ version from ._version import get_versions @@ -85,7 +81,4 @@ def main(): octoprint.run() if __name__ == "__main__": - ### DEBUG START - cProfile.run('main()', '/tmp/profilestats') - ### DEBUG END - #main() + main() From 147034680d2efe2412f3a2b1211eab8b571fb447 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 10:40:10 +0200 Subject: [PATCH 30/35] added exception argument --- src/octoprint/util/comm_acc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index ca4f4954..abd308ce 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -428,13 +428,13 @@ class MachineCom(object): try: self._temperature_timer.cancel() self._temperature_timer = None - except: + except AttributeError: pass if self._sd_status_timer is not None: try: self._sd_status_timer.cancel() - except: + except AttributeError: pass self._monitoring_active = False From 8a9317d7426bef289c953bb641bc8ac917651466 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 11:31:55 +0200 Subject: [PATCH 31/35] changed sleep from 0.1sec to 0.001sec in _send_loop() --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index abd308ce..cf94ddd3 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1757,7 +1757,7 @@ class MachineCom(object): while self._send_queue_active: try: if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) < 20): - time.sleep(0.1) + time.sleep(0.001) continue # wait until we have something in the queue From 5b89302deb58d3296396069ccdea49114a0124d1 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 12:47:19 +0200 Subject: [PATCH 32/35] added stuff to resolve acc_line_length bug --- src/octoprint/util/comm_acc.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index cf94ddd3..2169d3b7 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1756,7 +1756,10 @@ class MachineCom(object): while self._send_queue_active: try: - if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) < 20): + peeked_entry = self._send_queue.peek() + p_command, p_linenbr, p_cmd_type = peeked_entry + + if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 10): time.sleep(0.001) continue @@ -2341,6 +2344,7 @@ class TypedQueue(queue.Queue): def __init__(self, maxsize=0): queue.Queue.__init__(self, maxsize=maxsize) self._lookup = [] + self._peekedItem = None; def _put(self, item): if isinstance(item, tuple) and len(item) == 3: @@ -2354,7 +2358,11 @@ class TypedQueue(queue.Queue): queue.Queue._put(self, item) def _get(self): - item = queue.Queue._get(self) + if self._peekedItem is None: + item = queue.Queue._get(self) + else: + item = self._peekedItem + self._peekedItem = None if isinstance(item, tuple) and len(item) == 3: cmd, line, cmd_type = item @@ -2363,6 +2371,10 @@ class TypedQueue(queue.Queue): return item + def peek(self): + if self._peekedItem is None: + self._peekedItem = self._get() + return self._peekedItem class TypeAlreadyInQueue(Exception): def __init__(self, t, *args, **kwargs): From 77499fb86858fa1c7103eee765d349d21b850510 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 12:54:21 +0200 Subject: [PATCH 33/35] changed acc remaining value from 10 to 5 character --- src/octoprint/util/comm_acc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 2169d3b7..4d89e9d3 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -1759,7 +1759,7 @@ class MachineCom(object): peeked_entry = self._send_queue.peek() p_command, p_linenbr, p_cmd_type = peeked_entry - if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 10): + if(self.RX_BUFFER_SIZE - sum(self.acc_line_lengths) - len(p_command) < 5): time.sleep(0.001) continue From 2449f9e327ca2f12e6bd348d558b5038f79415b8 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 16:40:49 +0200 Subject: [PATCH 34/35] changed standart position poll rate to 1sec and removed disabling during printing --- src/octoprint/util/comm_acc.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index 4d89e9d3..dcecbf03 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -256,19 +256,6 @@ class MachineCom(object): if self._state == newState: return - if newState == self.STATE_PRINTING: - if self._temperature_timer is not None: - self._temperature_timer.cancel() - self._temperature_timer = None - elif newState == self.STATE_OPERATIONAL: - if self._temperature_timer is not None: - self._temperature_timer.cancel() - self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) - self._temperature_timer.start() - else: - if self._temperature_timer is not None: - self._temperature_timer.cancel() - if newState == self.STATE_CLOSED or newState == self.STATE_CLOSED_WITH_ERROR: if settings().get(["feature", "sdSupport"]): self._sdFileList = False @@ -480,7 +467,7 @@ class MachineCom(object): specialcmd = cmd[1:].lower() if "togglestatusreport" in specialcmd: if self._temperature_timer is None: - self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) + self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) self._temperature_timer.start() else: self._temperature_timer.cancel() @@ -1416,7 +1403,7 @@ class MachineCom(object): #self._temperature_timer = RepeatedTimer(lambda: get_interval("temperature"), self._poll_temperature, run_first=True) if self._temperature_timer is not None: self._temperature_timer.cancel() - self._temperature_timer = RepeatedTimer(0.5, self._poll_temperature, run_first=True) + self._temperature_timer = RepeatedTimer(1, self._poll_temperature, run_first=True) self._temperature_timer.start() if(nextState == None): From 9d383f303eb90b0743f114cbe2da7622d90cd352 Mon Sep 17 00:00:00 2001 From: make-ing Date: Tue, 6 Oct 2015 18:46:00 +0200 Subject: [PATCH 35/35] added /disconnect to help message --- src/octoprint/util/comm_acc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/octoprint/util/comm_acc.py b/src/octoprint/util/comm_acc.py index dcecbf03..025a6f16 100644 --- a/src/octoprint/util/comm_acc.py +++ b/src/octoprint/util/comm_acc.py @@ -491,6 +491,7 @@ class MachineCom(object): self._log("available commands are:") self._log(" /togglestatusreport") self._log(" /setstatusfrequency ") + self._log(" /disconnect") return eepromCmd = re.search("^\$[0-9]+=.+$", cmd)