Jumperless/JumperlessNano/scripts/find_Jumperless_upload.py
2023-07-08 09:04:30 -07:00

30 lines
802 B
Python

Import("env")
def find_jumperless_port_upload(source, target, env):
import serial
import serial.tools.list_ports
autodetected = -1
ports = serial.tools.list_ports.comports()
i = 0
for port, desc, hwid in ports:
print("{}: {} [{}]".format(i, port, desc))
if desc == "Jumperless":
autodetected = i
i = i + 1
if autodetected != -1:
selection = autodetected
env.Replace(MONITOR_PORT=ports[selection][0])
env.Replace(UPLOAD_PORT=ports[selection][0])
#(env, "monitor_port", ports[selection][0])
# ConfigEnvOption(env, "upload_port", ports[selection][0])
print("Autodetected jumperless port: " + ports[selection][0])
env.AddPreAction("upload", find_jumperless_port_upload)