Jane Medium : Prepared using Python control MM32-LINK Automatic download program , This can reduce operations in the development process .
MM32-LINK In the process of opening the program , There is an error in the title of the dialog ,“Load form file”, It should be changed to “Load from file”.
key word
: MM32-LINK,Python, Simulation mouse , Automatic program download
stay Make smart MCU MM32F3277 The beta Described by MM32-LINK Complete for smart MCU The development process . In particular, a design based on MM32-LINK Of 5PIN Program download interface . however , If in the whole development process , need MM32-LINK Automatically complete program download , Need to pass through MM32-LINK The loader on the interface , And programming process . Using the mouse requires multiple operations .
The following will pass Python Program , Simulate mouse and keyboard operation , Complete the process of downloading the program with one click .
▲ chart 1.1 MM32-LINK Interface
By intercepting MM32-LINK Dialog box , Draw the line from the upper left corner to open programs Line segment of position , By displaying segment properties ( wide , Long ) So as to obtain the relative position of the mouse click to open the program button .(803,175)
according to Simulate a mouse click python In the introduction , have access to pyautogui The program package completes the simulation operation of the mouse .
▲ chart 1.1.1 Click on “ open programs ”, The file open dialog box pops up
from head import *
import pyautogui
MM32_TITLE = 'MM32-LINK'
offset_x = 803
offset_y = 175
rect = tspgetwindowrect(MM32_TITLE)
click_x = rect[0] + offset_x
click_y = rect[1] + offset_y
pyautogui.click(click_x, click_y)
for _ in range(20):
time.sleep(.1)
rect = tspgetwindowrect('Load form file')
if sum(rect) != 0:
break
printf(rect)
■ error :MM32-LINK The software has an error in the title of the open dialog box :Load form file
It should be changed to : “Load from file
”
And then use Python Analog shortcut keys , The bonus controls the entire automatic download process of the program .
▲ chart 1.2.1 Complete program import and download process
from head import *
import pyautogui
MM32_TITLE = 'MM32-LINK'
offset_x = 803
offset_y = 175
filename = r'D:\zhuoqing\window\ARM\IAR\MM32\Test\TestF103UART2.hex'
if not os.path.isfile(filename):
printf("ERROR:Can not find file :%s\a"%filename)
exit()
rect = tspgetwindowrect(MM32_TITLE)
click_x = rect[0] + offset_x
click_y = rect[1] + offset_y
LOAD_FILE = 'Load form file'
pyautogui.click(click_x, click_y)
for _ in range(20):
time.sleep(.1)
rect = tspgetwindowrect(LOAD_FILE)
if sum(rect) != 0:
break
if sum(rect) == 0:
printf("No load file dialog open !\a")
exit()
clipboard.copy(filename)
tspsendwindowkey(LOAD_FILE, "n", alt=1, noreturn=1)
tspsendwindowkey(LOAD_FILE, "v", control=1, noreturn=1)
tspsendwindowkey(LOAD_FILE, "o", alt=1, noreturn=1)
time.sleep(.5)
tspsendwindowkey(MM32_TITLE, "p", alt=1, noreturn=1)
for _ in range(20):
time.sleep(.1)
rect = tspgetwindowrect('Program')
if sum(rect) != 0: break
if sum(rect) == 0:
printf("ERROR:No program dialog open.\a")
exit()
tspsendwindowkey('Program', '\r', noreturn=1)
printf("\a")
time.sleep(2.0)
tspsendwindowkey('Program', 'c', alt=1, noreturn=1)
printf("\a")
Ed Write use Python control MM32-LINK Automatic download program , This can reduce operations in the development process .
MM32-LINK In the process of opening the program , There is an error in the title of the dialog ,“Load form file”, It should be changed to “Load from file”.
The completed procedure is given below .
#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# MM32PRG.PY -- by Dr. ZhuoQing 2021-11-03
#
# Note:
#============================================================
from head import *
import pyautogui
#------------------------------------------------------------
MM32_TITLE = 'MM32-LINK'
offset_x = 803
offset_y = 175
#------------------------------------------------------------
filename = r'D:\zhuoqing\window\ARM\IAR\MM32\Test\SeekFreeMP.Hex'
if len(sys.argv) > 1:
filename = sys.argv[1]
printf(filename)
#------------------------------------------------------------
if not os.path.isfile(filename):
printf("ERROR:Can not find file :%s\a"%filename)
exit()
#------------------------------------------------------------
windowrect = tspgetwindowrect(MM32_TITLE)
click_x = windowrect[0] + offset_x
click_y = windowrect[1] + offset_y
#------------------------------------------------------------
LOAD_FILE = 'Load form file'
pyautogui.click(click_x, click_y)
for _ in range(20):
time.sleep(.1)
rect = tspgetwindowrect(LOAD_FILE)
if sum(rect) != 0:
break
#------------------------------------------------------------
if sum(rect) == 0:
printf("No load file dialog open !\a")
exit()
#------------------------------------------------------------
clipboard.copy(filename)
tspsendwindowkey(LOAD_FILE, "n", alt=1, noreturn=1)
tspsendwindowkey(LOAD_FILE, "v", control=1, noreturn=1)
tspsendwindowkey(LOAD_FILE, "o", alt=1, noreturn=1)
time.sleep(.5)
#------------------------------------------------------------
tspsendwindowkey(MM32_TITLE, "c", alt=1, noreturn=1)
time.sleep(1)
wm_offsetx = 430
wm_offsety = 503
click_x = windowrect[0] + wm_offsetx
click_y = windowrect[1] + wm_offsety
pyautogui.click(click_x, click_y)
#------------------------------------------------------------
''' tspsendwindowkey(MM32_TITLE, "p", alt=1, noreturn=1) for _ in range(20): time.sleep(.1) rect = tspgetwindowrect('Program') if sum(rect) != 0: break if sum(rect) == 0: printf("ERROR:No program dialog open.\a") exit() tspsendwindowkey('Program', '\r', noreturn=1) printf("\a") time.sleep(2.0) tspsendwindowkey('Program', 'c', alt=1, noreturn=1) '''
#------------------------------------------------------------
printf("\a")
#------------------------------------------------------------
# END OF FILE : MM32PRG.PY
#============================================================
■ Links to related literature :
● Related chart Links :