Two changes to try to achieve repetier firmware compatibility
- Read a "wait" as an empty line in order to send keep alive temperature updates - Added option to add a checksum to all commands. Needed to add current line tracking for this, let's hope that we'll never get out of synch here...master
parent
7e595b27ed
commit
8ef580cfd9
|
@ -359,7 +359,8 @@ def getSettings():
|
||||||
},
|
},
|
||||||
"feature": {
|
"feature": {
|
||||||
"gcodeViewer": s.getBoolean(["feature", "gCodeVisualizer"]),
|
"gcodeViewer": s.getBoolean(["feature", "gCodeVisualizer"]),
|
||||||
"waitForStart": s.getBoolean(["feature", "waitForStartOnConnect"])
|
"waitForStart": s.getBoolean(["feature", "waitForStartOnConnect"]),
|
||||||
|
"alwaysSendChecksum": s.getBoolean(["feature", "alwaysSendChecksum"])
|
||||||
},
|
},
|
||||||
"folder": {
|
"folder": {
|
||||||
"uploads": s.getBaseFolder("uploads"),
|
"uploads": s.getBaseFolder("uploads"),
|
||||||
|
@ -401,6 +402,7 @@ def setSettings():
|
||||||
if "feature" in data.keys():
|
if "feature" in data.keys():
|
||||||
if "gcodeViewer" in data["feature"].keys(): s.setBoolean(["feature", "gCodeVisualizer"], data["feature"]["gcodeViewer"])
|
if "gcodeViewer" in data["feature"].keys(): s.setBoolean(["feature", "gCodeVisualizer"], data["feature"]["gcodeViewer"])
|
||||||
if "waitForStart" in data["feature"].keys(): s.setBoolean(["feature", "waitForStartOnConnect"], data["feature"]["waitForStart"])
|
if "waitForStart" in data["feature"].keys(): s.setBoolean(["feature", "waitForStartOnConnect"], data["feature"]["waitForStart"])
|
||||||
|
if "alwaysSendChecksum" in data["feature"].keys(): s.setBoolean(["feature", "alwaysSendChecksum"], data["feature"]["alwaysSendChecksum"])
|
||||||
|
|
||||||
if "folder" in data.keys():
|
if "folder" in data.keys():
|
||||||
if "uploads" in data["folder"].keys(): s.setBaseFolder("uploads", data["folder"]["uploads"])
|
if "uploads" in data["folder"].keys(): s.setBaseFolder("uploads", data["folder"]["uploads"])
|
||||||
|
|
|
@ -39,7 +39,8 @@ default_settings = {
|
||||||
},
|
},
|
||||||
"feature": {
|
"feature": {
|
||||||
"gCodeVisualizer": True,
|
"gCodeVisualizer": True,
|
||||||
"waitForStartOnConnect": False
|
"waitForStartOnConnect": False,
|
||||||
|
"alwaysSendChecksum": False
|
||||||
},
|
},
|
||||||
"folder": {
|
"folder": {
|
||||||
"uploads": None,
|
"uploads": None,
|
||||||
|
|
|
@ -959,6 +959,7 @@ function SettingsViewModel() {
|
||||||
|
|
||||||
self.feature_gcodeViewer = ko.observable(undefined);
|
self.feature_gcodeViewer = ko.observable(undefined);
|
||||||
self.feature_waitForStart = ko.observable(undefined);
|
self.feature_waitForStart = ko.observable(undefined);
|
||||||
|
self.feature_alwaysSendChecksum = ko.observable(undefined);
|
||||||
|
|
||||||
self.folder_uploads = ko.observable(undefined);
|
self.folder_uploads = ko.observable(undefined);
|
||||||
self.folder_timelapse = ko.observable(undefined);
|
self.folder_timelapse = ko.observable(undefined);
|
||||||
|
@ -1003,6 +1004,7 @@ function SettingsViewModel() {
|
||||||
|
|
||||||
self.feature_gcodeViewer(response.feature.gcodeViewer);
|
self.feature_gcodeViewer(response.feature.gcodeViewer);
|
||||||
self.feature_waitForStart(response.feature.waitForStart);
|
self.feature_waitForStart(response.feature.waitForStart);
|
||||||
|
self.feature_alwaysSendChecksum(response.feature.alwaysSendChecksum);
|
||||||
|
|
||||||
self.folder_uploads(response.folder.uploads);
|
self.folder_uploads(response.folder.uploads);
|
||||||
self.folder_timelapse(response.folder.timelapse);
|
self.folder_timelapse(response.folder.timelapse);
|
||||||
|
@ -1035,7 +1037,8 @@ function SettingsViewModel() {
|
||||||
},
|
},
|
||||||
"feature": {
|
"feature": {
|
||||||
"gcodeViewer": self.feature_gcodeViewer(),
|
"gcodeViewer": self.feature_gcodeViewer(),
|
||||||
"waitForStart": self.feature_waitForStart()
|
"waitForStart": self.feature_waitForStart(),
|
||||||
|
"alwaysSendChecksum": self.feature_alwaysSendChecksum()
|
||||||
},
|
},
|
||||||
"folder": {
|
"folder": {
|
||||||
"uploads": self.folder_uploads(),
|
"uploads": self.folder_uploads(),
|
||||||
|
|
|
@ -106,6 +106,13 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="control-group">
|
||||||
|
<div class="controls">
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox" data-bind="checked: feature_alwaysSendChecksum" id="settings-featureAlwaysSendChecksum"> Send a checksum with <strong>every</strong> command
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="tab-pane" id="settings_folder">
|
<div class="tab-pane" id="settings_folder">
|
||||||
|
|
|
@ -174,7 +174,10 @@ class MachineCom(object):
|
||||||
self._heatupWaitStartTime = 0
|
self._heatupWaitStartTime = 0
|
||||||
self._heatupWaitTimeLost = 0.0
|
self._heatupWaitTimeLost = 0.0
|
||||||
self._printStartTime100 = None
|
self._printStartTime100 = None
|
||||||
|
|
||||||
|
self._alwaysSendChecksum = settings().getBoolean(["feature", "alwaysSendChecksum"])
|
||||||
|
self._currentLine = 0
|
||||||
|
|
||||||
self.thread = threading.Thread(target=self._monitor)
|
self.thread = threading.Thread(target=self._monitor)
|
||||||
self.thread.daemon = True
|
self.thread.daemon = True
|
||||||
self.thread.start()
|
self.thread.start()
|
||||||
|
@ -344,7 +347,7 @@ class MachineCom(object):
|
||||||
t = time.time()
|
t = time.time()
|
||||||
self._heatupWaitTimeLost = t - self._heatupWaitStartTime
|
self._heatupWaitTimeLost = t - self._heatupWaitStartTime
|
||||||
self._heatupWaitStartTime = t
|
self._heatupWaitStartTime = t
|
||||||
elif line.strip() != '' and line.strip() != 'ok' and not line.startswith('Resend:') and line != 'echo:Unknown command:""\n' and self.isOperational():
|
elif line.strip() != '' and line.strip() != 'ok' and not line.startswith("wait") and not line.startswith('Resend:') and line != 'echo:Unknown command:""\n' and self.isOperational():
|
||||||
self._callback.mcMessage(line)
|
self._callback.mcMessage(line)
|
||||||
|
|
||||||
if self._state == self.STATE_DETECT_BAUDRATE:
|
if self._state == self.STATE_DETECT_BAUDRATE:
|
||||||
|
@ -385,28 +388,28 @@ class MachineCom(object):
|
||||||
else:
|
else:
|
||||||
self._testingBaudrate = False
|
self._testingBaudrate = False
|
||||||
elif self._state == self.STATE_CONNECTING:
|
elif self._state == self.STATE_CONNECTING:
|
||||||
if line == '' and startSeen:
|
if (line == "" or "wait" in line) and startSeen:
|
||||||
self._sendCommand("M105")
|
self._sendCommand("M105")
|
||||||
elif 'start' in line:
|
elif "start" in line:
|
||||||
startSeen = True
|
startSeen = True
|
||||||
elif 'ok' in line and startSeen:
|
elif "ok" in line and startSeen:
|
||||||
self._changeState(self.STATE_OPERATIONAL)
|
self._changeState(self.STATE_OPERATIONAL)
|
||||||
elif time.time() > timeout:
|
elif time.time() > timeout:
|
||||||
self.close()
|
self.close()
|
||||||
elif self._state == self.STATE_OPERATIONAL or self._state == self.STATE_PAUSED:
|
elif self._state == self.STATE_OPERATIONAL or self._state == self.STATE_PAUSED:
|
||||||
#Request the temperature on comm timeout (every 5 seconds) when we are not printing.
|
#Request the temperature on comm timeout (every 5 seconds) when we are not printing.
|
||||||
if line == '':
|
if line == "" or "wait" in line:
|
||||||
self._sendCommand("M105")
|
self._sendCommand("M105")
|
||||||
tempRequestTimeout = time.time() + 5
|
tempRequestTimeout = time.time() + 5
|
||||||
elif self._state == self.STATE_PRINTING:
|
elif self._state == self.STATE_PRINTING:
|
||||||
if line == '' and time.time() > timeout:
|
if line == "" and time.time() > timeout:
|
||||||
self._log("Communication timeout during printing, forcing a line")
|
self._log("Communication timeout during printing, forcing a line")
|
||||||
line = 'ok'
|
line = "ok"
|
||||||
#Even when printing request the temperture every 5 seconds.
|
#Even when printing request the temperture every 5 seconds.
|
||||||
if time.time() > tempRequestTimeout:
|
if time.time() > tempRequestTimeout:
|
||||||
self._commandQueue.put("M105")
|
self._commandQueue.put("M105")
|
||||||
tempRequestTimeout = time.time() + 5
|
tempRequestTimeout = time.time() + 5
|
||||||
if 'ok' in line:
|
if "ok" in line:
|
||||||
timeout = time.time() + 5
|
timeout = time.time() + 5
|
||||||
if not self._commandQueue.empty():
|
if not self._commandQueue.empty():
|
||||||
self._sendCommand(self._commandQueue.get())
|
self._sendCommand(self._commandQueue.get())
|
||||||
|
@ -460,7 +463,7 @@ class MachineCom(object):
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def _sendCommand(self, cmd):
|
def _sendCommand(self, cmd, sendChecksum=False):
|
||||||
cmd = cmd.upper()
|
cmd = cmd.upper()
|
||||||
if self._serial is None:
|
if self._serial is None:
|
||||||
return
|
return
|
||||||
|
@ -476,13 +479,23 @@ class MachineCom(object):
|
||||||
self._bedTargetTemp = float(re.search('S([0-9]+)', cmd).group(1))
|
self._bedTargetTemp = float(re.search('S([0-9]+)', cmd).group(1))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
self._log('Send: %s' % (cmd))
|
|
||||||
|
commandToSend = cmd
|
||||||
|
self._currentLine += 1
|
||||||
|
if sendChecksum or self._alwaysSendChecksum:
|
||||||
|
lineNumber = self._gcodePos
|
||||||
|
if self._alwaysSendChecksum:
|
||||||
|
lineNumber = self._currentLine
|
||||||
|
checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (lineNumber, cmd)))
|
||||||
|
commandToSend = "N%d%s*%d" % (lineNumber, cmd, checksum)
|
||||||
|
|
||||||
|
self._log('Send: %s' % (commandToSend))
|
||||||
try:
|
try:
|
||||||
self._serial.write(cmd + '\n')
|
self._serial.write(commandToSend + '\n')
|
||||||
except serial.SerialTimeoutException:
|
except serial.SerialTimeoutException:
|
||||||
self._log("Serial timeout while writing to serial port, trying again.")
|
self._log("Serial timeout while writing to serial port, trying again.")
|
||||||
try:
|
try:
|
||||||
self._serial.write(cmd + '\n')
|
self._serial.write(commandToSend + '\n')
|
||||||
except:
|
except:
|
||||||
self._log("Unexpected error while writing serial port: %s" % (getExceptionString()))
|
self._log("Unexpected error while writing serial port: %s" % (getExceptionString()))
|
||||||
self._errorValue = getExceptionString()
|
self._errorValue = getExceptionString()
|
||||||
|
@ -491,7 +504,16 @@ class MachineCom(object):
|
||||||
self._log("Unexpected error while writing serial port: %s" % (getExceptionString()))
|
self._log("Unexpected error while writing serial port: %s" % (getExceptionString()))
|
||||||
self._errorValue = getExceptionString()
|
self._errorValue = getExceptionString()
|
||||||
self.close(True)
|
self.close(True)
|
||||||
|
finally:
|
||||||
|
if "M110" in cmd:
|
||||||
|
if " N" in cmd:
|
||||||
|
try:
|
||||||
|
self._currentLine = int(re.search("N([0-9]+)", cmd).group(1))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self._currentLine = 0
|
||||||
|
|
||||||
def _sendNext(self):
|
def _sendNext(self):
|
||||||
if self._gcodePos >= len(self._gcodeList):
|
if self._gcodePos >= len(self._gcodeList):
|
||||||
self._changeState(self.STATE_OPERATIONAL)
|
self._changeState(self.STATE_OPERATIONAL)
|
||||||
|
@ -515,8 +537,7 @@ class MachineCom(object):
|
||||||
self._callback.mcZChange(z)
|
self._callback.mcZChange(z)
|
||||||
except:
|
except:
|
||||||
self._log("Unexpected error: %s" % (getExceptionString()))
|
self._log("Unexpected error: %s" % (getExceptionString()))
|
||||||
checksum = reduce(lambda x,y:x^y, map(ord, "N%d%s" % (self._gcodePos, line)))
|
self._sendCommand(line, True)
|
||||||
self._sendCommand("N%d%s*%d" % (self._gcodePos, line, checksum))
|
|
||||||
self._gcodePos += 1
|
self._gcodePos += 1
|
||||||
self._callback.mcProgress(self._gcodePos)
|
self._callback.mcProgress(self._gcodePos)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue