Methods for generating code based on sensor I / O device description files and related equipment
Through artificial intelligence models, the IO device description files are analyzed and sensor codes are generated, which solves the problems of inefficiency and high error rates of traditional methods, and realizes efficient and reliable code generation, reducing technical costs.
Patent Information
- Application Number
- CN202411397891.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-09
- Publication Date
- 2024-12-31
- Estimated Expiration
- 2044-10-09
AI Technical Summary
The IO device description file generation code of traditional IO-Link sensors is inefficient and has high error rates, resulting in increased technical development and maintenance costs.
The artificial intelligence model is used to analyze the sensor IO device description file, and the target code file is generated through the twin network and the code generation template generator to improve the efficiency and accuracy of code generation.
It significantly improves the efficiency of sensor code generation, reduces error rate and labor costs, and enhances the reliability and stability of the sensor.
Smart Images

Figure CN118897680B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of sensor technology, and in particular to a method for generating code according to a sensor IO device description file and related equipment. Background Art
[0002] With the continuous improvement of industrial automation and intelligence, various sensors are being used more and more in industrial scenarios. IO-Link sensors are being used more widely due to their efficient and reliable data transmission and intelligent device integration capabilities. Among them, the IODD (IO Device Description) file is a file that describes the functions and characteristics of IO-Link sensor devices, that is, the sensor IO device description file, which contains information data such as technical parameters, function description, data structure, and communication protocol of the sensor device. The control system can correctly identify, configure, and apply the corresponding IO-Link sensor through the sensor IO device description file. However, after the IO device description file of the traditional IO-Link sensor is defined, it is necessary to perform corresponding manual programming according to the IO device description file. On the one hand, manual programming is not only inefficient, but also has a high probability of error in the sensor code obtained by manual programming. On the other hand, the models and functions of IO-Link sensors are constantly increasing, and the content and number of the corresponding IO device description files are also increasing, which further leads to an increase in the workload of manual programming, which significantly increases the cost of technical development and subsequent technical maintenance costs. Summary of the invention
[0003] The main technical problem solved by the implementation methods of the present application is that the traditional method of generating codes according to the sensor IO device description file has a high probability of code errors, low efficiency and high technical costs.
[0004] In order to solve the above technical problems, the first technical solution adopted in the implementation mode of the present application is: providing a method for generating code according to a sensor IO device description file, including: obtaining the IO device description file of the target sensor; sending the IO device description file to a preset device description file parsing model for parsing to obtain the IO device description data corresponding to the target sensor; matching the corresponding code generation template according to the IO device description data and the communication protocol of the target sensor; generating the target code file corresponding to the target sensor according to the code generation template and the target code type.
[0005] Optionally, the training process of the preset device description file parsing model includes: obtaining the historical IO device description file of the historical sensor, and the corresponding sensor historical code; respectively extracting the first feature data of the historical IO device description file, and the second feature data of the sensor historical code; inputting the first feature data and the second feature data into the preset twin network to obtain the correlation data output by the twin network, and adjusting the parameters of the twin network according to the correlation data obtained by iterative training; using a preset loss function to calculate the corresponding correlation loss according to the correlation data, and optimizing the parameters of the device description file parsing model according to the correlation loss; repeating the steps from inputting the first feature data and the second feature data into the preset twin network to optimizing the parameters of the device description file parsing model according to the correlation loss, until the loss function converges to obtain the trained device description file parsing model.
[0006] Optionally, the step of extracting the first characteristic data of the historical IO device description file includes: parsing the historical IO device description file to obtain device identification data, device function data and communication network data corresponding to the historical sensor; generating a corresponding device feature matrix according to the device identification data, the device function data and the communication network data; and setting the device feature matrix to the first characteristic data.
[0007] Optionally, before the step of obtaining the IO device description file of the target sensor, it also includes: obtaining the sensor historical code corresponding to the historical sensor; extracting the code feature data of the sensor historical code, sending the code feature data to a preset clustering algorithm to obtain the corresponding feature code clustering cluster; training corresponding different code template generators through different feature code clustering clusters, wherein the code template generator is a code generation model constructed according to a neural network; calculating the corresponding loss data through a loss function preset by the code generation model, and optimizing the parameters of the code template generator according to the loss data; repeating the steps from training corresponding different code template generators through different feature code clustering clusters to optimizing the parameters of the code template generator according to the loss data until the loss function converges to obtain a trained code template generator; sending the sensor historical code to the code template generator to obtain different code generation templates output by the code template generator.
[0008] Optionally, after the step of generating the target code file corresponding to the target sensor according to the code generation template and the target code type, it also includes: obtaining standard test data corresponding to the communication protocol of the target sensor, verifying the target code file through the standard test data, and obtaining a first code test result; sending the target code file to a pre-deployed sensor test environment for testing, and obtaining a second code test result, wherein the pre-deployed sensor test environment includes a sensor of the same type or model as the target sensor, and the second code test result includes a sensor basic information acquisition code test result and a sensor business function code test result; if the first code test result or the second code test result is a test failure, re-execute the steps from sending the IO device description file to a preset device description file parsing model for parsing to obtaining the second code test result, until both the first code test result and the second code test result are test successes.
[0009] Optionally, after the step of generating the target code file corresponding to the target sensor according to the code generation template and the target code type, it also includes: storing the IO device description file of the target sensor and the corresponding generated target code file; regularly detecting whether the IO device description file is updated from the source address of the IO device description file of the target sensor; if updated, re-executing the steps from obtaining the IO device description file of the target sensor to storing the IO device description file of the target sensor and the corresponding generated target code file.
[0010] Optionally, after the step of generating a target code file corresponding to the target sensor according to the code generation template and the target code type, it also includes: using the target code file to replace the sensor historical code; repeating the steps of extracting the code feature data of the sensor historical code to obtaining the different code generation templates output by the code template generator.
[0011] In order to solve the above technical problems, the second technical solution adopted in the implementation mode of the present application is: to provide a device for generating code according to a sensor IO device description file, including: a file data receiving module, used to obtain the IO device description file of the target sensor; a file data parsing module, used to send the IO device description file to a preset device description file parsing model for parsing, and obtain the IO device description data corresponding to the target sensor; a code template matching module, used to match the corresponding code generation template according to the IO device description data and the communication protocol of the target sensor; a sensor code generation module, used to generate a target code file corresponding to the target sensor according to the code generation template and the target code type.
[0012] To solve the above technical problems, the third technical solution adopted in the implementation manner of the present application is: to provide an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for generating code according to the sensor IO device description file as described above.
[0013] In order to solve the above technical problems, the fourth technical solution adopted in the implementation mode of the present application is: providing a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are executed by an electronic device, the electronic device executes the method of generating code according to the sensor IO device description file as described above.
[0014] Different from the related art, the present application generates the corresponding target sensor code after parsing the sensor IO device description file through an artificial intelligence model, which not only improves the efficiency of sensor code generation, reduces the error rate and labor cost of the sensor code, but also further improves the reliability and stability of the sensor. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] One or more embodiments are exemplarily described by corresponding drawings, which do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and the figures in the drawings do not constitute proportional limitations unless otherwise stated.
[0016] Figure 1 It is a schematic diagram of the application environment of the method for generating code according to the sensor IO device description file provided in an embodiment of the present application.
[0017] Figure 2 It is a schematic diagram of the execution flow of the method for generating code according to the sensor IO device description file provided in an embodiment of the present application.
[0018] Figure 3 It is a schematic diagram of the training process of the device description file parsing model provided in an embodiment of the present application.
[0019] Figure 4 It is a schematic diagram of the execution flow of obtaining different code generation templates provided in an embodiment of the present application.
[0020] Figure 5 It is a structural diagram of an apparatus for generating code according to a sensor IO device description file provided in an embodiment of the present application.
[0021] Figure 6 Schematic diagram of the hardware structure of an electronic device 600 for executing the method for generating code according to a sensor IO device description file provided in an embodiment of the present application. DETAILED DESCRIPTION
[0022] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0023] It should be noted that, if there is no conflict, the various features in the embodiments of the present application can be combined with each other, all within the scope of protection of the present application. In addition, although the functional modules are divided in the device schematic diagram and the logical order is shown in the flow chart, in some cases, the steps shown or described can be performed in a different order than the module division in the device schematic diagram or the order in the flow chart.
[0024] Unless otherwise defined, all technical and scientific terms used in this specification have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The term "and / or" used in this specification includes any and all combinations of one or more of the related listed items.
[0025] To facilitate understanding of the present embodiment, a method for generating code according to a sensor IO device description file disclosed in an embodiment of the present application is first introduced in detail. The executor of the method for generating code according to a sensor IO device description file provided in the embodiment of the present application is generally an electronic device with certain computing capabilities, such as a computer device. In some possible implementation methods, the method for generating code according to a sensor IO device description file can be implemented by a processor calling computer-readable instructions stored in a memory.
[0026] The following is an example of a computer device as the execution subject to illustrate the method of generating code according to the sensor IO device description file provided in the embodiment of the present application. Figure 1 , Figure 1 is a schematic diagram of an application environment of a method for generating code according to a sensor IO device description file provided in an embodiment of the present application, Figure 1The computer devices in the above can be, but are not limited to, various personal computers and laptops. The computer devices can also be servers. The servers can be independent servers or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDNs), and big data and artificial intelligence platforms. It is understandable that Figure 1 The number of computer devices in the figure is only for reference and can be expanded to any number according to actual needs.
[0027] Please continue reading Figure 2 , Figure 2 is a schematic diagram of the execution flow of the method for generating code according to the sensor IO device description file provided in an embodiment of the present application, such as Figure 2 As shown, including:
[0028] S1. Obtain the IO device description file of the target sensor.
[0029] Among them, the information contained in the sensor's IO device description file includes communication protocol, device parameters, identification data, process data and diagnostic data, as well as device images and manufacturer information.
[0030] S2. Send the IO device description file to a preset device description file parsing model for parsing to obtain IO device description data corresponding to the target sensor.
[0031] As a preferred implementation, please continue to refer to Figure 3 , Figure 3 is a schematic diagram of the training process of the device description file parsing model provided in the embodiment of the present application, such as Figure 3 As shown, the training process includes:
[0032] S21. Obtain a historical IO device description file of a historical sensor and a corresponding sensor historical code.
[0033] S22, respectively extracting the first characteristic data of the historical IO device description file and the second characteristic data of the sensor historical code.
[0034] As another preferred embodiment, the step of extracting the first characteristic data of the historical IO device description file includes: first, parsing the historical IO device description file to obtain the device identification data, device function data and communication network data corresponding to the historical sensor. Among them, the device identification data may include but is not limited to: device name, device logo, manufacturer name. Device function data includes but is not limited to: process data, service data and event data. Communication network data includes but is not limited to: network structure data, baud rate data, shortest cycle time data. Then, a corresponding characteristic matrix is generated based on the device identification data, device function data and communication network data obtained by parsing. Among them, the characteristic matrix contains at least three characteristic vectors, and the device identification data, device function data and communication network data respectively correspond to at least one characteristic vector. Finally, the device characteristic matrix is set to the above-mentioned first characteristic data.
[0035] S23, input the first feature data and the second feature data into the preset twin network, obtain the correlation data output by the twin network, and adjust the parameters of the twin network according to the correlation data obtained by iterative training.
[0036] Among them, in the preset Siamese Network, the first sub-network is used to process the above-mentioned first characteristic data, that is, to obtain the characteristics of the historical IO device description file, and the second sub-network is used to process the above-mentioned second characteristic data, that is, to obtain the characteristics of the corresponding historical code, and then the correlation data between the first characteristic data and the second characteristic data is obtained through the preset Siamese Network. Among them, it should be specially noted that during the training process, it is necessary to ensure that the correlation between the above-mentioned historical IO device description file and the corresponding sensor historical code is the highest, and the correlation between the above-mentioned historical IO device description file and other non-corresponding sensor historical codes should be significantly reduced. According to the aforementioned correlation requirements, the parameters of the twin network are adjusted in the above-mentioned iterative training process.
[0037] S24. Calculate the corresponding correlation loss according to the correlation data using a preset loss function, and optimize the parameters of the device description file parsing model according to the correlation loss.
[0038] S25. Determine whether the preset loss function converges. If the preset loss function does not converge, jump to execute the above step S22, that is, repeat the above steps of inputting the first feature data and the second feature data to the preset twin network to the above steps of optimizing the parameters of the device description file parsing model according to the correlation loss. If the preset loss function has converged, jump to execute step S26.
[0039] S26, obtaining a trained device description file parsing module.
[0040] S3. Match the corresponding code generation template according to the IO device description data and the communication protocol of the target sensor.
[0041] As a preferred implementation, please continue to refer to Figure 4 , Figure 4 is a schematic diagram of the execution flow of obtaining different code generation templates provided in the embodiment of the present application, such as Figure 4 As shown, incl.
[0042] S31. Obtain a sensor history code corresponding to the history sensor.
[0043] S32, extracting code feature data of the sensor's historical code, sending the code feature data to a preset clustering algorithm, and obtaining a corresponding feature code clustering cluster.
[0044] S33. Training different code template generators corresponding to different feature code clusters, wherein the code template generator is a code generation model constructed based on a neural network.
[0045] S34. Calculate the corresponding loss data through the loss function preset by the code generation model, and optimize the parameters of the code template generator according to the loss data.
[0046] S35, determine whether the loss function converges. If the loss function does not converge, jump to execute the above step S33, that is, repeat the above steps of training different code template generators corresponding to different feature code clustering clusters to the preset twin network to optimizing the parameters of the code template generator according to the loss data. If the loss function has converged, jump to execute step S36.
[0047] S36. Obtain a trained code template generator.
[0048] S37. Send the sensor historical code to the code template generator to obtain different code generation templates output by the code template generator.
[0049] Among them, the code features of the sensor's historical codes are first extracted, and then clustered according to the code features. The historical codes with high code feature similarity can be divided together, and then a more general type of code template is generated, which can be more efficient and convenient in the subsequent reverse use (i.e., generating the corresponding sensor code according to the code generation template), and obtain higher code accuracy.
[0050] S4. Generate a target code file corresponding to the target sensor according to the code generation template and the target code type.
[0051] As a preferred implementation, after obtaining the corresponding target code file, the target code file can also be tested to improve the stability and security of the target code file before it is applied to the sensor. Specifically, obtain the specification test data corresponding to the communication protocol of the target sensor, such as the corresponding IO-Link communication protocol, verify the target code file through the specification test data, and obtain the first code test result. Then, send the target code file to the pre-deployed sensor test environment for testing, for example, verify whether the sensor code can obtain the corresponding distance voltage value, NTC (Negative Temperature Coefficient) temperature value, object state, etc. during execution through the test environment, and obtain the second code test result, wherein the pre-deployed sensor test environment includes a sensor of the same type or model as the target sensor, and the second code test result includes the sensor basic information acquisition code test result and the sensor business function code test result, the sensor basic information acquisition code is used to obtain the basic information of the sensor, such as the sensor manufacturer identity information, the sensor product name, model, communication rate, etc., and the sensor business function code is used to implement the business function of the sensor, for example, for an inductive sensor, the business function generally includes but is not limited to: temperature detection, alarm, switch type configuration, switch action number record, switch delay setting, etc. Finally, if the first code test result or the second code test result is a test failure, the steps of sending the IO device description file to the preset device description file parsing model for parsing to obtain the second code test result are re-executed until both the first code test result and the second code test result are test successes.
[0052] As a preferred implementation, after the above step S4, the IO device description file of the target sensor and the corresponding generated target code file are stored. Then, a corresponding timed detection task is generated and started, and the IO device description file of the target sensor is regularly detected from the source address, such as the corresponding FTP file storage network address, to see whether the IO device description file has been updated. Finally, if the IO device description file has been updated, for example, the file modification date corresponding to the source address is later than the date of the previously received file, or the file version corresponding to the source address is greater than the version of the previously received file, then the steps from obtaining the IO device description file of the target sensor to storing the IO device description file of the target sensor and the corresponding generated target code file are re-executed.
[0053] In addition, after the corresponding target code file is generated and stored, the target code file can also be manually modified accordingly. For example, the corresponding technician manually modifies the generated sensor target code file. Not only can the generated sensor target code file be manually reviewed and corrected, but also manual secondary development can be performed based on the generated sensor target code file to realize more sensor functions.
[0054] As another preferred implementation, after the above step S4, the sensor target code file obtained can also be used to replace the above sensor historical code. Then, the steps of extracting the code feature data of the sensor historical code to obtaining the different code generation templates output by the code template generator are repeated, that is, the training process of the code template generator is further optimized using the generated target code file to obtain a code generation template with better generalization ability and more optimization.
[0055] The method for generating code according to the sensor IO device description file provided in the embodiment of the present application is to obtain the IO device description file of the target sensor; send the IO device description file to a preset device description file parsing model for parsing to obtain the IO device description data corresponding to the target sensor; match the corresponding code generation template according to the IO device description data and the communication protocol of the target sensor; generate the target code file corresponding to the target sensor according to the code generation template and the target code type. After parsing the sensor IO device description file through an artificial intelligence model, the corresponding target sensor code is generated, which not only improves the efficiency of sensor code generation, reduces the error rate and labor cost of sensor code, but also further improves the reliability and stability of the sensor.
[0056] Please continue reading Figure 5 , Figure 5 is a schematic diagram of the structure of an apparatus for generating code according to a sensor IO device description file provided in an embodiment of the present application, such as Figure 5 As shown, the device 50 comprises:
[0057] The file data receiving module 51 is used to obtain the IO device description file of the target sensor;
[0058] A file data parsing module 52, used for sending the IO device description file to a preset device description file parsing model for parsing, to obtain IO device description data corresponding to the target sensor;
[0059] A code template matching module 53, used to match a corresponding code generation template according to the IO device description data and the communication protocol of the target sensor;
[0060] The sensor code generation module 54 is used to generate a target code file corresponding to the target sensor according to the code generation template and the target code type.
[0061] As an optional implementation, the device 50 for generating code based on the sensor IO device description file also includes a first model training module, which is used to obtain the historical IO device description file of the historical sensor and the corresponding sensor historical code; respectively extract the first feature data of the historical IO device description file and the second feature data of the sensor historical code; input the first feature data and the second feature data to the preset twin network to obtain the correlation data output by the twin network, and adjust the parameters of the twin network according to the correlation data obtained by iterative training; use a preset loss function to calculate the corresponding correlation loss according to the correlation data, and optimize the parameters of the device description file parsing model according to the correlation loss; repeat the steps from inputting the first feature data and the second feature data to the preset twin network to optimizing the parameters of the device description file parsing model according to the correlation loss, until the loss function converges to obtain the trained device description file parsing model.
[0062] As an optional implementation, the first model training module is also used to parse the historical IO device description file to obtain the device identification data, device function data and communication network data corresponding to the historical sensor; generate a corresponding device feature matrix based on the device identification data, the device function data and the communication network data; and set the device feature matrix to the first feature data.
[0063] As an optional implementation, the device 50 for generating code according to the sensor IO device description file also includes a code generation template module, which is used to obtain the sensor historical code corresponding to the historical sensor; extract the code feature data of the sensor historical code, send the code feature data to a preset clustering algorithm, and obtain the corresponding feature code clustering cluster; train different code template generators corresponding to different feature code clustering clusters, wherein the code template generator is a code generation model constructed according to a neural network; calculate the corresponding loss data through a loss function preset by the code generation model, and optimize the parameters of the code template generator according to the loss data; repeat the steps between training the different code template generators corresponding to different feature code clustering clusters and optimizing the parameters of the code template generator according to the loss data, until the loss function converges to obtain a trained code template generator; send the sensor historical code to the code template generator to obtain different code generation templates output by the code template generator.
[0064] As an optional implementation, the sensor code generation module 54 is also used to obtain standard test data corresponding to the communication protocol of the target sensor, verify the target code file through the standard test data, and obtain a first code test result; send the target code file to a pre-deployed sensor test environment for testing, and obtain a second code test result, wherein the pre-deployed sensor test environment includes a sensor of the same type or model as the target sensor, and the second code test result includes a sensor basic information acquisition code test result and a sensor business function code test result; if the first code test result or the second code test result is a test failure, then re-execute the steps from sending the IO device description file to a preset device description file parsing model for parsing to obtaining the second code test result, until both the first code test result and the second code test result are test successes.
[0065] As an optional implementation, the sensor code generation module 54 is also used to store the IO device description file of the target sensor and the corresponding generated target code file; periodically detect whether the IO device description file is updated from the source address of the IO device description file of the target sensor; if updated, re-execute the steps from obtaining the IO device description file of the target sensor to storing the IO device description file of the target sensor and the corresponding generated target code file.
[0066] As an optional implementation, the sensor code generation module 54 is also used to replace the sensor historical code with the target code file; repeatedly execute the steps of extracting the code feature data of the sensor historical code to obtaining the different code generation templates output by the code template generator.
[0067] It should be noted that the above-mentioned device for generating code according to the sensor IO device description file can execute the method for generating code according to the sensor IO device description file provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in the embodiment of the device for generating code according to the sensor IO device description file, please refer to the method for generating code according to the sensor IO device description file provided in the embodiment of the present application.
[0068] Please continue reading Figure 6 , Figure 6 is a schematic diagram of the hardware structure of an electronic device 600 for executing a method for generating code according to a sensor IO device description file provided in an embodiment of the present application, such as Figure 6 As shown, the electronic device 600 includes:
[0069] One or more processors 610 and memory 620, Figure 6 A processor 610 is taken as an example.
[0070] The processor 610 and the memory 620 may be connected via a bus or other means. Figure 6 The example of connecting through bus is taken in the following.
[0071] The memory 620, as a non-volatile computer-readable storage medium, can be used to store non-volatile software programs, non-volatile computer executable programs and modules, such as program instructions / modules corresponding to the method for generating code according to the sensor IO device description file in the embodiment of the present application. The processor 610 executes various functional applications and data processing of the server by running the non-volatile software programs, instructions and modules stored in the memory 620, that is, the method for generating code according to the sensor IO device description file in the above method embodiment is realized.
[0072] The memory 620 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required by at least one function; the data storage area may store data created by the use of a device that generates code according to a sensor IO device description file, etc. In addition, the memory 620 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other non-volatile solid-state storage device. In some embodiments, the memory 620 may optionally include a memory remotely arranged relative to the processor 610, and these remote memories may be connected to the device that generates code according to the sensor IO device description file via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0073] The one or more modules are stored in the memory 620, and when executed by the one or more processors 610, the method of generating code according to the sensor IO device description file in any of the above method embodiments is executed, for example, the method described above is executed. Figure 2 Steps S1 to S4 of the method, Figure 3 Steps S21 to S26 of the method, Figure 4 Steps S31 to S37 of the method are implemented Figure 5 The functions of modules 51-54 in.
[0074] The above-mentioned product can execute the method provided in the embodiment of the present application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in this embodiment, please refer to the method provided in the embodiment of the present application.
[0075] The embodiment of the present application provides a non-volatile computer-readable storage medium, wherein the non-volatile computer-readable storage medium stores computer-executable instructions, and the computer-executable instructions are executed by one or more processors, such as Figure 6 A processor 610 in the embodiment may enable the one or more processors to execute the method for generating code according to the sensor IO device description file in any of the above method embodiments, for example, executing the above described Figure 2 Steps S1 to S4 of the method, Figure 3 Steps S21 to S26 of the method, Figure 4 Steps S31 to S37 of the method are implemented Figure 5 The functions of modules 51-54 in.
[0076] The present application provides a computer program product, wherein the computer program product includes a computer program stored on a non-volatile computer-readable storage medium, wherein the computer program includes program instructions, and when the program instructions are executed by the electronic device, the electronic device is enabled to execute the method for generating code according to the sensor IO device description file in any of the above method embodiments, for example, to execute the above described Figure 2 Steps S1 to S4 of the method, Figure 3 Steps S21 to S26 of the method, Figure 4 Steps S31 to S37 of the method are implemented Figure 5 The functions of modules 51-54 in.
[0077] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0078] Through the description of the above embodiments, it can be clearly understood by those skilled in the art that each embodiment can be implemented by means of software plus a general hardware platform, or by hardware. It can be understood by those skilled in the art that all or part of the processes in the above embodiment methods can be completed by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0079] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Under the concept of the present application, the technical features in the above embodiments or different embodiments can also be combined, the steps can be implemented in any order, and there are many other changes in different aspects of the present application as described above, which are not provided in detail for the sake of simplicity. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments can still be modified, or some of the technical features can be replaced by equivalents. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for generating code according to a sensor IO device description file, characterized in that: include: Get the IO device description file of the target sensor; Sending the IO device description file to a preset device description file parsing model for parsing to obtain IO device description data corresponding to the target sensor; Matching a corresponding code generation template according to the IO device description data and the communication protocol of the target sensor; Generate a target code file corresponding to the target sensor according to the code generation template and the target code type; Among them, the training process of the preset device description file parsing model includes: obtaining the historical IO device description file of the historical sensor, and the corresponding sensor historical code; respectively extracting the first feature data of the historical IO device description file, and the second feature data of the sensor historical code; inputting the first feature data and the second feature data into the preset twin network to obtain the correlation data output by the twin network, and adjusting the parameters of the twin network according to the correlation data obtained by iterative training; using a preset loss function to calculate the corresponding correlation loss according to the correlation data, and optimizing the parameters of the device description file parsing model according to the correlation loss; repeating the steps between inputting the first feature data and the second feature data into the preset twin network and optimizing the parameters of the device description file parsing model according to the correlation loss, until the loss function converges, and the trained device description file parsing model is obtained; Wherein, before the step of obtaining the IO device description file of the target sensor, it also includes: obtaining the sensor historical code corresponding to the historical sensor; extracting the code feature data of the sensor historical code, sending the code feature data to a preset clustering algorithm to obtain the corresponding feature code clustering cluster; training corresponding different code template generators through different feature code clustering clusters, wherein the code template generator is a code generation model constructed according to a neural network; calculating the corresponding loss data through a loss function preset by the code generation model, and optimizing the parameters of the code template generator according to the loss data; repeating the steps from training corresponding different code template generators through different feature code clustering clusters to optimizing the parameters of the code template generator according to the loss data until the loss function converges to obtain a trained code template generator; sending the sensor historical code to the code template generator to obtain different code generation templates output by the code template generator; Among them, the step of extracting the first characteristic data of the historical IO device description file includes: parsing the historical IO device description file to obtain the device identification data, device function data and communication network data corresponding to the historical sensor; generating a corresponding device feature matrix according to the device identification data, the device function data and the communication network data; and setting the device feature matrix as the first characteristic data.
2. The method for generating code according to the sensor IO device description file according to claim 1, characterized in that: After the step of generating the target code file corresponding to the target sensor according to the code generation template and the target code type, the method further includes: Acquire standard test data corresponding to the communication protocol of the target sensor, verify the target code file through the standard test data, and obtain a first code test result; Sending the target code file to a pre-deployed sensor test environment for testing to obtain a second code test result, wherein the pre-deployed sensor test environment includes a sensor of the same type or model as the target sensor, and the second code test result includes a sensor basic information acquisition code test result and a sensor business function code test result; If the first code test result or the second code test result is a test failure, the steps of sending the IO device description file to the preset device description file parsing model for parsing to obtaining the second code test result are re-executed until the first code test result and the second code test result are both tested successfully.
3. The method for generating code according to the sensor IO device description file according to claim 1, characterized in that: After the step of generating the target code file corresponding to the target sensor according to the code generation template and the target code type, the method further includes: Storing the IO device description file of the target sensor and the corresponding generated target code file; Periodically detecting whether the IO device description file of the target sensor is updated from a source address of the IO device description file; If updated, the steps from obtaining the IO device description file of the target sensor to storing the IO device description file of the target sensor and the corresponding generated target code file are re-executed.
4. The method for generating code according to the sensor IO device description file according to claim 1, characterized in that: After the step of generating the target code file corresponding to the target sensor according to the code generation template and the target code type, the method further includes: Using the target code file to replace the sensor history code; Repeat the steps of extracting the code feature data of the sensor historical code to obtaining the different code generation templates output by the code template generator.
5. A device for generating code according to a sensor IO device description file, characterized in that: include: A file data receiving module, used to obtain the IO device description file of the target sensor; A file data parsing module, used for sending the IO device description file to a preset device description file parsing model for parsing, to obtain IO device description data corresponding to the target sensor; A code template matching module, used to match a corresponding code generation template according to the IO device description data and the communication protocol of the target sensor; A sensor code generation module, used to generate a target code file corresponding to the target sensor according to the code generation template and the target code type; The first model training module is used to obtain the historical IO device description file of the historical sensor and the corresponding sensor historical code; respectively extract the first feature data of the historical IO device description file and the second feature data of the sensor historical code; input the first feature data and the second feature data to the preset twin network to obtain the correlation data output by the twin network, and adjust the parameters of the twin network according to the correlation data obtained by iterative training; use the preset loss function to calculate the corresponding correlation loss according to the correlation data, and optimize the parameters of the device description file parsing model according to the correlation loss; repeat the steps from inputting the first feature data and the second feature data to the preset twin network to optimizing the parameters of the device description file parsing model according to the correlation loss, until the loss function converges, and the trained device description file parsing model is obtained; A code generation template module is used to obtain a sensor history code corresponding to a history sensor; extract code feature data of the sensor history code, send the code feature data to a preset clustering algorithm, and obtain a corresponding feature code cluster; Different code template generators are trained through different feature code clustering clusters, wherein the code template generator is a code generation model constructed based on a neural network; corresponding loss data is calculated through a loss function preset by the code generation model, and parameters of the code template generator are optimized according to the loss data; the steps of training different code template generators through different feature code clustering clusters to optimizing the parameters of the code template generator according to the loss data are repeated until the loss function converges to obtain a trained code template generator; the sensor historical code is sent to the code template generator to obtain different code generation templates output by the code template generator; Among them, the first model training module is also used to parse the historical IO device description file to obtain the device identification data, device function data and communication network data corresponding to the historical sensor; generate a corresponding device feature matrix according to the device identification data, the device function data and the communication network data; and set the device feature matrix to the first feature data.
6. An electronic device, characterized in that: include: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the method for generating code according to a sensor IO device description file according to any one of claims 1 to 4.
7. A non-volatile computer-readable storage medium, characterized in that: The non-volatile computer-readable storage medium stores computer-executable instructions. When the computer-executable instructions are executed by an electronic device, the electronic device executes the method for generating code according to a sensor IO device description file according to any one of claims 1 to 4.