Method for automatically generating program with interface based on communication protocol
By automatically generating interface programs based on communication protocols, the problem of modification of upper computer software caused by frequent changes in the firmware communication protocol of instruments and equipment is solved, and the automatic generation of upper computer software is realized, and the development efficiency and response speed are improved.
Patent Information
- Application Number
- CN202311381631.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-24
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, the firmware communication protocol of instruments and equipment changes frequently, resulting in frequent modification of the upper computer software, which increases the risk of manual intervention and the inefficient development efficiency.
The method of automatically generating interface programs based on communication protocols is adopted, and the host computer software programs are automatically generated by presetting code fields, generating configuration tables, filling the content of the table header, writing and compiling source code, reducing manual intervention.
It realizes the automatic generation of upper computer software, reduces the need for manual code modification, improves development efficiency and response speed, and reduces labor and time costs.
Smart Images

Figure CN119883246A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of software, and in particular to an interaction method between an instrument and a host computer software. Background Art
[0002] Instruments and equipment all have multiple hardware modules that implement different functions, called firmware. In order to maintain normal communication with the firmware to realize data transmission and reception, the host computer software needs to be consistent with the firmware in the communication protocol. The firmware communication protocol is usually formulated directly by the firmware manufacturer, or by the firmware team during the development and testing phase. During the development and testing phase of the instrument, the firmware communication protocol usually changes due to changes in functional requirements, development defects or fault repairs, so the host computer software needs to modify the code. Otherwise, the inconsistency of the communication protocol between the host computer and the firmware will cause confusion in the transmission and reception and execution of instructions, and ultimately cause the instrument to fail to operate normally.
[0003] In research and development projects, research and development personnel are generally assigned to multiple different professional modules, and the R&D personnel between multiple different professional modules cooperate with each other and are independent of each other. At present, the modification of the host computer software of most instruments and equipment requires programmers to manually modify the communication protocol related codes. That is, when the communication protocol of the firmware changes, professional programmers are required to manually modify the code of the communication protocol part, and then recompile the code to finally generate executable software. Since manual participation in the modification is required, when the protocol is modified frequently and the modification content is complex, the probability of code errors will increase. If problems occur in the compilation process, the manually modified code needs to be manually checked, resulting in secondary labor costs, which seriously affects the efficiency of research and development. Summary of the invention
[0004] In view of the deficiencies in the prior art, the first object of the present invention is to propose a method for automatically generating a program with an interface based on a communication protocol, which can be applied to the research and development stage of instruments and equipment.
[0005] To achieve the above object, the present invention adopts the following technical solution:
[0006] The method for automatically generating a program with an interface based on a communication protocol comprises the following steps:
[0007] S1: According to the corresponding firmware function, preset the code field of the host computer software about the communication protocol, and leave blank the content part of the communication protocol rules about the corresponding firmware function;
[0008] S2: setting a configuration table for each function of each firmware in character form, wherein the configuration table includes a node name in character form corresponding to the communication protocol rule table header of the corresponding firmware function;
[0009] S3: Obtain the communication protocol rule content corresponding to the firmware function, wherein the communication protocol rule content includes a communication protocol rule header and content corresponding to the header; fill the corresponding content of the header of the communication protocol rule corresponding to the firmware function obtained in the form of characters into the node name associated with the configuration table; and obtain a complete configuration table;
[0010] S4: Traverse the complete configuration table obtained in step S3 row by row, and obtain information on the corresponding content of the corresponding table header according to the name of each node;
[0011] S5: Retrieve the code field preset in step S1, and fill in the information corresponding to the content of the header obtained in step S4 into the blank space of the code field to generate a complete source code;
[0012] S6: compile the source code obtained in step S5 to generate a program;
[0013] S7: When the communication protocol of the corresponding firmware function changes, repeat steps S2 to S6.
[0014] A further technical solution is that in step S3, the corresponding content of the header of the communication protocol rules corresponding to the firmware function obtained is filled in the configuration table in the form of characters at the node name associated with the configuration table. Specifically, the corresponding content of the header of the communication protocol rules corresponding to the firmware function obtained is copied to the node name associated with the configuration table.
[0015] A further technical solution is that the character form in step S2 is specifically a code character form of the same programming language as the code used in step S5.
[0016] A further technical solution is that the character form in step S2 is specifically a code character form of a programming language different from the code used in step S5.
[0017] A further technical solution is that the code field preset in step S1 includes code statements of the production interface.
[0018] A further technical solution is that the code field preset in step S1 includes a code statement for returning error feedback.
[0019] The beneficial effects of the present invention are:
[0020] The automatic generation of the program of the host computer software of the present invention only depends on the configuration table file, the writing steps of the source code in the process, and the compilation operation of the source code are all hidden, and the writing of the configuration file does not have too high technical relevance. Even if the modification frequency of the communication protocol is very high, it is also possible to quickly respond to interface changes, thereby quickly debugging and accelerating production efficiency. Whether from the perspective of labor cost or time cost, a great efficiency improvement is obtained. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] Figure 1 It is a schematic diagram of the process of the present invention;
[0022] Figure 2 This is an example diagram of the firmware functional protocol content;
[0023] Figure 3 is an example diagram of a configuration table. DETAILED DESCRIPTION
[0024] Below, in conjunction with the accompanying drawings and specific embodiments, the present invention is further described:
[0025] like Figure 1 As shown, taking the development and testing of a transmission electron microscope as an example, the algorithm flow chart of the method for automatically generating a program with an interface based on a communication protocol of the present invention includes the following steps:
[0026] S1: According to the corresponding firmware function, preset the code field of the host computer software regarding the communication protocol, and leave blank the content part of the communication protocol rules regarding the corresponding firmware function.
[0027] S2: Setting a configuration table in character form for each function of each firmware, wherein the configuration table includes a node name in character form corresponding to the communication protocol rule table header of the corresponding firmware function. Figure 2 The figure shows the content of a functional protocol provided by a firmware module of an electron microscope, wherein the first line is a communication protocol rule header, and the node name in the configuration table is set according to the content of the header. For example, in this embodiment, for the header content of "main command", the node name in the configuration table is set to "MainCommand", and for the header content of "synchronous frame", the node name in the configuration table is set to "SyncFrame". Figure 3 For the entire instrument, it is only necessary to obtain and set the configuration table for each firmware and each function.
[0028] S3: Obtain the communication protocol rule content corresponding to the firmware function, wherein the communication protocol rule content includes a communication protocol rule header and content corresponding to the header, such as Figure 2 As shown, the communication protocol rules are provided by the firmware manufacturer or the firmware development team; the corresponding content of the header of the communication protocol rules corresponding to the firmware function is filled in the configuration table in the form of characters and is associated with the node name. For example, in this embodiment, the content "0x32" corresponding to the "main command" is filled in the node name "MainCommand" associated with the "main command" in the configuration table to form the content ""MainCommand":"0x32"". When all the node names are filled in, a complete configuration table is obtained, as shown in FIG. Figure 3The example shown is a complete configuration table. This step can be implemented manually, and it can be realized by simply informing the executor of the correspondence between the table header and the node name. The executor does not need professional programming knowledge, which reduces the difficulty and labor cost of staffing. On the other hand, this step can also be implemented in an automated way, such as obtaining the communication protocol rule content from the firmware manual provided by the manufacturer through image recognition, or grabbing the content from the firmware's communication protocol rule document through text capture. After the content is obtained, the configuration table is completed by character matching. Preferably, the corresponding content of the table header of the communication protocol rule corresponding to the firmware function is copied to the associated node name in the configuration table. Direct copying can further simplify the workload and improve efficiency.
[0029] S4: Traverse the complete configuration table obtained in step S3 line by line, and obtain the information of the corresponding content of the corresponding table header according to the name of each node; since the computer-implemented algorithm is not directly obtained by humans, but is implemented through logical operations, and computers can only understand mechanical language, the role of this step is to translate the field content understood by humans into code fragments that can be read by machines.
[0030] S5: Retrieve the code field preset in step S1, and fill in the information corresponding to the content of the header obtained from step S4 into the blank space of the code field to generate a complete source code. Among them, the character form in step S2 can specifically be a code character form of the same programming language as the code used in step S5, so that the obtained information is the code field, further simplifying the operation and improving efficiency. Code character forms of different programming languages can also be used to improve versatility, reduce the difficulty of operation in the previous step S2, and further reduce labor costs. Furthermore, the code field preset in step S1 includes code statements for the production interface, and / or the code field preset in step S1 includes code statements for returning error feedback, so that the program obtained after compilation has an operation interface, which is convenient for human-computer interaction, and can provide feedback to the operator when data or quality errors occur.
[0031] S6: compile the source code obtained in step S5 to generate a program; this step can be implemented by a compiler of the operating system, such as "Microsoft Visual Studio" software, to compile the source code into a usable program.
[0032] S7: When the communication protocol of the corresponding firmware function changes, repeat steps S2 to S6, among which only step S2 may require human intervention, which greatly reduces the difficulty of reprogramming the upper computer software due to the change of the firmware function communication protocol.
[0033] The above description is only a preferred embodiment of the present invention, which is a further detailed description of the present invention in combination with a specific preferred embodiment, and the specific implementation of the present invention cannot be considered to be limited to these descriptions. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for automatically generating a program with an interface based on a communication protocol, characterized in that: The steps include: S1: According to the corresponding firmware function, preset the code field of the host computer software about the communication protocol, and leave blank the content part of the communication protocol rules about the corresponding firmware function; S2: setting a configuration table for each function of each firmware in character form, wherein the configuration table includes a node name in character form corresponding to the communication protocol rule table header of the corresponding firmware function; S3: Obtain the communication protocol rule content corresponding to the firmware function, wherein the communication protocol rule content includes a communication protocol rule header and content corresponding to the header; fill the corresponding content of the header of the communication protocol rule corresponding to the firmware function obtained in the form of characters into the node name associated with the configuration table; Get the complete configuration table; S4: Traverse the complete configuration table obtained in step S3 row by row, and obtain information on the corresponding content of the corresponding table header according to the name of each node; S5: Retrieve the code field preset in step S1, and fill in the information corresponding to the content of the header obtained in step S4 into the blank space of the code field to generate a complete source code; S6: compile the source code obtained in step S5 to generate a program; S7: When the communication protocol of the corresponding firmware function changes, repeat steps S2 to S6.
2. The method for automatically generating a program with an interface based on a communication protocol according to claim 1, characterized in that: In the step S3, the corresponding content of the header of the communication protocol rules corresponding to the firmware function is filled in the configuration table in the form of characters at the node name associated with the configuration table. Specifically, the corresponding content of the header of the communication protocol rules corresponding to the firmware function is copied to the node name associated with the configuration table.
3. The method for automatically generating a program with an interface based on a communication protocol according to claim 2, characterized in that: The character form in step S2 is specifically a code character form of the same programming language as the code used in step S5.
4. The method for automatically generating a program with an interface based on a communication protocol according to claim 1, characterized in that: The character form in step S2 is specifically a code character form of a programming language different from the code used in step S5.
5. The method for automatically generating a program with an interface based on a communication protocol according to claim 1, characterized in that: The code field preset in step S1 includes code statements of the production interface.
6. The method for automatically generating a program with an interface based on a communication protocol according to claim 1, characterized in that: The code field preset in step S1 includes a code statement for returning error feedback.