From 2206b84f3e7d062d2d75216faec08df6e99968f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 4 Jun 2020 18:58:09 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20hook=20to=20extend=20serial?= =?UTF-8?q?=20port=20names?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/plugins/hooks.rst | 19 +++++++++++++++++++ src/octoprint/util/comm.py | 7 +++++++ 2 files changed, 26 insertions(+) diff --git a/docs/plugins/hooks.rst b/docs/plugins/hooks.rst index 3f1a44ac0..506d025ef 100644 --- a/docs/plugins/hooks.rst +++ b/docs/plugins/hooks.rst @@ -890,6 +890,25 @@ octoprint.comm.protocol.temperatures.received :tab-width: 4 :caption: `sanitize_temperatures.py `_ +.. _sec-plugins-hook-comm-transport-serial-additonal-port-names: + +octoprint.comm.transport.serial.additional_port_names +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. py:function:: additional_port_names_hook(candidates, *args, **kwargs) + + Return additional port names (not glob patterns!) to use as a serial connection to the printer. Expected to be + ``list`` of ``string``s. + + Useful in combination with :ref:`octoprint.comm.transport.serial.factory ` + to implement custom serial-like ports through plugins. + + For an example of use see the bundled ``virtual_printer`` plugin. + + :param list candidates: The port names already found on the system available for connection. + :return: Additional port names to offer up for connection. + :rtype: list + .. _sec-plugins-hook-comm-transport-serial-factory: octoprint.comm.transport.serial.factory diff --git a/src/octoprint/util/comm.py b/src/octoprint/util/comm.py index 56296d771..0bc162533 100644 --- a/src/octoprint/util/comm.py +++ b/src/octoprint/util/comm.py @@ -188,6 +188,13 @@ def serialList(): for additional in additionalPorts: candidates += glob.glob(additional) + hooks = octoprint.plugin.plugin_manager().get_hooks("octoprint.comm.transport.serial.additional_port_names") + for name, hook in hooks.items(): + try: + candidates += hook(candidates) + except Exception: + logging.getLogger(__name__).exception("Error while retrieving additional " + "serial port names from hook {}".format(name)) # special treatment for virtual printer # TODO: Move that exclusively into the plugin