PrinterConnection.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from .avr_isp import stk500v2, ispBase, intelHex
  4. import serial
  5. import threading
  6. import time
  7. import queue
  8. import re
  9. import functools
  10. import os
  11. import os.path
  12. from UM.Application import Application
  13. from UM.Signal import Signal, SignalEmitter
  14. from UM.Resources import Resources
  15. from UM.Logger import Logger
  16. from UM.OutputDevice.OutputDevice import OutputDevice
  17. from UM.OutputDevice import OutputDeviceError
  18. from UM.PluginRegistry import PluginRegistry
  19. from PyQt5.QtQuick import QQuickView
  20. from PyQt5.QtQml import QQmlComponent, QQmlContext
  21. from PyQt5.QtCore import QUrl, QObject, pyqtSlot, pyqtProperty, pyqtSignal, Qt
  22. from UM.i18n import i18nCatalog
  23. catalog = i18nCatalog("cura")
  24. class PrinterConnection(OutputDevice, QObject, SignalEmitter):
  25. def __init__(self, serial_port, parent = None):
  26. QObject.__init__(self, parent)
  27. OutputDevice.__init__(self, serial_port)
  28. SignalEmitter.__init__(self)
  29. #super().__init__(serial_port)
  30. self.setName(catalog.i18nc("@item:inmenu", "USB printing"))
  31. self.setShortDescription(catalog.i18nc("@action:button", "Print with USB"))
  32. self.setDescription(catalog.i18nc("@info:tooltip", "Print with USB"))
  33. self.setIconName("print")
  34. self._serial = None
  35. self._serial_port = serial_port
  36. self._error_state = None
  37. self._connect_thread = threading.Thread(target = self._connect)
  38. self._connect_thread.daemon = True
  39. self._end_stop_thread = threading.Thread(target = self._pollEndStop)
  40. self._end_stop_thread.deamon = True
  41. # Printer is connected
  42. self._is_connected = False
  43. # Printer is in the process of connecting
  44. self._is_connecting = False
  45. # The baud checking is done by sending a number of m105 commands to the printer and waiting for a readable
  46. # response. If the baudrate is correct, this should make sense, else we get giberish.
  47. self._required_responses_auto_baud = 3
  48. self._progress = 0
  49. self._listen_thread = threading.Thread(target=self._listen)
  50. self._listen_thread.daemon = True
  51. self._update_firmware_thread = threading.Thread(target= self._updateFirmware)
  52. self._update_firmware_thread.deamon = True
  53. self._heatup_wait_start_time = time.time()
  54. ## Queue for commands that need to be send. Used when command is sent when a print is active.
  55. self._command_queue = queue.Queue()
  56. self._is_printing = False
  57. ## Set when print is started in order to check running time.
  58. self._print_start_time = None
  59. self._print_start_time_100 = None
  60. ## Keep track where in the provided g-code the print is
  61. self._gcode_position = 0
  62. # List of gcode lines to be printed
  63. self._gcode = []
  64. # Number of extruders
  65. self._extruder_count = 1
  66. # Temperatures of all extruders
  67. self._extruder_temperatures = [0] * self._extruder_count
  68. # Target temperatures of all extruders
  69. self._target_extruder_temperatures = [0] * self._extruder_count
  70. #Target temperature of the bed
  71. self._target_bed_temperature = 0
  72. # Temperature of the bed
  73. self._bed_temperature = 0
  74. # Current Z stage location
  75. self._current_z = 0
  76. self._x_min_endstop_pressed = False
  77. self._y_min_endstop_pressed = False
  78. self._z_min_endstop_pressed = False
  79. self._x_max_endstop_pressed = False
  80. self._y_max_endstop_pressed = False
  81. self._z_max_endstop_pressed = False
  82. # In order to keep the connection alive we request the temperature every so often from a different extruder.
  83. # This index is the extruder we requested data from the last time.
  84. self._temperature_requested_extruder_index = 0
  85. self._updating_firmware = False
  86. self._firmware_file_name = None
  87. self._control_view = None
  88. onError = pyqtSignal()
  89. progressChanged = pyqtSignal()
  90. extruderTemperatureChanged = pyqtSignal()
  91. bedTemperatureChanged = pyqtSignal()
  92. endstopStateChanged = pyqtSignal(str ,bool, arguments = ["key","state"])
  93. @pyqtProperty(float, notify = progressChanged)
  94. def progress(self):
  95. return self._progress
  96. @pyqtProperty(float, notify = extruderTemperatureChanged)
  97. def extruderTemperature(self):
  98. return self._extruder_temperatures[0]
  99. @pyqtProperty(float, notify = bedTemperatureChanged)
  100. def bedTemperature(self):
  101. return self._bed_temperature
  102. @pyqtProperty(str, notify = onError)
  103. def error(self):
  104. return self._error_state
  105. # TODO: Might need to add check that extruders can not be changed when it started printing or loading these settings from settings object
  106. def setNumExtuders(self, num):
  107. self._extruder_count = num
  108. self._extruder_temperatures = [0] * self._extruder_count
  109. self._target_extruder_temperatures = [0] * self._extruder_count
  110. ## Is the printer actively printing
  111. def isPrinting(self):
  112. if not self._is_connected or self._serial is None:
  113. return False
  114. return self._is_printing
  115. @pyqtSlot()
  116. def startPrint(self):
  117. self.writeStarted.emit(self)
  118. gcode_list = getattr( Application.getInstance().getController().getScene(), "gcode_list")
  119. self.printGCode(gcode_list)
  120. ## Start a print based on a g-code.
  121. # \param gcode_list List with gcode (strings).
  122. def printGCode(self, gcode_list):
  123. if self.isPrinting() or not self._is_connected:
  124. Logger.log("d", "Printer is busy or not connected, aborting print")
  125. self.writeError.emit(self)
  126. return
  127. self._gcode.clear()
  128. for layer in gcode_list:
  129. self._gcode.extend(layer.split("\n"))
  130. #Reset line number. If this is not done, first line is sometimes ignored
  131. self._gcode.insert(0, "M110")
  132. self._gcode_position = 0
  133. self._print_start_time_100 = None
  134. self._is_printing = True
  135. self._print_start_time = time.time()
  136. for i in range(0, 4): #Push first 4 entries before accepting other inputs
  137. self._sendNextGcodeLine()
  138. self.writeFinished.emit(self)
  139. ## Get the serial port string of this connection.
  140. # \return serial port
  141. def getSerialPort(self):
  142. return self._serial_port
  143. ## Try to connect the serial. This simply starts the thread, which runs _connect.
  144. def connect(self):
  145. if not self._updating_firmware and not self._connect_thread.isAlive():
  146. self._connect_thread.start()
  147. ## Private fuction (threaded) that actually uploads the firmware.
  148. def _updateFirmware(self):
  149. if self._is_connecting or self._is_connected:
  150. self.close()
  151. hex_file = intelHex.readHex(self._firmware_file_name)
  152. if len(hex_file) == 0:
  153. Logger.log("e", "Unable to read provided hex file. Could not update firmware")
  154. return
  155. programmer = stk500v2.Stk500v2()
  156. programmer.progressCallback = self.setProgress
  157. programmer.connect(self._serial_port)
  158. time.sleep(1) # Give programmer some time to connect. Might need more in some cases, but this worked in all tested cases.
  159. if not programmer.isConnected():
  160. Logger.log("e", "Unable to connect with serial. Could not update firmware")
  161. return
  162. self._updating_firmware = True
  163. try:
  164. programmer.programChip(hex_file)
  165. self._updating_firmware = False
  166. except Exception as e:
  167. Logger.log("e", "Exception while trying to update firmware %s" %e)
  168. self._updating_firmware = False
  169. return
  170. programmer.close()
  171. self.setProgress(100, 100)
  172. self.firmwareUpdateComplete.emit()
  173. ## Upload new firmware to machine
  174. # \param filename full path of firmware file to be uploaded
  175. def updateFirmware(self, file_name):
  176. Logger.log("i", "Updating firmware of %s using %s", self._serial_port, file_name)
  177. self._firmware_file_name = file_name
  178. self._update_firmware_thread.start()
  179. @pyqtSlot()
  180. def startPollEndstop(self):
  181. self._poll_endstop = True
  182. self._end_stop_thread.start()
  183. @pyqtSlot()
  184. def stopPollEndstop(self):
  185. self._poll_endstop = False
  186. def _pollEndStop(self):
  187. while self._is_connected and self._poll_endstop:
  188. self.sendCommand("M119")
  189. time.sleep(0.5)
  190. ## Private connect function run by thread. Can be started by calling connect.
  191. def _connect(self):
  192. Logger.log("d", "Attempting to connect to %s", self._serial_port)
  193. self._is_connecting = True
  194. programmer = stk500v2.Stk500v2()
  195. try:
  196. programmer.connect(self._serial_port) # Connect with the serial, if this succeeds, it"s an arduino based usb device.
  197. self._serial = programmer.leaveISP()
  198. except ispBase.IspError as e:
  199. Logger.log("i", "Could not establish connection on %s: %s. Device is not arduino based." %(self._serial_port,str(e)))
  200. except Exception as e:
  201. Logger.log("i", "Could not establish connection on %s, unknown reasons. Device is not arduino based." % self._serial_port)
  202. # If the programmer connected, we know its an atmega based version. Not all that usefull, but it does give some debugging information.
  203. for baud_rate in self._getBaudrateList(): # Cycle all baud rates (auto detect)
  204. Logger.log("d","Attempting to connect to printer with serial %s on baud rate %s", self._serial_port, baud_rate)
  205. if self._serial is None:
  206. try:
  207. self._serial = serial.Serial(str(self._serial_port), baud_rate, timeout = 3, writeTimeout = 10000)
  208. except serial.SerialException:
  209. #Logger.log("i", "Could not open port %s" % self._serial_port)
  210. continue
  211. else:
  212. if not self.setBaudRate(baud_rate):
  213. continue # Could not set the baud rate, go to the next
  214. time.sleep(1.5) # Ensure that we are not talking to the bootloader. 1.5 sec seems to be the magic number
  215. sucesfull_responses = 0
  216. timeout_time = time.time() + 5
  217. self._serial.write(b"\n")
  218. self._sendCommand("M105") # Request temperature, as this should (if baudrate is correct) result in a command with "T:" in it
  219. while timeout_time > time.time():
  220. line = self._readline()
  221. if line is None:
  222. self.setIsConnected(False) # Something went wrong with reading, could be that close was called.
  223. return
  224. if b"T:" in line:
  225. self._serial.timeout = 0.5
  226. sucesfull_responses += 1
  227. if sucesfull_responses >= self._required_responses_auto_baud:
  228. self._serial.timeout = 2 #Reset serial timeout
  229. self.setIsConnected(True)
  230. Logger.log("i", "Established printer connection on port %s" % self._serial_port)
  231. return
  232. self._sendCommand("M105") # Send M105 as long as we are listening, otherwise we end up in an undefined state
  233. Logger.log("e", "Baud rate detection for %s failed", self._serial_port)
  234. self.close() # Unable to connect, wrap up.
  235. self.setIsConnected(False)
  236. ## Set the baud rate of the serial. This can cause exceptions, but we simply want to ignore those.
  237. def setBaudRate(self, baud_rate):
  238. try:
  239. self._serial.baudrate = baud_rate
  240. return True
  241. except Exception as e:
  242. return False
  243. def setIsConnected(self, state):
  244. self._is_connecting = False
  245. if self._is_connected != state:
  246. self._is_connected = state
  247. self.connectionStateChanged.emit(self._serial_port)
  248. if self._is_connected:
  249. self._listen_thread.start() #Start listening
  250. else:
  251. Logger.log("w", "Printer connection state was not changed")
  252. connectionStateChanged = Signal()
  253. ## Close the printer connection
  254. def close(self):
  255. if self._connect_thread.isAlive():
  256. try:
  257. self._connect_thread.join()
  258. except Exception as e:
  259. pass # This should work, but it does fail sometimes for some reason
  260. self._connect_thread = threading.Thread(target=self._connect)
  261. self._connect_thread.daemon = True
  262. if self._serial is not None:
  263. self.setIsConnected(False)
  264. try:
  265. self._listen_thread.join()
  266. except:
  267. pass
  268. self._serial.close()
  269. self._listen_thread = threading.Thread(target=self._listen)
  270. self._listen_thread.daemon = True
  271. self._serial = None
  272. def isConnected(self):
  273. return self._is_connected
  274. @pyqtSlot(int)
  275. def heatupNozzle(self, temperature):
  276. Logger.log("d", "Setting nozzle temperature to %s", temperature)
  277. self._sendCommand("M104 S%s" % temperature)
  278. @pyqtSlot(int)
  279. def heatupBed(self, temperature):
  280. Logger.log("d", "Setting bed temperature to %s", temperature)
  281. self._sendCommand("M140 S%s" % temperature)
  282. @pyqtSlot("long", "long","long")
  283. def moveHead(self, x, y, z):
  284. Logger.log("d","Moving head to %s, %s , %s", x, y, z)
  285. self._sendCommand("G0 X%s Y%s Z%s"%(x,y,z))
  286. @pyqtSlot()
  287. def homeHead(self):
  288. self._sendCommand("G28")
  289. ## Directly send the command, withouth checking connection state (eg; printing).
  290. # \param cmd string with g-code
  291. def _sendCommand(self, cmd):
  292. if self._serial is None:
  293. return
  294. if "M109" in cmd or "M190" in cmd:
  295. self._heatup_wait_start_time = time.time()
  296. if "M104" in cmd or "M109" in cmd:
  297. try:
  298. t = 0
  299. if "T" in cmd:
  300. t = int(re.search("T([0-9]+)", cmd).group(1))
  301. self._target_extruder_temperatures[t] = float(re.search("S([0-9]+)", cmd).group(1))
  302. except:
  303. pass
  304. if "M140" in cmd or "M190" in cmd:
  305. try:
  306. self._target_bed_temperature = float(re.search("S([0-9]+)", cmd).group(1))
  307. except:
  308. pass
  309. try:
  310. command = (cmd + "\n").encode()
  311. self._serial.write(b"\n")
  312. self._serial.write(command)
  313. except serial.SerialTimeoutException:
  314. Logger.log("w","Serial timeout while writing to serial port, trying again.")
  315. try:
  316. time.sleep(0.5)
  317. self._serial.write((cmd + "\n").encode())
  318. except Exception as e:
  319. Logger.log("e","Unexpected error while writing serial port %s " % e)
  320. self._setErrorState("Unexpected error while writing serial port %s " % e)
  321. self.close()
  322. except Exception as e:
  323. Logger.log("e","Unexpected error while writing serial port %s" % e)
  324. self._setErrorState("Unexpected error while writing serial port %s " % e)
  325. self.close()
  326. ## Ensure that close gets called when object is destroyed
  327. def __del__(self):
  328. self.close()
  329. def createControlInterface(self):
  330. if self._control_view is None:
  331. path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "ControlWindow.qml"))
  332. component = QQmlComponent(Application.getInstance()._engine, path)
  333. self._control_context = QQmlContext(Application.getInstance()._engine.rootContext())
  334. self._control_context.setContextProperty("manager", self)
  335. self._control_view = component.create(self._control_context)
  336. ## Show control interface.
  337. # This will create the view if its not already created.
  338. def showControlInterface(self):
  339. if self._control_view is None:
  340. self.createControlInterface()
  341. self._control_view.show()
  342. ## Send a command to printer.
  343. # \param cmd string with g-code
  344. def sendCommand(self, cmd):
  345. if self.isPrinting():
  346. self._command_queue.put(cmd)
  347. elif self.isConnected():
  348. self._sendCommand(cmd)
  349. ## Set the error state with a message.
  350. # \param error String with the error message.
  351. def _setErrorState(self, error):
  352. self._error_state = error
  353. self.onError.emit()
  354. ## Private function to set the temperature of an extruder
  355. # \param index index of the extruder
  356. # \param temperature recieved temperature
  357. def _setExtruderTemperature(self, index, temperature):
  358. try:
  359. self._extruder_temperatures[index] = temperature
  360. self.extruderTemperatureChanged.emit()
  361. except Exception as e:
  362. pass
  363. ## Private function to set the temperature of the bed.
  364. # As all printers (as of time of writing) only support a single heated bed,
  365. # these are not indexed as with extruders.
  366. def _setBedTemperature(self, temperature):
  367. self._bed_temperature = temperature
  368. self.bedTemperatureChanged.emit()
  369. def requestWrite(self, node):
  370. self.showControlInterface()
  371. def _setEndstopState(self, endstop_key, value):
  372. if endstop_key == b'x_min':
  373. if self._x_min_endstop_pressed != value:
  374. self.endstopStateChanged.emit('x_min', value)
  375. self._x_min_endstop_pressed = value
  376. elif endstop_key == b'y_min':
  377. if self._y_min_endstop_pressed != value:
  378. self.endstopStateChanged.emit('y_min', value)
  379. self._y_min_endstop_pressed = value
  380. elif endstop_key == b'z_min':
  381. if self._z_min_endstop_pressed != value:
  382. self.endstopStateChanged.emit('z_min', value)
  383. self._z_min_endstop_pressed = value
  384. ## Listen thread function.
  385. def _listen(self):
  386. Logger.log("i", "Printer connection listen thread started for %s" % self._serial_port)
  387. temperature_request_timeout = time.time()
  388. ok_timeout = time.time()
  389. while self._is_connected:
  390. line = self._readline()
  391. if line is None:
  392. break # None is only returned when something went wrong. Stop listening
  393. if time.time() > temperature_request_timeout:
  394. if self._extruder_count > 0:
  395. self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._extruder_count
  396. self.sendCommand("M105 T%d" % (self._temperature_requested_extruder_index))
  397. else:
  398. self.sendCommand("M105")
  399. temperature_request_timeout = time.time() + 5
  400. if line.startswith(b"Error:"):
  401. # Oh YEAH, consistency.
  402. # Marlin reports an MIN/MAX temp error as "Error:x\n: Extruder switched off. MAXTEMP triggered !\n"
  403. # But a bed temp error is reported as "Error: Temperature heated bed switched off. MAXTEMP triggered !!"
  404. # So we can have an extra newline in the most common case. Awesome work people.
  405. if re.match(b"Error:[0-9]\n", line):
  406. line = line.rstrip() + self._readline()
  407. # Skip the communication errors, as those get corrected.
  408. if b"Extruder switched off" in line or b"Temperature heated bed switched off" in line or b"Something is wrong, please turn off the printer." in line:
  409. if not self.hasError():
  410. self._setErrorState(line[6:])
  411. elif b" T:" in line or line.startswith(b"T:"): #Temperature message
  412. try:
  413. self._setExtruderTemperature(self._temperature_requested_extruder_index,float(re.search(b"T: *([0-9\.]*)", line).group(1)))
  414. except:
  415. pass
  416. if b"B:" in line: # Check if it"s a bed temperature
  417. try:
  418. self._setBedTemperature(float(re.search(b"B: *([0-9\.]*)", line).group(1)))
  419. except Exception as e:
  420. pass
  421. #TODO: temperature changed callback
  422. elif b"_min" in line or b"_max" in line:
  423. tag, value = line.split(b':', 1)
  424. self._setEndstopState(tag,(b'H' in value or b'TRIGGERED' in value))
  425. if self._is_printing:
  426. if line == b"" and time.time() > ok_timeout:
  427. line = b"ok" # Force a timeout (basicly, send next command)
  428. if b"ok" in line:
  429. ok_timeout = time.time() + 5
  430. if not self._command_queue.empty():
  431. self._sendCommand(self._command_queue.get())
  432. else:
  433. self._sendNextGcodeLine()
  434. elif b"resend" in line.lower() or b"rs" in line: # Because a resend can be asked with "resend" and "rs"
  435. try:
  436. self._gcode_position = int(line.replace(b"N:",b" ").replace(b"N",b" ").replace(b":",b" ").split()[-1])
  437. except:
  438. if b"rs" in line:
  439. self._gcode_position = int(line.split()[1])
  440. else: # Request the temperature on comm timeout (every 2 seconds) when we are not printing.)
  441. if line == b"":
  442. if self._extruder_count > 0:
  443. self._temperature_requested_extruder_index = (self._temperature_requested_extruder_index + 1) % self._extruder_count
  444. self.sendCommand("M105 T%d" % self._temperature_requested_extruder_index)
  445. else:
  446. self.sendCommand("M105")
  447. Logger.log("i", "Printer connection listen thread stopped for %s" % self._serial_port)
  448. ## Send next Gcode in the gcode list
  449. def _sendNextGcodeLine(self):
  450. if self._gcode_position >= len(self._gcode):
  451. return
  452. if self._gcode_position == 100:
  453. self._print_start_time_100 = time.time()
  454. line = self._gcode[self._gcode_position]
  455. if ";" in line:
  456. line = line[:line.find(";")]
  457. line = line.strip()
  458. try:
  459. if line == "M0" or line == "M1":
  460. line = "M105" #Don"t send the M0 or M1 to the machine, as M0 and M1 are handled as an LCD menu pause.
  461. if ("G0" in line or "G1" in line) and "Z" in line:
  462. z = float(re.search("Z([0-9\.]*)", line).group(1))
  463. if self._current_z != z:
  464. self._current_z = z
  465. except Exception as e:
  466. Logger.log("e", "Unexpected error with printer connection: %s" % e)
  467. self._setErrorState("Unexpected error: %s" %e)
  468. checksum = functools.reduce(lambda x,y: x^y, map(ord, "N%d%s" % (self._gcode_position, line)))
  469. self._sendCommand("N%d%s*%d" % (self._gcode_position, line, checksum))
  470. self._gcode_position += 1
  471. self.setProgress(( self._gcode_position / len(self._gcode)) * 100)
  472. self.progressChanged.emit()
  473. ## Set the progress of the print.
  474. # It will be normalized (based on max_progress) to range 0 - 100
  475. def setProgress(self, progress, max_progress = 100):
  476. self._progress = (progress / max_progress) * 100 #Convert to scale of 0-100
  477. self.progressChanged.emit()
  478. ## Cancel the current print. Printer connection wil continue to listen.
  479. @pyqtSlot()
  480. def cancelPrint(self):
  481. self._gcode_position = 0
  482. self.setProgress(0)
  483. self._gcode = []
  484. # Turn of temperatures
  485. self._sendCommand("M140 S0")
  486. self._sendCommand("M104 S0")
  487. self._is_printing = False
  488. ## Check if the process did not encounter an error yet.
  489. def hasError(self):
  490. return self._error_state != None
  491. ## private read line used by printer connection to listen for data on serial port.
  492. def _readline(self):
  493. if self._serial is None:
  494. return None
  495. try:
  496. ret = self._serial.readline()
  497. except Exception as e:
  498. Logger.log("e","Unexpected error while reading serial port. %s" %e)
  499. self._setErrorState("Printer has been disconnected")
  500. self.close()
  501. return None
  502. return ret
  503. ## Create a list of baud rates at which we can communicate.
  504. # \return list of int
  505. def _getBaudrateList(self):
  506. ret = [115200, 250000, 230400, 57600, 38400, 19200, 9600]
  507. return ret
  508. def _onFirmwareUpdateComplete(self):
  509. self._update_firmware_thread.join()
  510. self._update_firmware_thread = threading.Thread(target= self._updateFirmware)
  511. self._update_firmware_thread.deamon = True
  512. self.connect()