程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python automated code generation and validation code summary

編輯:Python

python Software automation

  • 0 Clue
  • 1. Turn on automatically 、 compile 、 download :
    • 1.1 Automatically open the project , Open software
    • 1.2. Auto click compile , Download button ,
  • 2. Automatic code writing
    • 2.1 Make changes to the project
    • 2.2 Yes C File change
  • 3 The part of verification
    • 3.1 Read high and low levels
    • 3.2 Upload level PC
    • 3.3 The upper computer receives data
  • 4 Hardware preparation and connection

0 Clue

First, explain the whole plan , It's divided into three parts ,

  1. Automatically generate the required code, compile and download ,
  2. Verify the correctness of the code
  3. Implementation of hardware part

In this automatic way , Reduce duplication of effort in chip testing , And improve code generation IDE Tools .

1. Turn on automatically 、 compile 、 download :

1.1 Automatically open the project , Open software

The following code is opened through an absolute path Keil engineering

import subprocess
import os
main = "C:/Users/siyu/.PyCharmCE2019.1/config/scratches/two/main.uvproj"
if os.path.exists(main):
rc,out= subprocess.getstatusoutput(main)
print (rc)
print ('*'*10)
print (out)

Reference resources :
python in 3 Call executable file .exe Methods

python Realize to windows The libraries involved in window operation are ctypes 、win32GUI、pywin32、win32con etc. , These still need to continue to enrich knowledge .

1.2. Auto click compile , Download button ,

Use python Open the project file , Use python Medium pyautiogui Realize the positioning of the keys

The installation of the package

pip install pyautogui
import pyautogui
# Determine the position of the target screenshot on the system , Both methods can be implemented 
#location=pyautogui.locateOnScreen(image='autotest.png')
location=pyautogui.locateOnScreen(image='C:/Users/siyu/Pictures/autotest.png')
# Output coordinates 
print(location)
# utilize center() Function to obtain the central coordinate position of the target image in the system 
x,y=pyautogui.center(location)
print('center()',x,y)
# Click on the recognized target image 
# Parameters x,y Represents the coordinate position ,clicks Represents the number of hits ,button It can be set as left or right key 
pyautogui.click(x=x,y=y,clicks=1,button='left')

This has been implemented based on GUI The operating , The difference lies in clicking different buttons , Need to dynamically add buttons .

Reference code
The use of
【pyautogui】 utilize Python Conduct windows Image recognition and click on the system (Mac OS The system can also )

other
【Python】 Match the position in the original image through the screenshot (opencv)
pyppeteer( 6、 ... and )– adopt opencv Find the location of the picture in another picture

2. Automatic code writing

This is divided into three parts
a) Add... To the implementation project C file
b) Yes C Change the code in the file
C) After optimization GUI The implementation of the

2.1 Make changes to the project

Implementation steps :
Open the project file in text mode >>> Add files

Realize the reading of project files , And save it to str Array

f = open("main.uvproj","r") # Set file object 
str = f.read() # take txt All the contents of the file are read into the string str in 
print(str)
f.close() # Close the file 

Realization main String lookup , And output line number

findMusic="main";
MusicLine=0;
f = open('main.c','r')
for lines in f.readlines():
MusicLine=MusicLine+1;
if lines.find(findMusic)!=-1:
print(lines)
print("find it .........................")
print(MusicLine)
#print(lines,end='')
f.close()

python Change the specified row
Code not verified , Should be python2 Code for

#coding=utf-8
lines=[]
f=open("d:\\1script\\1.txt",'r') #your path!
for line in f:
lines.append(line)
f.close()
print lines
lines.insert(3,"666\n") # Fourth line insert 666 And return 
s=''.join(lines)
f=open("d:\\1script\\1.txt",'w+') # Rewrite file 
f.write(s)
f.close()
del lines[:] # clear list 
print lines

Reference code :
python How to open a txt file It realizes two functions of reading and writing .
python Write to the specified line of the file

2.2 Yes C File change

Implementation steps : open C file >>> Locate the location that needs to be changed >>> Compare and modify libraries , Modify the code >>> Save and exit
Library functions are required to locate the code , It is difficult to recognize the meaning of all the codes , Only code regions can be generated and cannot be edited ,

Realization c File reading , And storage to str in

f = open("main.c","r") # Set file object 
str = f.read() # take txt All the contents of the file are read into the string str in 
print(str)
f.close() # Close the file 

Make replicable ,

  1. Insert code on the specified line , be based on Excel Indexes , Multiple lines can be inserted
  2. The inserted code can be based on GPIO Automatically generate and change key information , Find based on characters , Or global variables change , Map to different gpio. The mapping relationship uses Excel Input .

PS: As mentioned above Excel The input can be replaced by GUI Interface input . And the mapping relationship is directly recognized by the picture .

3 The part of verification

Implementation steps :
gpio Read high and low levels >>> Upload high and low levels PC>>>PC According to the uploaded data , And the part of coding , Know whether the requirements are met

3.1 Read high and low levels

FPGA The high-speed port of can realize GHZ The judgment of the , But it needs to be confirmed that the common IO Maximum reading speed of the port .

Common interface speeds

Interface Speed IIC100K、400K、1M、3.4M etc. SPI50M max?\STM32 Maximum 18MSATA1.0—1.5Gbps \ 2.0—3Gbps \ 3.0—6GbpsUART Generally not more than 20K?

Generally, the maximum test speed is 18M, If the rich design 50M The biggest one is . If there is a high-speed requirement , Need to redraw PCB, Or connect to a specific interface in advance .

3.2 Upload level PC

adopt USB Protocol upload , Common are the use of specific USB chip , Realization 2.0 The transmission of . Can basically meet the needs of ?

USB The speed of :

Foreign name Time Transmission rate Supply voltage Supply current USB1.01996 year 1.5 Mbps(0.12 MB/s) (Low-Speed)5V500mAUSB1.11998 year 12 Mbps(1.5 MB/s) (Full-Speed)5V500mAUSB2.02000 year 480Mbps(60 MB/s)(High-speed)5V500mAUSB3.02008 year 5.0Gbps(500MB/s )(Super-speed)5V900mAUSB3.1–10.0Gbps(1000MB/s )(Super-speed)––

USB Transfer to computer
Little Mei :USB2.0 CY7C68013 Based on little MEG ACX720 FPGA Development board , The driver recommended by the chip manufacturer is adopted .
Punctual atom Da Vinci FPGA Development board

3.3 The upper computer receives data

This part needs to develop corresponding receiving tools , be based on USB Learning from . There is no corresponding knowledge reserve for this part .

4 Hardware preparation and connection

FPGA >>> High speed connector >>> Adapter plate >>>FPGA Daughter board

The first two are ready-made Salins development boards , The rear adapter board is a multilayer board ,

The adapter board can be connected to the... For logic analysis FPGA, It can also be connected to the existing voltage converter PCB.

PS: Possible problems :
a) Voltage matching problem . existing FPGA The output voltage is 1.8V,
b) The problem of board signal attenuation


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved