From ecba95c3f3e71f5d9387a2d9a192606ba21fba64 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Fri, 10 Aug 2018 21:38:45 +0200 Subject: [PATCH] fix gcode serialization fixes #14 --- CHANGELOG.md | 4 ++++ DuetRRFOutputDevice.py | 44 ++++++++++++------------------------------ README.md | 14 +++++++------- plugin.json | 4 ++-- 4 files changed, 25 insertions(+), 41 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1aaa98..e9b0a77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog of Cura-DuetRRFPlugin +## v0.0.17: 2018-08-10 + * fix missing settings at the end of the gcode file + * make use of the default GCodeWrite that Cura uses for "Save to File" + ## v0.0.16: 2018-04-11 * improve simulation mode diff --git a/DuetRRFOutputDevice.py b/DuetRRFOutputDevice.py index f856e73..b055a13 100644 --- a/DuetRRFOutputDevice.py +++ b/DuetRRFOutputDevice.py @@ -1,10 +1,11 @@ import os.path -from io import StringIO -from time import time, sleep import datetime import base64 import urllib import json +from io import StringIO +from time import time, sleep +from typing import cast from PyQt5 import QtNetwork from PyQt5.QtCore import QFile, QUrl, QObject, QCoreApplication, QByteArray, QTimer, pyqtProperty, pyqtSignal, pyqtSlot @@ -14,6 +15,8 @@ from UM.Application import Application from UM.Logger import Logger from UM.Message import Message +from UM.Mesh.MeshWriter import MeshWriter +from UM.PluginRegistry import PluginRegistry from UM.OutputDevice.OutputDevice import OutputDevice from UM.OutputDevice import OutputDeviceError @@ -152,36 +155,13 @@ def onFilenameAccepted(self): Logger.log("d", self._name_id + " | Loading gcode...") - # find the G-code for the active build plate to print - version = Application.getInstance().getVersion() - Logger.log("d", "Found Cura %s" % version) - if version.startswith('3.0') or version.startswith('3.1'): - # Cura 3.0 and 3.1 - gcode = getattr(Application.getInstance().getController().getScene(), "gcode_list") - else: - if version.startswith('3.2'): - # Cura 3.2 - active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate - else: - # Cura 3.3 and later - active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate - - gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict") - gcode = gcode_dict[active_build_plate_id] - - lines = len(gcode) - Logger.log("d", "Found %s lines of gcode." % lines) - - # send all the gcode to self._stream - nextYield = time() + 0.05 - i = 0 - for line in gcode: - i += 1 - self._stream.write(line) - if time() > nextYield: - self._onProgress(i / lines) - QCoreApplication.processEvents() - nextYield = time() + 0.05 + # get the g-code through the GCodeWrite plugin + # this serializes the actual scene and should produce the same output as "Save to File" + gcode_writer = cast(MeshWriter, PluginRegistry.getInstance().getPluginObject("GCodeWriter")) + success = gcode_writer.write(self._stream, None) + if not success: + Logger.log("e", "GCodeWrite failed.") + return # start Logger.log("d", self._name_id + " | Connecting...") diff --git a/README.md b/README.md index adab44c..a88774f 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,25 @@ # Cura-DuetRRFPlugin -Plugin for Cura 3 that adds output devices for a Duet RepRapFirmware printer: "Print", "Simulate", and "Upload". +Plugin for Cura 3.4 that adds output devices for a Duet RepRapFirmware printer: "Print", "Simulate", and "Upload". ## Installation With Cura not running, unpack the zip file from the [release](https://github.com/Kriechi/Cura-DuetRRFPlugin/releases/latest) to this specific folder: ### Windows -`C:\Users\\AppData\Roaming\cura\3.3\plugins\Cura-DuetRRFPlugin` +`C:\Users\\AppData\Roaming\cura\3.4\plugins\Cura-DuetRRFPlugin` ### Mac -`~/Library/Application Support/Cura/3.3/plugins/Cura-DuetRRFPlugin` +`~/Library/Application Support/Cura/3.4/plugins/Cura-DuetRRFPlugin` ### Linux -`/home//.local/share/cura/3.3/plugins/Cura-DuetRRFPlugin` +`/home//.local/share/cura/3.4/plugins/Cura-DuetRRFPlugin` Be careful, the unzipper often tacks on the name of the zip as a folder at the bottom and you don't want it nested. You want the files to show up in that -folder. +folder. -Make sure that the plugin folder name is a listed above and it does not have -any trailing version numbers (`-0.0.16`) or similar. +Make sure that the plugin folder name is a listed above and it does not have +any trailing version numbers (`-0.0.17`) or similar. ## Running from source Alternatively you can run from the source directly. It'll make it easy to diff --git a/plugin.json b/plugin.json index 4941543..a7cc0e7 100644 --- a/plugin.json +++ b/plugin.json @@ -1,7 +1,7 @@ { "name": "DuetRRF", "author": "Thomas Kriechbaumer", - "description": "Provides direct upload of gcode to DuetRRF.", - "version": "0.0.16", + "description": "Upload and Print to DuetWifi / DuetEthernet / Duet Maestro with RepRapFirmware.", + "version": "0.0.17", "api": 4 }