Method for automatically generating data analysis code and GUI (Graphical User Interface) code in automatic test system
Through the configuration file-driven code automatic generation module, the problem of inefficient data analysis and GUI code generation in automated test systems is solved, and the rapid response to changes in data formats of different testers is achieved, and development efficiency and stability are improved.
Patent Information
- Application Number
- CN202411137290.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-19
- Publication Date
- 2024-12-20
AI Technical Summary
In automated testing systems, it is difficult for the prior art to generate data analysis and GUI code quickly and accurately, resulting in inefficient development. When the data format of the tester changes, the code needs to be updated frequently, which increases the error rate.
By writing configuration files, using the code to automatically generate front-end and back-end code, and compile it into .dll files, the centralized control system can call the .dll file to receive and display tester data. You only need to update the configuration files to cope with the data formats of different testers. change.
It improves the efficiency of centralized control system development, reduces the error rate of artificial code writing, maintains the stability of the system, and reduces the need for frequent updates of centralized control programs.
Smart Images

Figure CN119166126A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a method for automatically generating data parsing code and GUI code in an automated testing system, and belongs to the field of automated testing. Background Art
[0002] Digitalization is an important trend in current development. The investment in automated production lines can greatly improve the test efficiency in the field of automated testing, realize the centralized control of test processes and test data, and the closed-loop management of the entire production process, laying a good foundation for the automatic fault diagnosis and health monitoring of the entire test system. As the middle layer of the automated production line, the centralized control system connects with the MES system at the upper layer, receives the information of the tested products and test tasks, and uploads the test results. The lower layer connects with the tester to perform unified management of the tester, automatic control of the test processes of various models, real-time display of test data, and display and management of test results.
[0003] The centralized control system needs to receive and parse the data of multiple test channels in real time in the background, and pass it to the front-end GUI interface for display. Since the parsing and display of data need to be described by software code, when the amount of data to be processed increases, the parsing and display code also increases greatly, making manual code writing a heavy task. The centralized control system needs to connect to multiple testers, and the data format uploaded by each tester may be different. When the data format changes, the code needs to be rewritten. Summary of the invention
[0004] The technical problem solved by the present invention is: to overcome the shortcomings of the prior art, to provide a method for automatically generating data parsing code and GUI code in an automated test system, which can quickly and accurately generate the required code in batches, improve the development efficiency of the centralized control system, and reduce the error rate of manually written data parsing and display code during the development process.
[0005] The technical solution of the present invention is:
[0006] A method for automatically generating data parsing code and GUI code in an automated test system, comprising:
[0007] (1) Write the configuration file in the specified format;
[0008] (2) The code automatic generation module reads the configuration file and transfers the read information into the cell array defined by the code automatic generation module;
[0009] (3) Generate backend code through the code automatic generation module;
[0010] (4) Generate front-end code through the code automatic generation module;
[0011] (5) Compile and generate .dll files based on the generated front-end code and back-end code for the centralized control system software to call;
[0012] (6) The centralized control system software calls the .dll file to display the tester data received through the TCP-IP protocol.
[0013] Furthermore, the configuration file is written in a specified format, specifically:
[0014] The configuration file includes relevant parameters of multiple channels. The relevant parameters of each channel are the same, which are: channel n name, channel n data length, channel n data starting position, channel n data scaling amount, channel n data offset; n represents the channel number; each line of data in the configuration file is the relevant parameters of a channel.
[0015] Furthermore, the code automatic generation module is written in matlab, and the code automatic generation module includes a front-end code automatic generation unit and a back-end code automatic generation unit.
[0016] Further, the front-end code is generated by the automatic code generation module, that is, the front-end code is generated by the automatic code generation unit, as follows:
[0017] (4.1) Define a cell array in MATLAB. The array has only one column and the data is the channel name. The data in the cell array is read from the configuration file.
[0018] (4.2) Define the starting position of the display controls on the interface, and the row and column spacing between each control;
[0019] (4.3) Write the xaml code required for a display control. The input parameters of the xaml code are the channel name and placement position. The xaml code defines the color and font properties of the variable, as well as the backend variable bound to the control. The channel name required in the xaml code is obtained from the cell array.
[0020] (4.4) Get the coordinates of each control based on the row spacing and column spacing, which is the placement position in the xaml code;
[0021] (4.5) Define the number of controls that can be placed on each page, and automatically switch to the next page when the number exceeds the range;
[0022] (4.6) Write a loop body, the number of loops is the total number of channel names, and generate corresponding xaml code for each channel name to obtain the complete WPF front-end code.
[0023] Further, the backend code is generated by the code automatic generation module, that is, the backend code is generated by the backend code automatic generation unit, as follows:
[0024] (3.1) Define a cell array in MATLAB. The array contains five columns, namely: channel name, channel data length, channel data starting position, channel data scaling, and channel data offset; the data in the cell array is read from the configuration file;
[0025] (3.2) Write a data analysis function. The input parameter of the data analysis function is a cell array. The data analysis function analyzes the data of a channel in the cell array to obtain the actual physical value of the channel.
[0026] (3.3) The actual physical value parsed by the data parsing function corresponds to the backend variable bound to the control in the frontend code, and the backend variable value is passed to the frontend for display, and comments are automatically added to the corresponding code;
[0027] (3.4) The data parsing function is called cyclically to parse all channel data and obtain the C# backend code required for all channel parsing.
[0028] Furthermore, the actual physical value of the channel is calculated in the following manner:
[0029] (1) Obtaining preliminary values: The starting position and length of the data in the cell array are stored in the form of byte data. After locating and extracting the byte sequence from the cell array, the original byte data is converted into preliminary values through a shift operation.
[0030] (2) After obtaining the preliminary value, the value is adjusted according to the data scaling amount and the data offset to obtain the actual physical value of the channel.
[0031] Furthermore, the data scaling amount is used to enlarge or reduce the preliminary value by a certain proportion to reflect its correct magnitude in the actual physical quantity, and the data offset is used to adjust the reference point of the data to ensure that it can accurately correspond to the required physical value; the preliminary value multiplied by the data scaling amount and then subtracted by the data offset is the actual physical value of the channel.
[0032] In a second aspect, the present invention further proposes a processor, which is used to run a program, wherein the program executes the method for automatically generating data parsing code and GUI code in the automated testing system when the program is running.
[0033] In a third aspect, the present invention further proposes a non-volatile storage medium, comprising: a computer program product, which, when executed, executes the method for automatically generating data parsing code and GUI code in the automated testing system.
[0034] In a fourth aspect, the present invention further proposes a computer program product, which, when executed by a processor, implements the method for automatically generating data parsing codes and GUI codes in the automated testing system.
[0035] The beneficial effects of the present invention compared with the prior art are:
[0036] (1) When the method of the present invention is actually applied, when the data structure and format of the tester are changed, it is only necessary to modify the configuration file, and then use the code automatic generation module to generate the code required for data analysis and display, and compile the code to generate a .dll file. The dll file can parse the data uploaded by the tester through the TCP-IP protocol, and the centralized control calls the .dll file to complete the data display. Therefore, when changing to a different type of tester, the centralized control program does not need to be updated, and only the called .dll file needs to be updated.
[0037] (2) The method of the present invention can transform the traditional method of modifying the centralized control program into a method where the centralized control only needs to call different .dll files, which greatly improves the code development efficiency, reduces the error rate, and maintains the stability of the centralized control program version. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a schematic diagram of the traditional data analysis and display method;
[0039] Figure 2 A schematic diagram of a data parsing and display method for an automatic code generation module of the present invention;
[0040] Figure 3 Generate front-end code flow chart for the code automatic generation module;
[0041] Figure 4 Generates backend code flow chart for the code automatic generation module. DETAILED DESCRIPTION
[0042] The specific embodiments of the present invention are further described in detail below with reference to the accompanying drawings.
[0043] The centralized control system needs to receive and parse the data of multiple test channels in real time in the background, and pass it to the front-end GUI interface for display. Since the parsing and display of data need to be described by software code, when the amount of data to be processed increases, the parsing and display code also increases greatly, making manual code writing a heavy task. The centralized control system needs to connect to multiple testers, and the data format uploaded by each tester may be different. When the data format changes, the code needs to be rewritten. Traditional data parsing and display methods such as Figure 1As shown, the name of each channel is specified in the configuration file. By reading the configuration file, the name of each channel is identified, and then the data uploaded by the tester is parsed through the data structure and parsing method specified in the communication protocol file. The channel name and channel data are matched and displayed on the interface. The code for the entire process needs to be written manually, which is prone to errors.
[0044] The present invention proposes a method for automatically generating background parsing code and front-end GUI display code for centralized control system data. A code automatic generation module is written in Matlab. By calling the module to read the configuration file, the front-end and back-end codes are automatically generated to perform data parsing and display without manually writing the corresponding code. When the data formats uploaded by different testers are different, it is only necessary to change the configuration file, use the code automatic generation module to automatically generate the front-end and back-end codes, and compile them into .dll files. The centralized control software calls the .dll file to complete the data display. The development efficiency of the centralized control system is improved, and the error rate of manually writing data processing and display codes during the development process is reduced.
[0045] The principle block diagram of the method for calling the code automatic generation module to perform data analysis and display proposed by the present invention is as follows: Figure 2 As shown, the code generation process is as follows:
[0046] (1) Write the configuration file in accordance with the specified format.
[0047] The configuration file includes relevant parameters of multiple channels. The relevant parameters of each channel are the same, which are: channel n name, channel n data length, channel n data starting position, channel n data scaling amount, channel n data offset; n represents the channel number; each line of data in the configuration file is the relevant parameters of a channel.
[0048] For example, the configuration file format is:
[0049] Channel 1 name Channel 1 data length Channel 1 data start position Channel 1 data scaling Channel 1 data offset
[0050] Channel 2 name Channel 2 data length Channel 2 data starting position Channel 2 data scaling Channel 2 data offset
[0051] …
[0052] Channel n name Channel n data length Channel n data start position Channel n data scaling Channel n data offset
[0053] (2) The automatic code generation module reads the configuration file and passes the read information into the cell array defined by the module.
[0054] (3) The code automatic generation module generates backend code.
[0055] like Figure 4 As shown, the code automatic generation module is written in matlab, and the code automatic generation module includes a front-end code automatic generation unit and a back-end code automatic generation unit. First, all the information in the first line of the configuration file is read, and the channel name, data length, data starting position, data scaling, and data offset are obtained by parsing, and then the C# language parsing code is automatically generated.
[0056] The details are as follows:
[0057] (3.1) Define a cell array in MATLAB. The array contains five columns, namely: channel name, channel data length, channel data starting position, channel data scaling, and channel data offset; the data in the cell array is read from the configuration file;
[0058] (3.2) Write a data analysis function. The input parameter of the data analysis function is a cell array. The data analysis function analyzes the data of a channel in the cell array to obtain the actual physical value of the channel.
[0059] (3.2.1) Obtaining preliminary values: The starting position and length of the data in the cell array are stored in the form of byte data. After locating and extracting the byte sequence from the cell array, the original byte data is converted into preliminary values through shift operations;
[0060] (3.2.2) After obtaining the preliminary value, adjust the value according to the data scaling amount and data offset to obtain the actual physical value of the channel.
[0061] For example, when the data length is 4 bytes, the configuration file parsing method is:
[0062] Actual physical value of channel = (((byte[data starting position])|((byte[data starting position+1])<<8)|((byte[data starting position+2])<<16)|((byte[data starting position+3])<<24))*data scaling amount-data offset.
[0063] When the data length changes, the number of items in the above formula for calculating the preliminary value can be increased or decreased accordingly. << means shifting to the left.
[0064] (3.3) The actual physical value parsed by the data parsing function corresponds to the backend variable bound to the control in the frontend code, and the backend variable value is passed to the frontend for display, and comments are automatically added to the corresponding code;
[0065] (3.4) The data parsing function is called cyclically to parse all channel data and obtain the C# backend code required for all channel parsing.
[0066] (4) The code automatic generation module generates front-end code.
[0067] The code contains the channel name, display box location, properties, etc. When there are many channels, the code volume is huge and needs to be written manually by programmers. The code automatic generation module can automatically generate the above code according to the xaml format.
[0068] like Figure 3 As shown, the details are as follows:
[0069] (4.1) Define a cell array in MATLAB. The array has only one column and the data is the channel name. The data in the cell array is read from the configuration file.
[0070] (4.2) Define the starting position of the display controls on the interface, and the row and column spacing between each control;
[0071] (4.3) Write the xaml code required for a display control. The input parameters of the xaml code are the channel name and placement position. The xaml code defines the color and font properties of the variable, as well as the backend variable bound to the control. The channel name required in the xaml code is obtained from the cell array.
[0072] (4.4) Get the coordinates of each control based on the row spacing and column spacing, which is the placement position in the xaml code;
[0073] (4.5) Define the number of controls that can be placed on each page, and automatically switch to the next page when the number exceeds the range;
[0074] (4.6) Write a loop body, the number of loops is the total number of channel names, and generate corresponding xaml code for each channel name to obtain the complete WPF front-end code.
[0075] (5) The automatically generated front-end and back-end codes are compiled through Visual Studio to generate .dll files for the centralized control software to call.
[0076] (6) The centralized control calls the .dll file to display the tester data received through the TCP-IP protocol.
[0077] Parts of the present invention that are not described in detail belong to common knowledge among those skilled in the art.
Claims
1. A method for automatically generating data parsing code and GUI code in an automated test system. Features include: (1) Write the configuration file in the specified format; (2) The code automatic generation module reads the configuration file and transfers the read information into the cell array defined by the code automatic generation module; (3) Generate backend code through the code automatic generation module; (4) Generate front-end code through the code automatic generation module; (5) Compile and generate .dll files based on the generated front-end code and back-end code for the centralized control system software to call; (6) The centralized control system software calls the .dll file to display the tester data received through the TCP-IP protocol.
2. The method for automatically generating data analysis code and GUI code in an automated test system according to claim 1, Features: The configuration file is written in the prescribed format, specifically: The configuration file includes relevant parameters of multiple channels. The relevant parameters of each channel are the same, which are: channel n name, channel n data length, channel n data starting position, channel n data scaling amount, channel n data offset; n represents the channel number; each line of data in the configuration file is the relevant parameters of a channel.
3. The method for automatically generating data analysis code and GUI code in an automated test system according to claim 1, Features: The code automatic generation module is written in Matlab, and the code automatic generation module includes a front-end code automatic generation unit and a back-end code automatic generation unit.
4. The method for automatically generating data analysis code and GUI code in an automated test system according to claim 3, Features: The front-end code is generated by the automatic code generation module, that is, the front-end code is generated by the automatic code generation unit, as follows: (4.1) Define a cell array in MATLAB. The array has only one column and the data is the channel name. The data in the cell array is read from the configuration file. (4.2) Define the starting position of the display controls on the interface, and the row and column spacing between each control; (4.3) Write the xaml code required for a display control. The input parameters of the xaml code are the channel name and placement position. The xaml code defines the color and font properties of the variable, as well as the backend variable bound to the control. The channel name required in the xaml code is obtained from the cell array. (4.4) Get the coordinates of each control based on the row spacing and column spacing, which is the placement position in the xaml code; (4.5) Define the number of controls that can be placed on each page, and automatically switch to the next page when the number exceeds the range; (4.6) Write a loop body, the number of loops is the total number of channel names, and generate corresponding xaml code for each channel name to obtain the complete WPF front-end code.
5. The method for automatically generating data analysis code and GUI code in an automated test system according to claim 4, Features: The backend code is generated by the code automatic generation module, that is, the backend code is generated by the backend code automatic generation unit, as follows: (3.1) Define a cell array in MATLAB. The array contains five columns, namely: channel name, channel data length, channel data starting position, channel data scaling, and channel data offset; the data in the cell array is read from the configuration file; (3.2) Write a data analysis function. The input parameter of the data analysis function is a cell array. The data analysis function analyzes the data of a channel in the cell array to obtain the actual physical value of the channel. (3.3) The actual physical value parsed by the data parsing function corresponds to the backend variable bound to the control in the frontend code, and the backend variable value is passed to the frontend for display, and comments are automatically added to the corresponding code; (3.4) The data parsing function is called cyclically to parse all channel data and obtain the C# backend code required for all channel parsing.
6. The method for automatically generating data analysis code and GUI code in an automated test system according to claim 5, Features: The actual physical value of the channel is calculated in the following way: (1) Obtaining preliminary values: The starting position and length of the data in the cell array are stored in the form of byte data. After locating and extracting the byte sequence from the cell array, the original byte data is converted into preliminary values through a shift operation. (2) After obtaining the preliminary value, the value is adjusted according to the data scaling amount and the data offset to obtain the actual physical value of the channel.
7. The method for automatically generating data analysis code and GUI code in an automated test system according to claim 6, Features: The data scaling amount is used to enlarge or reduce the preliminary value by a certain ratio to reflect its correct magnitude in the actual physical quantity. The data offset is used to adjust the reference point of the data to ensure that it can accurately correspond to the required physical value. The actual physical value of the channel is obtained by multiplying the preliminary value by the data scaling amount and then subtracting the data offset.
8. A processor, It is characterized in that The processor is used to run a program, wherein the program, when running, executes the method for automatically generating data parsing code and GUI code in an automated testing system according to any one of claims 1 to 7.
9. A non-volatile storage medium, It is characterized in that include: A computer program product, when executed, executes the method for automatically generating data parsing code and GUI code in an automated testing system according to any one of claims 1 to 7.
10. A computer program product, It is characterized in that When the computer program product is executed by a processor, the method for automatically generating data parsing code and GUI code in an automated testing system according to any one of claims 1 to 7 is implemented.
