mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-21 21:58:01 -06:00
USBPrinting: stk500v2 cleanups
* Removing unneeded import of "os" * Removing unused "e" from SerialException * Adding #@UndefinedVariable tags for PyDev * Making message in Logger.log more detailed for portList(). Might be confusing in the logs to see just a list of ports without knowing where it is from. Contributes to CURA-1809
This commit is contained in:
parent
f8a5ee8c9b
commit
8503492b4d
1 changed files with 5 additions and 6 deletions
|
@ -3,7 +3,6 @@ STK500v2 protocol implementation for programming AVR chips.
|
||||||
The STK500v2 protocol is used by the ArduinoMega2560 and a few other Arduino platforms to load firmware.
|
The STK500v2 protocol is used by the ArduinoMega2560 and a few other Arduino platforms to load firmware.
|
||||||
This is a python 3 conversion of the code created by David Braam for the Cura project.
|
This is a python 3 conversion of the code created by David Braam for the Cura project.
|
||||||
"""
|
"""
|
||||||
import os
|
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
@ -28,7 +27,7 @@ class Stk500v2(ispBase.IspBase):
|
||||||
self.close()
|
self.close()
|
||||||
try:
|
try:
|
||||||
self.serial = Serial(str(port), speed, timeout=1, writeTimeout=10000)
|
self.serial = Serial(str(port), speed, timeout=1, writeTimeout=10000)
|
||||||
except SerialException as e:
|
except SerialException:
|
||||||
raise ispBase.IspError("Failed to open serial port")
|
raise ispBase.IspError("Failed to open serial port")
|
||||||
except:
|
except:
|
||||||
raise ispBase.IspError("Unexpected error while connecting to serial port:" + port + ":" + str(sys.exc_info()[0]))
|
raise ispBase.IspError("Unexpected error while connecting to serial port:" + port + ":" + str(sys.exc_info()[0]))
|
||||||
|
@ -92,7 +91,7 @@ class Stk500v2(ispBase.IspBase):
|
||||||
self.sendMessage([0x06, 0x00, 0x00, 0x00, 0x00])
|
self.sendMessage([0x06, 0x00, 0x00, 0x00, 0x00])
|
||||||
load_count = (len(flash_data) + page_size - 1) / page_size
|
load_count = (len(flash_data) + page_size - 1) / page_size
|
||||||
for i in range(0, int(load_count)):
|
for i in range(0, int(load_count)):
|
||||||
recv = self.sendMessage([0x13, page_size >> 8, page_size & 0xFF, 0xc1, 0x0a, 0x40, 0x4c, 0x20, 0x00, 0x00] + flash_data[(i * page_size):(i * page_size + page_size)])
|
self.sendMessage([0x13, page_size >> 8, page_size & 0xFF, 0xc1, 0x0a, 0x40, 0x4c, 0x20, 0x00, 0x00] + flash_data[(i * page_size):(i * page_size + page_size)])
|
||||||
if self.progress_callback is not None:
|
if self.progress_callback is not None:
|
||||||
if self._has_checksum:
|
if self._has_checksum:
|
||||||
self.progress_callback(i + 1, load_count)
|
self.progress_callback(i + 1, load_count)
|
||||||
|
@ -183,11 +182,11 @@ class Stk500v2(ispBase.IspBase):
|
||||||
def portList():
|
def portList():
|
||||||
ret = []
|
ret = []
|
||||||
import _winreg
|
import _winreg
|
||||||
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
|
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") #@UndefinedVariable
|
||||||
i=0
|
i=0
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
values = _winreg.EnumValue(key, i)
|
values = _winreg.EnumValue(key, i) #@UndefinedVariable
|
||||||
except:
|
except:
|
||||||
return ret
|
return ret
|
||||||
if "USBSER" in values[0]:
|
if "USBSER" in values[0]:
|
||||||
|
@ -206,7 +205,7 @@ def main():
|
||||||
""" Entry point to call the stk500v2 programmer from the commandline. """
|
""" Entry point to call the stk500v2 programmer from the commandline. """
|
||||||
import threading
|
import threading
|
||||||
if sys.argv[1] == "AUTO":
|
if sys.argv[1] == "AUTO":
|
||||||
Logger.log("d", portList())
|
Logger.log("d", "portList(): ", repr(portList()))
|
||||||
for port in portList():
|
for port in portList():
|
||||||
threading.Thread(target=runProgrammer, args=(port,sys.argv[2])).start()
|
threading.Thread(target=runProgrammer, args=(port,sys.argv[2])).start()
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue