Last active
April 7, 2021 08:43
-
-
Save zerog2k/4173d1e9fc7cf5959f22f9f0e71b6c6e to your computer and use it in GitHub Desktop.
script to upload firmware to FlashForge Dreamer (or PowerSpec Ultra3D) printers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
''' | |
script to upload firmware to FlashForge Dreamer (or PowerSpec Ultra3D) printers | |
''' | |
import usb | |
import hashlib | |
printer = usb.core.find(idVendor=0x2b71) | |
CONTROL_EP = 0x01 | |
FILE_EP = 0x03 | |
FILENAME = "dreamer_v2.15.20200917.bin" | |
TARGET_FILENAME = "dreamer.bin" # "power.bin" for PowerSpec Ultra3D | |
m = hashlib.md5() | |
fw = open(FILENAME, 'rb') | |
m.update(fw.read()) | |
md5sum = m.hexdigest() | |
fwsize = fw.tell() | |
fw.seek(0) | |
printer.set_configuration() | |
# start control | |
printer.write(CONTROL_EP, '~M601 S0\r\n') | |
ret = printer.read(0x81, 120) | |
print(ret.tobytes()) | |
# start fw write | |
fw_write_str = "~M28 {} 0:/sys/{}\r\n".format(fwsize, TARGET_FILENAME) | |
printer.write(CONTROL_EP, fw_write_str) | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) | |
# write fw to endpoint | |
printer.write(FILE_EP, fw.read(), 3000) # seems like i was getting timeouts below about 1500ms | |
# finish fw write | |
fw_write_str = "~M29 {}\r\n".format(md5sum) | |
printer.write(CONTROL_EP, fw_write_str) | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) | |
# trigger fw flash on next boot? | |
printer.write(CONTROL_EP, '~M600\r\n') | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) | |
# stop control | |
printer.write(CONTROL_EP, '~M602\r\n') | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) | |
ret = printer.read(0x81, 100) | |
print(ret.tobytes()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment