Browse Source

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
Youness Alaoui 8 years ago
parent
commit
7e7e15a12b

+ 2 - 0
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.

+ 8 - 18
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"