Don't crash if USB device is taken over by other applications or breaks

If it happens at just the wrong moment, Cura could crash. Hopefully no longer, though I fear that now it would maybe crash somewhere else with the same error then. We'll find out through new error reports, I hope.

Fixes Sentry issue CURA-K8.
This commit is contained in:
Ghostkeeper 2020-04-23 11:43:25 +02:00
parent 971d8cd8e2
commit 29d2e5c921
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A

View file

@ -191,7 +191,10 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
try: try:
self._serial = Serial(str(self._serial_port), self._baud_rate, timeout=self._timeout, writeTimeout=self._timeout) self._serial = Serial(str(self._serial_port), self._baud_rate, timeout=self._timeout, writeTimeout=self._timeout)
except SerialException: except SerialException:
Logger.log("w", "An exception occurred while trying to create serial connection") Logger.warning("An exception occurred while trying to create serial connection.")
return
except OSError as e:
Logger.warning("The serial device is suddenly unavailable while trying to create a serial connection: {err}".format(err = str(e)))
return return
CuraApplication.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged) CuraApplication.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
self._onGlobalContainerStackChanged() self._onGlobalContainerStackChanged()