From f2192ba232bc0d54a19880682f1bb3011b857a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 29 May 2015 11:36:36 +0200 Subject: [PATCH] Fix: Re-open detected serial port with specified baudrate The serial port was previously kept open from the Stk500 initialization, which defaults to 115200 baud. Closes #892 --- CHANGELOG.md | 46 +++++++++++++++++++++----------------- src/octoprint/util/comm.py | 23 ++++++++++--------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 220ac380..8441f068 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ search * You can now define a folder (default: `~/.octoprint/watched`) to be watched for newly added GCODE (or -- if slicing support is enabled -- STL) files to automatically add. -* OctoPrint now has a [plugin system](http://docs.octoprint.org/en/devel/plugins/index.html) which allows extending its +* OctoPrint now has a [plugin system](http://docs.octoprint.org/en/devel/plugins/index.html) which allows extending its core functionality. * New type of API key: [App Session Keys](http://docs.octoprint.org/en/devel/api/apps.html) for trusted applications * Printer Profiles: Printer properties like print volume, extruder offsets etc are now managed via Printer Profiles. A @@ -49,18 +49,18 @@ * Start counting the layers at 1 instead of 0 in the GCODE viewer * Upgraded [Font Awesome](https://fortawesome.github.io/Font-Awesome/) to version 3.2.1 * Better error reporting for timelapse rendering and system commands -* Custom control can now be defined so that they show a Confirm dialog with configurable text before executing +* Custom control can now be defined so that they show a Confirm dialog with configurable text before executing ([#532](https://github.com/foosel/OctoPrint/issues/532) and [#590](https://github.com/foosel/OctoPrint/pull/590)) * Slicing has been greatly improved: - * It now allows for a definition of slicing profiles to use for slicing plus overrides which can be defined per slicing + * It now allows for a definition of slicing profiles to use for slicing plus overrides which can be defined per slicing job (defining overrides is not yet part of the UI but it's on the roadmap). * A new slicing dialog has been added which allows (re-)slicing uploaded STL files (which are now displayed in the file list as well). This dialog also allows specifying which action to take after slicing has been completed (none, selecting the sliced GCODE for printing or starting to print it directly) - * Slicers themselves are integrated into the system via ``SlicingPlugins``. - * The [Cura integration](https://github.com/daid/Cura) has changed in such a way that OctoPrint now calls the - [CuraEngine](https://github.com/Ultimaker/CuraEngine) directly instead of depending on the full Cura installation. See - [the wiki](https://github.com/foosel/OctoPrint/wiki/Plugin:-Cura) for instructions on how to change your setup to + * Slicers themselves are integrated into the system via ``SlicingPlugins``. + * The [Cura integration](https://github.com/daid/Cura) has changed in such a way that OctoPrint now calls the + [CuraEngine](https://github.com/Ultimaker/CuraEngine) directly instead of depending on the full Cura installation. See + [the wiki](https://github.com/foosel/OctoPrint/wiki/Plugin:-Cura) for instructions on how to change your setup to accommodate the new integration. * The "Slicing done" notification is now colored green ([#558](https://github.com/foosel/OctoPrint/issues/558)). * The slicing API allows positioning the model to slice on the print bed (Note: this is not yet available in the UI). @@ -111,15 +111,15 @@ NTP server on a Raspberry Pi image. Achieved through monkey patching Tornado with [this PR](https://github.com/tornadoweb/tornado/pull/1290). * Serial ports matching ``/dev/ttyAMA*`` are not anymore listed by default (this was the reason for a lot of people - running into problems while attempting to connect to their printer on their Raspberry Pis, on which ``/dev/ttyAMA0`` - is the OS's serial console by default). Added configuration of additional ports to the Serial Connection section in + running into problems while attempting to connect to their printer on their Raspberry Pis, on which ``/dev/ttyAMA0`` + is the OS's serial console by default). Added configuration of additional ports to the Serial Connection section in the Settings to make it easier for those people who do indeed have their printer connected to ``/dev/ttyAMA0``. -* Better behaviour of the settings dialog on low-width devices, navigation and content also now scroll independently +* Better behaviour of the settings dialog on low-width devices, navigation and content also now scroll independently from each other (see also [#823](https://github.com/foosel/OctoPrint/pull/823)) * Renamed "Temperature Timeout" and "SD Status Timeout" in Settings to "Temperature Interval" and "SD Status Interval" to better reflect what those values are actually used for. * Better behaviour of the settings dialog on mobile devices. -* Added support for rectangular printer beds with the origin in the center ([#682](https://github.com/foosel/OctoPrint/issues/682) +* Added support for rectangular printer beds with the origin in the center ([#682](https://github.com/foosel/OctoPrint/issues/682) and [#852](https://github.com/foosel/OctoPrint/pull/852)). Printer profiles now contain a new settings ``volume.origin`` which can either be ``lowerleft`` or ``center``. For circular beds only ``center`` is supported. * Made baudrate detection a bit more solid, still can't perform wonders. @@ -129,13 +129,15 @@ data points. Anything older than ``n`` minutes will be cut off, with ``n`` defaulting to 30min. This value can be changed under "Temperatures" in the Settings ([#343](https://github.com/foosel/OctoPrint/issues/343)). * High-DPI support for the GCode viewer ([#837](https://github.com/foosel/OctoPrint/issues/837)). -* Stop websocket connections from multiplying([#888](https://github.com/foosel/OctoPrint/pull/888)). +* Stop websocket connections from multiplying ([#888](https://github.com/foosel/OctoPrint/pull/888)). +* New setting to rotate webcam by 90° counter clockwise ([#895](https://github.com/foosel/OctoPrint/issues/895) and + [#906](https://github.com/foosel/OctoPrint/pull/906)) ### Bug Fixes * [#435](https://github.com/foosel/OctoPrint/issues/435) - Always interpret negative duration (e.g. for print time left) as 0 -* [#633](https://github.com/foosel/OctoPrint/issues/633) - Correctly interpret temperature lines from multi extruder +* [#633](https://github.com/foosel/OctoPrint/issues/633) - Correctly interpret temperature lines from multi extruder setups under Smoothieware * [#556](https://github.com/foosel/OctoPrint/issues/556) - Allow login of the same user from multiple browsers without side effects @@ -183,6 +185,8 @@ * [#809](https://github.com/foosel/OctoPrint/issues/809) - Added proper form validation to printer profile editor * [#824](https://github.com/foosel/OctoPrint/issues/824) - Settings getting lost when switching between panes in the settings dialog (fix provided by [#879](https://github.com/foosel/OctoPrint/pull/879)) + * [#892](https://github.com/foosel/OctoPrint/issues/892) - Preselected baudrate is now properly used for auto detected + serial ports * [#909](https://github.com/foosel/OctoPrint/issues/909) - Fixed Z-Timelapse for Z changes on ``G1`` moves. * Various fixes without tickets: * GCODE viewer now doesn't stumble over completely extrusionless GCODE files @@ -196,8 +200,8 @@ * Fixed handling of SD card files in folders * Fixed refreshing of timelapse file list upon finished rendering of a new one * Fixed ``/api/printer`` which wasn't adapter yet to new internal offset data model - * Made initial connection to printer a bit more responsive: Having to wait for the first serial timeout before sending - the first ``M105`` even when not waiting for seeing a "start" caused unnecessary wait times for reaching the + * Made initial connection to printer a bit more responsive: Having to wait for the first serial timeout before sending + the first ``M105`` even when not waiting for seeing a "start" caused unnecessary wait times for reaching the "Operational" state. * Log cancelled prints only once (thanks to @imrahil for the headsup) @@ -207,10 +211,10 @@ ### Bug Fixes -* Fixed another instance of a missing `branch` fields in version dicts generated by versioneer (compare +* Fixed another instance of a missing `branch` fields in version dicts generated by versioneer (compare [#634](https://github.com/foosel/OctoPrint/pull/634)). Caused an issue when installing from source archive downloaded from Github. - + ([Commits](https://github.com/foosel/OctoPrint/compare/1.1.2...master)) ## 1.1.2 (2015-03-23) @@ -273,7 +277,7 @@ ### New Features -* New REST API, including User API Keys additionally to the global API key. Please note that **this will break existing +* New REST API, including User API Keys additionally to the global API key. Please note that **this will break existing API clients** as it replaces the old API (same endpoint). You can find the documentation of the new API at [docs.octoprint.org](http://docs.octoprint.org/en/1.1.0/api/index.html). * New Event structure allows more flexibility regarding payload data, configuration files will be migrated automatically. @@ -298,9 +302,9 @@ * The dimensions of the print bed can now be configured via the Settings ([#396](https://github.com/foosel/OctoPrint/pull/396)) * Target temperature reporting format of Repetier Firmware is now supported as well ([360](https://github.com/foosel/OctoPrint/issues/360)) * Version tracking now based on git tagging and [versioneer](https://github.com/warner/python-versioneer/). Version number, - git commit and branch get reported in the format `--g ( branch)`, + git commit and branch get reported in the format `--g ( branch)`, e.g. `1.2.0-dev-172-ga48b5de (devel branch)`. -* Made "Center viewport on model" and "Zoom in on model" in the GCODE viewer automatically deselect and de-apply if +* Made "Center viewport on model" and "Zoom in on model" in the GCODE viewer automatically deselect and de-apply if viewport gets manipulated by the user ([#398](https://github.com/foosel/OctoPrint/issues/398)) * GCODE viewer now interprets inverted axes for printer control and mirrors print bed accordingly ([#431](https://github.com/foosel/OctoPrint/issues/431)) * Added `clean` command to `setup.py`, removes old build artifacts (mostly interesting for developers) @@ -319,7 +323,7 @@ * [#381](https://github.com/foosel/OctoPrint/issues/381) - Only list those SD files that have an ASCII filename * Fixed a race condition that could occur when pressing "Print" (File not opened yet, but attempt to read from it) * [#398](https://github.com/foosel/OctoPrint/issues/398) - Fixed interfering options in GCODE viewer -* [#399](https://github.com/foosel/OctoPrint/issues/399) & [360](https://github.com/foosel/OctoPrint/issues/360) - Leave +* [#399](https://github.com/foosel/OctoPrint/issues/399) & [360](https://github.com/foosel/OctoPrint/issues/360) - Leave bed temperature unset when not detected (instead of dying a horrible death) * [#492](https://github.com/foosel/OctoPrint/issues/492) - Fixed a race condition which could lead to an attempt to read from an already closed serial port, causing an error to be displayed to the user diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 9148c863..2f8e0813 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -1239,7 +1239,7 @@ class MachineCom(object): if port is None or port == 'AUTO': # no known port, try auto detection self._changeState(self.STATE_DETECT_SERIAL) - serial_obj = self._detectPort(False) + serial_obj = self._detectPort(True) if serial_obj is None: self._log("Failed to autodetect serial port") self._errorValue = 'Failed to autodetect serial port.' @@ -1247,17 +1247,18 @@ class MachineCom(object): eventManager().fire(Events.ERROR, {"error": self.getErrorString()}) return None + port = serial_obj.port + + # connect to regular serial port + self._log("Connecting to: %s" % port) + if baudrate == 0: + baudrates = baudrateList() + serial_obj = serial.Serial(str(port), 115200 if 115200 in baudrates else baudrates[0], timeout=read_timeout, writeTimeout=10000, parity=serial.PARITY_ODD) else: - # connect to regular serial port - self._log("Connecting to: %s" % port) - if baudrate == 0: - baudrates = baudrateList() - serial_obj = serial.Serial(str(port), 115200 if 115200 in baudrates else baudrates[0], timeout=read_timeout, writeTimeout=10000, parity=serial.PARITY_ODD) - else: - serial_obj = serial.Serial(str(port), baudrate, timeout=read_timeout, writeTimeout=10000, parity=serial.PARITY_ODD) - serial_obj.close() - serial_obj.parity = serial.PARITY_NONE - serial_obj.open() + serial_obj = serial.Serial(str(port), baudrate, timeout=read_timeout, writeTimeout=10000, parity=serial.PARITY_ODD) + serial_obj.close() + serial_obj.parity = serial.PARITY_NONE + serial_obj.open() return serial_obj