|
@@ -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"
|