※ 实验总结 ※
编写了利用Python控制MM32-LINK自动下载程序,这可以减少在开发过程中的操作。
MM32-LINK在打开程序过程中,对话框的标题出现错误,“Load form file”,应该修改成“Load from file”。
下面给出完成的程序。
- #!/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
- #============================================================
|