Skip to content

Commit 5fc42a6

Browse files
committed
tools, pydfu: Some fixes to support Python 3.
1 parent 842210f commit 5fc42a6

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

tools/pydfu.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def consume(fmt, data, names):
239239

240240
def cstring(string):
241241
"""Extracts a null-terminated string from a byte array."""
242-
return string.split('\0', 1)[0]
242+
return string.split(b'\0', 1)[0]
243243

244244

245245
def compute_crc(data):
@@ -361,8 +361,8 @@ def get_dfu_devices(*args, **kwargs):
361361
refine the search.
362362
"""
363363

364-
return usb.core.find(*args, find_all=True,
365-
custom_match=FilterDFU(), **kwargs)
364+
return list(usb.core.find(*args, find_all=True,
365+
custom_match=FilterDFU(), **kwargs))
366366

367367

368368
def get_memory_layout(device):
@@ -504,7 +504,11 @@ def main():
504504
list_dfu_devices(idVendor=__VID, idProduct=__PID)
505505
return
506506

507-
init()
507+
try:
508+
init()
509+
except ValueError as er:
510+
print(str(er))
511+
sys.exit(1)
508512

509513
if args.mass_erase:
510514
print ("Mass erase...")

0 commit comments

Comments
 (0)