System and method for automatically generating industrial equipment HMI interface based on PLC program
Technical Field
The invention relates to the field of industrial automation, in particular to a system and a method for automatically generating an industrial equipment HMI interface based on a PLC program.
Background
In the field of industrial automation, PLC (Programmable Logic Controller) is a digital computer device for implementing automatic control, typically for controlling a machine or a factory production line. To better control and monitor the internal conditions of the devices controlled by the PLC, it is often necessary to configure the corresponding HMI (Human Machine Interface) interface for the PLC program.
The traditional HMI interface development method is that engineers manually write corresponding interfaces for the PLC programs. In detail, writing an HMI interface for a PLC requires manual work according to the following procedure: dragging (configuring) a creation control, binding the control to a designated variable of a PLC program, and writing a page read-write data script; manually writing an HMI program is a complex and time-consuming process, especially when the number of variables, pages, increases, and the developer needs to repeatedly drag the control arrangement control layout and perform the variable binding operation. In the development process, a great deal of repeated work exists, misoperation is easy to occur when the variables are bound, and when the variable addresses of the PLC program change, the HMI program also needs to change correspondingly. Generally speaking, manually writing an HMI procedure is a cumbersome process that is time-consuming, labor-consuming, and difficult to maintain, and is not conducive to efficient and automation of industrial production.
Therefore, in order to solve the technical defects in the prior art, a solution is needed to solve the technical problems in the prior art.
Disclosure of Invention
In order to solve the problems, the invention provides a system and a method for automatically generating an industrial equipment HMI interface based on a PLC program, which can automatically analyze the PLC program and generate a corresponding HMI interface according to a variable history value and code logic in the program, thereby greatly improving the efficiency and the automation level of interface development.
In order to solve the problems existing in the prior art, the technical scheme of the invention is as follows:
a system for automatically generating an industrial equipment HMI interface based on a PLC program, comprising:
the source code acquisition unit is used for acquiring source codes of the running program of the PLC equipment;
the operation data acquisition unit is used for acquiring variable data in the operation process of the PLC equipment;
the data processing unit is used for carrying out data processing on the acquired static source codes and dynamic variable data to obtain variable basic information and determining the control type of the optimal matching;
and the HMI code generating unit is used for generating HMI codes according to the variable basic information and the control type information so as to generate an HMI interface.
As a further improvement, the operation data acquisition unit is an external monitoring script which periodically acquires variable values during the operation of the PLC program and stores the variable values in a database or file.
As a further improvement scheme, the data processing unit analyzes and determines the control type corresponding to the variable according to the collected variable history value and the PLC program source code; and executing a clustering algorithm in the data processing unit, clustering according to variable characteristics of the static PLC program source code and the dynamic variable history value, and outputting variable control types and control initialization parameters.
As a further improvement scheme, in the HMI code generation unit, according to the mapping from variable characteristics to control types and a predefined control template library, the control is generated, the control attribute is filled, the data source of the control is bound to the PLC variable address, and meanwhile, page logic processing and control layout XML files are automatically generated.
As a further improvement scheme, a clustering algorithm is executed in the data processing unit, variables with similar characteristics are divided into the same category, and uniform control types are allocated; the classification features comprise variable types, variable history value conditions, grammar structures, statement logic contexts and program comments, and the feature weights can be adjusted according to actual application and requirements so as to ensure optimal control type matching.
The invention also discloses a method for automatically generating the HMI interface of the industrial equipment based on the PLC program, which comprises the following steps:
step S1: acquiring a source code of a running program of the PLC equipment and variable data in the running process of the PLC equipment;
step S2: processing data according to the variable history value and the PLC program source code acquired in the step S1 and determining the control type corresponding to the variable;
step S3: and (3) based on the result of the step (S2), carrying out automatic code generation by combining with a preset template to obtain an HMI control and page layout code, and compiling and generating an HMI executable operation program.
As a further improvement, in step S1, a monitoring script is started to periodically collect variable data to form a data set D for a PLC program running in the PLC device:
D={d 1 ,d 2 ,…,d i }
wherein d i A set of all variable values for the ith acquisition period; and formats the data into JSON or XML text format for ease of processing and analysis.
As a further improvement, in step S2, static code analysis is performed based on the PLC program source code, and basic information of each variable is extracted, wherein a static analysis function a is defined s =S c For each variable v εS → A c Static analysis extracts its attribute a v Including data type, scope, and context information in the program:
a v =(type v ,scope v ,context v )
data type v Data type being variable;
scope v The scope range of the variable is divided into a block level, a function level and a global level;
context information context v The context of variables in the program, including module location, nesting level, and logic function;
performing dynamic analysis, and processing variable data D acquired from the running of the PLC program to obtain dynamic clustering characteristics, wherein the characteristics describe the behavior mode of the variables, and the dynamic clustering characteristics comprise:
D v =(frequency v ,trend v ,range v ,center v ,spread v )
wherein the frequency characteristic frequency v The method comprises the following steps: the frequency of the variable value change;
trend feature trend v The method comprises the following steps: trend of variation of the variable over time;
trend value set range v The method comprises the following steps: a range of variation of the variable;
cluster center v The method comprises the following steps: in cluster analysis, the center point of variable data distribution;
distribution range spread v The method comprises the following steps: the distribution range or variance of variable data in the clusters.
As a further development, in step S2, the static and dynamic features D are combined v And a v Classifying the variables by using a clustering algorithm C to determine the proper control types of the variables;
merging static attributes a v And dynamic characteristics D v Construction of a feature vector f v Wherein, the method comprises the steps of, wherein,linking operations representing feature vectors:
f v =(type v ,scope v ,context v ,frequency v ,trend v ,range v ,center v ,spread v )
the clustering algorithm C is based on the feature vector f v Providing clustering of each variable v to determine the most appropriate control type t for the variable i :
C v =Cluster(f v )
Clustering result C v For a series of statistics describing the distribution of historical values of variables, each cluster center or cluster represents a set of variables with similar characteristics that are best suited for a particular type of control, the cluster center or cluster corresponding to a different type of control.
As a further improvement scheme, a K-means clustering algorithm is adopted, and the process of obtaining the variable control type is expressed as an iterative process:
where k is the number of clusters, S i Is the ith cluster, mu i Is S i Is defined by a center point of (2); through the processing of a clustering algorithm without supervision learning, a plurality of categories t are obtained through the division of static characteristics and dynamic characteristics i The same category will be assigned and mapped to the same control type.
As a further improvement, in step S1, the monitoring script may be written by Python or Lua, and run on an external device (such as an industrial personal computer), and communicate with the PLC through a network protocol (such as Modbus, UDP, OPC, etc.), and periodically obtain real values of all variables in the program, and store the real values in a database or a file in a text format such as JSON, XML, etc., so as to facilitate subsequent analysis and use.
As a further improvement, in step S1, the real-time variable value, that is, the variable value result in the running process of the PLC program, is communicated with the PLC by the monitoring script in a preset period (much longer than the running period of the PLC), and is collected by the communication protocol supported by the PLC.
As a further development, in step S1, the PLC program is a text language (instruction sheet, structured text) or a graphic table (ladder diagram, functional block, sequential functional flow diagram) conforming to IEC61131-3, and the PLC program is five programming languages (FBD (Function Block Diagram), LD (Ladder Diagram), ST (Structured Text), SFC (Sequential Function Chart), IL (Instruction List)) based on the IEC61131-3 standard. The graphical form is parsed and marked to convert it into an equivalent XML text representation.
In step S2, the input of the variable analysis model is the static PLC program source code and the dynamic variable history value, the output is the variable control type and the control initialization parameter, and the model algorithm mainly includes but is not limited to the clustering algorithms such as K-means, hierarchical clustering, mean shift, etc.
As a further improvement scheme, in step S2, the model algorithm clusters according to the variable characteristics, classifies the variables with similar characteristics into the same category, and allocates uniform control types; classification features including, but not limited to, variable type, variable history value case, grammar structure, sentence logic context, and program annotation, feature weights can be adjusted according to actual application and requirements to ensure optimal control type matching.
As a further improvement, in step S3, the automatic code generation involves: generating HMI program source codes according to a predefined control template library by the system; the method mainly comprises control parameters, data synchronization logic and UI component layout, and is used for filling the control attributes and binding the control attributes to variable addresses.
As a further improvement, in step S3, the manual verification involves writing operation, that is, manually reviewing the control variable address and variable type related to writing operation in the data synchronization code, so as to ensure that the writing operation logic of the PLC meets the expectations.
Compared with the prior art, the invention has the beneficial effects that:
1. the analysis and understanding of the PLC program are realized, and the control types corresponding to the variables are obtained through automatic analysis. Starting from the static source code layers of the five PLC programs and the real values of the variables in the dynamic running process, analyzing the variables through a clustering algorithm, and thus obtaining the appropriate control corresponding to the variables;
2. the method has the advantages that the variable bound with the control is automatically generated, the situation of address binding errors is avoided, manual intervention can be effectively reduced, and the accuracy of HMI program development is improved;
3. automatic code generation is introduced, an HMI program is automatically generated aiming at the control code, the HMI program can be used as a semi-automatic HMI program development method, and the development of the HMI program is rapidly completed by combining manual correction, so that the development efficiency is greatly improved.
Drawings
For a clearer description of embodiments of the invention or of the solutions of the prior art, the drawings that are used in the description of the embodiments or of the prior art will be briefly described, the drawings in the description that follow are merely examples of embodiments of the invention, from which, to a person skilled in the art, further drawings can be obtained:
FIG. 1 is a schematic diagram of a system for automatically generating an HMI interface of an industrial device based on a PLC program according to the present invention;
FIG. 2 is a flow chart of a method for automatically generating an HMI interface of an industrial device based on a PLC program according to the present invention;
fig. 3 is a block diagram of a method for automatically generating an HMI interface for an industrial equipment based on a PLC program.
Detailed Description
The technical scheme of the invention is described in detail below with reference to the accompanying drawings and the specific embodiments.
Referring to fig. 1, a schematic diagram of a system for automatically generating an HMI interface of an industrial apparatus based on a PLC program according to the present invention is shown, including:
the source code acquisition unit is used for acquiring source codes of the running program of the PLC equipment;
the operation data acquisition unit is used for acquiring variable data in the operation process of the PLC equipment;
the data processing unit is used for carrying out data processing on the acquired static source codes and dynamic variable data to obtain variable basic information and determining the control type of the optimal matching;
and the HMI code generating unit is used for generating HMI codes according to the variable basic information and the control type information so as to generate an HMI interface.
In the above technical scheme, the operation data acquisition unit is an external monitoring script, and the script periodically acquires the variable value during the operation of the PLC program and stores the variable value in a database or a file.
The data processing unit analyzes and determines the control type corresponding to the variable according to the collected variable history value and the PLC program source code; and executing a clustering algorithm in the data processing unit, clustering according to variable characteristics of the static PLC program source code and the dynamic variable history value, and outputting variable control types and control initialization parameters.
And in the HMI code generation unit, generating a control and a page layout code according to the mapping of the variable characteristics to the control types and a predefined template, filling the attribute of the control, binding the control to a corresponding variable address, and automatically generating an XML layout file of the page layout and the control code, the component layout and the logic processing part of the HMI.
Executing a clustering algorithm in the data processing unit, dividing variables with similar characteristics into the same category, and distributing uniform control types; the classification features comprise variable types, variable history value conditions, grammar structures, statement logic contexts and program comments, and the feature weights can be adjusted according to actual application and requirements so as to ensure optimal control type matching.
Referring to fig. 2 and 3, the embodiment provides a method for automatically generating an HMI interface of an industrial device based on a PLC program, which specifically includes the following steps:
step S1: acquiring a source code of a running program of the PLC equipment and variable data in the running process of the PLC equipment;
step S2: processing data according to the variable history value and the PLC program source code acquired in the step S1 and determining the control type corresponding to the variable;
step S3: and (3) based on the result of the step (S2), carrying out automatic code generation by combining with a preset template to obtain an HMI control and page layout code, and compiling and generating an HMI executable operation program.
The specific steps are as follows:
s1: PLC data acquisition and storage
And running the PLC program and starting the monitoring script. The monitoring script is set to collect data every 100 milliseconds (Δt=1000 ms) as a period. The script is written by using Python, PLC variable data is obtained through an Ethernet UDP protocol, the script is configured to obtain variable data in the PLC once every 1000ms, 3600s are continuously collected, and a data set D is formed:
D={d 1 ,d 2 ,…,d i }
wherein d i Is the set of all variable values in the ith acquisition period. These data are then formatted into JSON or XML text format for ease of processing and analysis.
S2: PLC variable analysis and clustering
The variable analysis and clustering need to consider both static code analysis and dynamic variable history values.
The static code analysis is based on analysis of the source code of the PLC program, and basic information of each variable is extracted. And directly extracting various variable attributes for text engineering (instruction list and structured text), and directly extracting the text engineering (functional blocks and ladder diagram) after converting the text engineering (functional blocks and ladder diagram) into equivalent XML text expression by corresponding standards. Definition of the static analysis function A s =S c For each variable v εS → A c Static analysis can extract its attribute a v Including data type, scope, context information in the program, etc.:
a v =(type v ,scope v ,context v )
1. data type (type) v ): the data type of the variable, such as integer, floating point, boolean, character;
2. scope (scope) v ): scope ranges of variables, such as block level, function level, global level;
3. context information (context) v ): the context of variables in a program, such as at module location, nested levels, logic functions.
The dynamic analysis fully utilizes variable data D acquired from the running of the PLC program, and dynamic clustering features are obtained through processing, and describe the behavior modes of the variables, and the dynamic clustering features comprise:
D v =(frequency v ,trend v ,range v ,center v ,spread v )
1. frequency characteristics (frequency v ): the frequency of the variable value change;
2. trend feature (trend) v ): trend of variation over time, such as gradual increase, decrease or periodic variation;
3. trend value set (range) v ): the variable range, the maximum and minimum value, the value with the largest occurrence number and the average value of the variables;
4. clustering center (center) v ): in the process of aggregationIn class analysis, the center point of variable data distribution;
5. distribution range (spread) v ): the distribution range or variance of variable data in the clusters.
Clustering algorithm combines static and dynamic features D v And a v And classifying the variables by using a clustering algorithm C so as to determine the proper control types of the variables. The process is completed through various clustering algorithms, such as K-means clustering, hierarchical clustering or mean shift clustering, and the selection of the clustering algorithms can be determined according to the distribution characteristics of variable data and actual requirements.
Merging static attributes a v And dynamic characteristics D v Construction of a feature vector f v Wherein, the method comprises the steps of, wherein,linking operations representing feature vectors:
f v =(type v ,scope v ,context v ,frequency v ,trend v ,range v ,center v ,spread v )
the clustering algorithm C is based on the feature vector f v Providing clustering for each variable v, and determining the most suitable control type t of the variable i :
C v =Cluster(f v )
Clustering result C v There may be a series of statistics describing the distribution of historical values of the variables, such as a cluster center, distance measure, or number of clusters, each cluster representing a set of variables with similar characteristics that are best suited for a particular type of control, the cluster center or cluster may correspond to different types of controls, such as a slider, switch button, text entry box, numeric dial, etc. generic controls.
In detail, the process of obtaining variable control types by the K-means clustering algorithm can be expressed as an iterative process:
where k is the number of clusters, S i Is the ith cluster, mu i Is S i Is defined by a center point of the lens. Through the processing of the cluster algorithm without supervision learning, a plurality of categories t can be obtained through the division of static characteristics and dynamic characteristics i The same category will be assigned and mapped to the same control type. For example: frequently changing digital analog values are mapped to digital text boxes, while boolean variables are mapped to switch controls, and readings from one temperature sensor may be mapped to a dashboard control with real-time updates, with a set of multiple temperature output values in the same function block mapped as a graph of curve data.
In general, through the static code structure and the dynamic value condition of the variable, similar variable characteristics are extracted according to the historical change frequency, the historical value mean value, the maximum value, the type and the logic context of the variable, and the HMI control type corresponding to the variable is obtained.
S3: HMI automatic code generation
After the variable basic information and the control type information are obtained, the system generates the control and page layout codes according to the mapping from the variable to the control type and the predefined template M according to the preset template. And filling the control attribute, binding the control to the corresponding variable address, and automatically generating the page layout of the HMI and the XML layout file of the control codes, the component layout and the necessary logic processing part.
After the code is generated, an additional safety check step is needed, and an engineer checks the control with the writing operation which possibly affects the safety of the equipment to prevent improper operation from affecting the running or safety of the equipment, such as an input box for setting the temperature and the on-off switching value of an on-site important switch. After the checking and necessary adjustment are completed, the codes are compiled into a final HMI executable operation interface which can be deployed on the touch equipment for operators to use.
By the method, the HMI interface synchronous with the PLC program can be systematically and efficiently created, the early version PLC project can be greatly convenient for a developer to be compatible, the HMI program for monitoring can be quickly manufactured, the development efficiency is improved, and meanwhile, the operation safety and the data consistency are ensured.
The above description of the embodiments is only for aiding in the understanding of the method of the present invention and its core ideas. It should be noted that it will be apparent to those skilled in the art that various modifications and adaptations of the invention can be made without departing from the principles of the invention and these modifications and adaptations are intended to be within the scope of the invention as defined in the following claims.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.