Skip to content

Commit

Permalink
✨ Use low latency flag on serial port
Browse files Browse the repository at this point in the history
Might improve serial performance.

Implements OctoPrint#4099
  • Loading branch information
foosel committed May 7, 2021
1 parent f69ab86 commit ae60033
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/octoprint/server/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def getSettings():
"port": connectionOptions["portPreference"],
"baudrate": connectionOptions["baudratePreference"],
"exclusive": s.getBoolean(["serial", "exclusive"]),
"lowLatency": s.getBoolean(["serial", "lowLatency"]),
"portOptions": connectionOptions["ports"],
"baudrateOptions": connectionOptions["baudrates"],
"autoconnect": s.getBoolean(["serial", "autoconnect"]),
Expand Down Expand Up @@ -657,6 +658,8 @@ def _saveSettings(data):
s.setInt(["serial", "baudrate"], data["serial"]["baudrate"])
if "exclusive" in data["serial"]:
s.setBoolean(["serial", "exclusive"], data["serial"]["exclusive"])
if "lowLatency" in data["serial"]:
s.setBoolean(["serial", "lowLatency"], data["serial"]["lowLatency"])
if "timeoutConnection" in data["serial"]:
s.setFloat(
["serial", "timeout", "connection"],
Expand Down
1 change: 1 addition & 0 deletions src/octoprint/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def settings(init=False, basedir=None, configfile=None, overlays=None):
"port": None,
"baudrate": None,
"exclusive": True,
"lowLatency": True,
"autoconnect": False,
"log": False,
"timeout": {
Expand Down
1 change: 1 addition & 0 deletions src/octoprint/static/js/app/viewmodels/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ $(function () {
self.serial_port = ko.observable();
self.serial_baudrate = ko.observable();
self.serial_exclusive = ko.observable();
self.serial_lowLatency = ko.observable();
self.serial_portOptions = ko.observableArray([]);
self.serial_baudrateOptions = ko.observableArray([]);
self.serial_autoconnect = ko.observable(undefined);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
</label>
</div>
</div>
<div class="control-group">
<div class="controls">
<label class="checkbox">
<input type="checkbox" data-bind="checked: serial_lowLatency" id="settings-serialLowLatency"> {{ _('Request low latency mode on the serial port') }}
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">{{ _('Apply parity double open workaround')}}</label>
<div class="controls">
Expand Down
14 changes: 14 additions & 0 deletions src/octoprint/util/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3685,6 +3685,20 @@ def default(_, p, b, timeout):
# noinspection PyProtectedMember
set_close_exec(serial_obj._port_handle)

if hasattr(serial_obj, "set_low_latency_mode"):
try:
serial_obj.set_low_latency_mode(
settings().getBoolean(["serial", "lowLatency"])
)
except Exception:
self._logger.exception(
"Could not set low latency mode on serial port, continuing without"
)
else:
self._logger.info(
"Platform doesn't support low latency mode on serial port"
)

return BufferedReadlineWrapper(serial_obj)

serial_factories = list(self._serial_factory_hooks.items()) + [
Expand Down

0 comments on commit ae60033

Please sign in to comment.