My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

create_custom_upload_command_CDC.py 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env python
  2. #
  3. # Builds custom upload command
  4. # 1) Run platformio as a subprocess to find a COM port
  5. # 2) Build the upload command
  6. # 3) Exit and let upload tool do the work
  7. #
  8. # This script runs between completion of the library/dependencies installation and compilation.
  9. #
  10. # Will continue on if a COM port isn't found so that the compilation can be done.
  11. #
  12. from __future__ import print_function
  13. from __future__ import division
  14. import subprocess,os,sys,platform
  15. from SCons.Script import DefaultEnvironment
  16. current_OS = platform.system()
  17. env = DefaultEnvironment()
  18. build_type = os.environ.get("BUILD_TYPE", 'Not Set')
  19. if not(build_type == 'upload' or build_type == 'traceback' or build_type == 'Not Set') :
  20. env.Replace(UPLOAD_PROTOCOL = 'teensy-gui') # run normal Teensy2 scripts
  21. else:
  22. com_first = ''
  23. com_last = ''
  24. com_CDC = ''
  25. description_first = ''
  26. description_last = ''
  27. description_CDC = ''
  28. #
  29. # grab the first com port that pops up unless we find one we know for sure
  30. # is a CDC device
  31. #
  32. def get_com_port(com_search_text, descr_search_text, start):
  33. global com_first
  34. global com_last
  35. global com_CDC
  36. global description_first
  37. global description_last
  38. global description_CDC
  39. print('\nLooking for Serial Port\n')
  40. # stream output from subprocess and split it into lines
  41. pio_subprocess = subprocess.Popen(['platformio', 'device', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
  42. looking_for_description = False
  43. for line in iter(pio_subprocess.stdout.readline, ''):
  44. if 0 <= line.find(com_search_text):
  45. looking_for_description = True
  46. com_last = line.replace('\n', '')
  47. if com_first == '':
  48. com_first = com_last
  49. if 0 <= line.find(descr_search_text) and looking_for_description:
  50. looking_for_description = False
  51. description_last = line[ start : ]
  52. if description_first == '':
  53. description_first = description_last
  54. if 0 <= description_last.find('CDC'):
  55. com_CDC = com_last
  56. description_CDC = description_last
  57. if com_CDC == '' and com_first != '':
  58. com_CDC = com_first
  59. description_CDC = description_first
  60. elif com_CDC == '':
  61. com_CDC = 'COM_PORT_NOT_FOUND'
  62. while 0 <= com_CDC.find('\n'):
  63. com_CDC = com_CDC.replace('\n', '')
  64. while 0 <= com_CDC.find('\r'):
  65. com_CDC = com_CDC.replace('\r', '')
  66. if com_CDC == 'COM_PORT_NOT_FOUND':
  67. print(com_CDC, '\n')
  68. else:
  69. print('FOUND: ', com_CDC)
  70. print('DESCRIPTION: ', description_CDC, '\n')
  71. if current_OS == 'Windows':
  72. get_com_port('COM', 'Hardware ID:', 13)
  73. # avrdude_conf_path = env.get("PIOHOME_DIR") + '\\packages\\toolchain-atmelavr\\etc\\avrdude.conf'
  74. avrdude_conf_path = 'buildroot\\share\\vscode\\avrdude.conf'
  75. avrdude_exe_path = 'buildroot\\share\\vscode\\avrdude_5.10.exe'
  76. # source_path = env.get("PROJECTBUILD_DIR") + '\\' + env.get("PIOENV") + '\\firmware.hex'
  77. source_path = '.pio\\build\\' + env.get("PIOENV") + '\\firmware.hex'
  78. upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
  79. if current_OS == 'Darwin': # MAC
  80. get_com_port('usbmodem', 'Description:', 13)
  81. # avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
  82. avrdude_conf_path = 'buildroot/share/vscode/avrdude_macOS.conf'
  83. avrdude_exe_path = 'buildroot/share/vscode/avrdude_5.10_macOS'
  84. # source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
  85. source_path = '.pio/build/' + env.get("PIOENV") + '/firmware.hex'
  86. # upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
  87. upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
  88. print('upload_string: ', upload_string)
  89. if current_OS == 'Linux':
  90. get_com_port('/dev/tty', 'Description:', 13)
  91. # avrdude_conf_path = env.get("PIOHOME_DIR") + '/packages/toolchain-atmelavr/etc/avrdude.conf'
  92. avrdude_conf_path = 'buildroot/share/vscode/avrdude_linux.conf'
  93. avrdude_exe_path = 'buildroot/share/vscode/avrdude_5.10_linux'
  94. # source_path = env.get("PROJECTBUILD_DIR") + '/' + env.get("PIOENV") + '/firmware.hex'
  95. source_path = '.pio/build/' + env.get("PIOENV") + '/firmware.hex'
  96. # upload_string = 'avrdude -p usb1286 -c avr109 -P ' + com_CDC + ' -U flash:w:' + source_path + ':i'
  97. upload_string = avrdude_exe_path + ' -p usb1286 -c avr109 -P ' + com_CDC + ' -C ' + avrdude_conf_path + ' -U flash:w:' + source_path + ':i'
  98. env.Replace(
  99. UPLOADCMD = upload_string,
  100. MAXIMUM_RAM_SIZE = 8192,
  101. MAXIMUM_SIZE = 130048
  102. )