mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Prevent Cura from messing with serial ports of other devices by filtering ports with regular expressions passed in as environment variables
This commit is contained in:
parent
e3861b0d90
commit
c813005170
1 changed files with 23 additions and 0 deletions
|
@ -5,6 +5,8 @@ import threading
|
||||||
import platform
|
import platform
|
||||||
import time
|
import time
|
||||||
import serial.tools.list_ports
|
import serial.tools.list_ports
|
||||||
|
from os import environ
|
||||||
|
from re import search
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
|
||||||
|
|
||||||
|
@ -175,6 +177,27 @@ class USBPrinterOutputDeviceManager(QObject, OutputDevicePlugin):
|
||||||
port = (port.device, port.description, port.hwid)
|
port = (port.device, port.description, port.hwid)
|
||||||
if only_list_usb and not port[2].startswith("USB"):
|
if only_list_usb and not port[2].startswith("USB"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# To prevent cura from messing with serial ports of other devices,
|
||||||
|
# filter by regular expressions passed in as environment variables.
|
||||||
|
# Get possible patterns with python3 -m serial.tools.list_ports -v
|
||||||
|
|
||||||
|
# set CURA_DEVICENAMES=USB[1-9] -> e.g. not matching /dev/ttyUSB0
|
||||||
|
pattern = environ.get('CURA_DEVICENAMES')
|
||||||
|
if pattern and not search(pattern, port[0]):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# set CURA_DEVICETYPES=CP2102 -> match a type of serial converter
|
||||||
|
pattern = environ.get('CURA_DEVICETYPES')
|
||||||
|
if pattern and not search(pattern, port[1]):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# set CURA_DEVICEINFOS=LOCATION=2-1.4 -> match a physical port
|
||||||
|
# set CURA_DEVICEINFOS=VID:PID=10C4:EA60 -> match a vendor:product
|
||||||
|
pattern = environ.get('CURA_DEVICEINFOS')
|
||||||
|
if pattern and not search(pattern, port[2]):
|
||||||
|
continue
|
||||||
|
|
||||||
base_list += [port[0]]
|
base_list += [port[0]]
|
||||||
|
|
||||||
return list(base_list)
|
return list(base_list)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue