Skip to content

Commit

Permalink
fix gcode serialization
Browse files Browse the repository at this point in the history
fixes #14
  • Loading branch information
Kriechi committed Aug 10, 2018
1 parent cbc0624 commit ecba95c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 41 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
44 changes: 12 additions & 32 deletions DuetRRFOutputDevice.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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...")
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -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\<username>\AppData\Roaming\cura\3.3\plugins\Cura-DuetRRFPlugin`
`C:\Users\<username>\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/<username>/.local/share/cura/3.3/plugins/Cura-DuetRRFPlugin`
`/home/<username>/.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
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit ecba95c

Please sign in to comment.