From 7e7e15a12b45cb707149febedec5fe1694f7d73b Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Wed, 14 Sep 2016 14:57:43 -0400 Subject: [PATCH] Fix MachineManager connection to OutputDeviceManager signals late. If a PrinterOutputDevice is able to connect quickly to a machine, then by the time the MachineManager is created and connects to the signal, it will be too late, and it might miss that there is already connected devices. # Conflicts: # plugins/USBPrinting/USBPrinterOutputDeviceManager.py --- cura/Settings/MachineManager.py | 2 ++ .../USBPrinterOutputDeviceManager.py | 26 ++++++------------- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 6499e527f5..1675438625 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -91,6 +91,8 @@ class MachineManager(QObject): self._printer_output_devices = [] Application.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged) + # There might already be some output devices by the time the signal is connected + self._onOutputDevicesChanged() if active_machine_id != "" and ContainerRegistry.getInstance().findContainerStacks(id = active_machine_id): # An active machine was saved, so restore it. diff --git a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py index 7a62a59a45..26cf5f3942 100644 --- a/plugins/USBPrinting/USBPrinterOutputDeviceManager.py +++ b/plugins/USBPrinting/USBPrinterOutputDeviceManager.py @@ -19,6 +19,7 @@ import platform import glob import time import os.path +import serial.tools.list_ports from UM.Extension import Extension from PyQt5.QtQml import QQmlComponent, QQmlContext @@ -252,24 +253,13 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin, Extension): # \param only_list_usb If true, only usb ports are listed def getSerialPortList(self, only_list_usb = False): base_list = [] - if platform.system() == "Windows": - import winreg # type: ignore @UnresolvedImport - try: - key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") - i = 0 - while True: - values = winreg.EnumValue(key, i) - if not only_list_usb or "USBSER" or "VCP" in values[0]: - base_list += [values[1]] - i += 1 - except Exception as e: - pass - else: - if only_list_usb: - base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.usb*") + glob.glob("/dev/tty.wchusb*") + glob.glob("/dev/cu.wchusb*") - base_list = filter(lambda s: "Bluetooth" not in s, base_list) # Filter because mac sometimes puts them in the list - else: - base_list = base_list + glob.glob("/dev/ttyUSB*") + glob.glob("/dev/ttyACM*") + glob.glob("/dev/cu.*") + glob.glob("/dev/tty.usb*") + glob.glob("/dev/tty.wchusb*") + glob.glob("/dev/cu.wchusb*") + glob.glob("/dev/rfcomm*") + glob.glob("/dev/serial/by-id/*") + for port in serial.tools.list_ports.comports(): + if not isinstance(port, tuple): + port = (port.device, port.description, port.hwid) + if only_list_usb and not port[2].startswith("USB"): + continue + base_list += [port[0]] + return list(base_list) _instance = None # type: "USBPrinterOutputDeviceManager"