Conversion method of the statement list to ladder diagram
Technical field
The present invention relates to industrial control field, and in particular to the conversion method of statement list to ladder diagram.
Background technology
Ladder diagram (Ladder Diagram) is as the graphical volume of one kind originating from early stage relay logical control circuit
Cheng Yuyan, because its is easy to use, efficiently can intuitively realize complexity logic control function, among industrial control field from
Simple PLC must as one in system such as Distributed Control System (DCS), field bus control system (FCS) to complicated obtain
Indispensable and often most important programming language.Ladder diagram can typically be compiled into statement list, the sentence in specific implementation
Table is exactly often the elementary instruction of IEC61131-3 fictitious host computers, is instructed from binary program code and the statement list of fictitious host computer
Correspond.For the reason for the debugging maintenance, it is sometimes desirable to upload in the PLC internal processes of operation, the binary system uploaded
Code can very easily be converted to statement list, and statement list is textual program language after all, and no ladder diagram seems directly perceived
Simply, it is therefore desirable to which statement list is converted into ladder diagram.
The content of the invention
It is an object of the invention to provide a kind of conversion method of statement list to ladder diagram.
The present invention is achieved by the following technical programs:
Statement list to ladder diagram conversion method, with LD/LDN classes instruct, AND/ANDN classes instruction, OR/ORN classes instruction,
ALD is instructed, OLD instructions, and centered on LPS, LRD, LPP instruct the instruction of this six class, in addition to coil class instructs with function box class, line
Circle class is instructed according to the value of current logic stack top with function box class to decide whether execution or assignment, can extend execution as needed
Or the instruction of assignment;Comprise the following steps that:
Step 1:According to actual sentence, necessary data structure is established;
Step 2:Make Path chained list:1. creating a list structure, the object referred to herein as " path ", path are stored
Object factory forms the ladder diagram element, source node number, the information of destination node number in the path;Path can also include sub- road
Footpath, can be serial or parallel connection relation between subpath;2. establish a kind of node number application mechanism so that can apply arriving every time
One new node number;3. establish the path that the Node station that sets out enters destination node storehouse;
Step 3:Statement list is scanned, generates path chained list;
Step 4:According to the instruction scanned, corresponding path chained list is generated by special algorithm;
Step 5:Lift ladder diagram from the path chained list of generation;
Described step 4 generates corresponding path chained list by following special algorithm:
(1) LD/LDN classes instruct:
1. generates a new path, the ladder diagram element of a contact types is included in path;
2. applies for new node number, source node storehouse is pressed into;
3. applies for new node number again, destination node storehouse is pressed into;
4. the source node number of new routes is equal to source node storehouse stack top value;
5. the destination node number of new routes is equal to destination node storehouse stack top value;
6. path newly-generated is inserted into the front end of chained list;
(2) AND/ANDN classes instruct:
1. generates a new path, the ladder diagram element of a contact types is included in path;
2. new routes source node number is equal to destination node storehouse stack top value;
3. applies for new node number, destination node storehouse stack top value is replaced;
4. the source node number of new routes is equal to source node storehouse stack top value;
5. the destination node number of new routes is equal to destination node storehouse stack top value;
6. path newly-generated merges one compound path of connecting of generation with the path of chained list front end;
(3) OR/ORN classes instruct:
1. generates a new path, the ladder diagram element of a contact types is included in path;
2. new routes source node number is equal to source node storehouse stack top value;
3. new routes destination node number is equal to destination node storehouse stack top value;
4. path newly-generated merges one compound path in parallel of generation with the path of chained list front end;
(4) ALD is instructed:
1. generates a new path, not comprising any element;
2. new routes source node number is equal to source node storehouse stack top value;
3. the source node number that linked list heads start the 2nd location paths is equal to destination node storehouse stack value;
4. source nodes storehouse ejects, with new route source node replacing source node number storehouse stack top value;
5. destination nodes storehouse ejects;
6. new routes destination node number is equal to destination node storehouse stack top value;
7. 2 paths that in order starts linked list head are moved to the subpath of new route;
8. path newly-generated is inserted into the front end of chained list;
(5) OLD is instructed:
1. generates a new path, not comprising any element;
2. source nodes storehouse ejects;
3. destination nodes storehouse ejects;
4. new routes source node number is equal to source node storehouse stack top value;
5. new routes destination node number is equal to destination node storehouse stack top value;
6. the source node number that linked list heads start the 1st, 2 location paths is equal to source node storehouse stack top value;
7. the destination node number that linked list heads start the 1st, 2 location paths is equal to destination node storehouse stack top value;
8. 2 paths that in order starts linked list head are moved to the subpath of new route;
9. path newly-generated is inserted into the front end of chained list;
(6) LPS is instructed:Replicate destination node storehouse stack top value and pop down;
(7) LRD is instructed:The value of the position of destination node storehouse the 2nd is replicated to stack top;
(8) LPP is instructed:Destination node storehouse ejects;
(9) coil class instructs:
1. generates a new path, the ladder diagram element of a coil-type is included in path;
2. new routes source node number is equal to source node storehouse stack top value;
3. new routes destination node number is equal to new node number;
4. path newly-generated is inserted into the front end of chained list;
(10) function box class instructs:
1. generates a new path, the ladder diagram element of One function box type is included in path;
2. new routes source node number is equal to source node storehouse stack top value;
3. new routes destination node number is equal to new node number;
4. path newly-generated is inserted into the front end of chained list;
The specific method that described step 5 lifts ladder diagram from the path chained list of generation is as follows:
Original path is only 1 ladder diagram element, without the path of subpath;By all original roads in the chained list of path
Ladder diagram element in footpath proposes, so that it may obtains the ladder diagram element corresponding to statement list and connects mutual annexation
;When ladder diagram element is extracted from original path, it then follows following principle:
1. being connected to access point corresponding to path source node number on the left of ladder diagrams element, it is connected on the right side of ladder diagram element
Access point corresponding to the door-plate node number of path;
2. the order in chained list or child list deposits ladder diagram element to by path.
Brief description of the drawings
Fig. 1 is the ladder diagram of the present invention;
Fig. 2 is the schematic diagram of the LD A generation respective paths of the present invention;
Fig. 3 is the schematic diagram of the LD B generation respective paths of the present invention;
Fig. 4 is the schematic diagram of the AND C generation respective paths of the present invention;
Fig. 5 is the schematic diagram of the LD D generation respective paths of the present invention;
Fig. 6 is the schematic diagram of the AND E generation respective paths of the present invention;
Fig. 7 is that the OLD of the present invention establishes the schematic diagram of relation between path;
Fig. 8 is the schematic diagram of the OR F generation respective paths of the present invention;
Fig. 9 is that the ALD of the present invention establishes the schematic diagram of relation between path;
Figure 10 is the schematic diagram of the AND G generation respective paths of the present invention;
Figure 11 is the schematic diagram of the LPS processing path nodes of the present invention;
Figure 12 is the schematic diagram of the AND H generation respective paths of the present invention;
Figure 13 is the schematic diagram of the ADD generation respective paths of the present invention;
Figure 14 is the schematic diagram of the LRD generation respective paths of the present invention.
Embodiment
Embodiments of the invention are described further below in conjunction with the accompanying drawings:
Statement list corresponding to ladder diagram as shown in Figure 1 is as follows, and Fig. 2 to Figure 14 is that the detailed process of below step illustrates,
Statement list to ladder diagram conversion method, with LD/LDN classes instruct, AND/ANDN classes instruction, OR/ORN classes instruction, ALD instruction,
OLD is instructed, and LPS, LRD, LPP are instructed centered on this six class instructs, in addition to coil class and function box class instruct, coil class with
The instruction of function box class decides whether execution or assignment according to the value of current logic stack top, can extend execution or assignment as needed
Instruction;Comprise the following steps that:
Step 1:According to actual sentence, necessary data structure is established;
Step 2:Make Path chained list:1. creating a list structure, the object referred to herein as " path ", path are stored
Object factory forms the ladder diagram element, source node number, the information of destination node number in the path;Path can also include sub- road
Footpath, can be serial or parallel connection relation between subpath;2. establish a kind of node number application mechanism so that can apply arriving every time
One new node number;3. establish the path that the Node station that sets out enters destination node storehouse;
Step 3:Statement list is scanned, generates path chained list;
Step 4:According to the instruction scanned, corresponding path chained list is generated by special algorithm;
Step 5:Lift ladder diagram from the path chained list of generation;
Described step 4 generates corresponding path chained list by following special algorithm:
(1) LD/LDN classes instruct:
1. generates a new path, the ladder diagram element of a contact types is included in path;
2. applies for new node number, source node storehouse is pressed into;
3. applies for new node number again, destination node storehouse is pressed into;
4. the source node number of new routes is equal to source node storehouse stack top value;
5. the destination node number of new routes is equal to destination node storehouse stack top value;
6. path newly-generated is inserted into the front end of chained list;
(2) AND/ANDN classes instruct:
1. generates a new path, the ladder diagram element of a contact types is included in path;
2. new routes source node number is equal to destination node storehouse stack top value;
3. applies for new node number, destination node storehouse stack top value is replaced;
4. the source node number of new routes is equal to source node storehouse stack top value;
5. the destination node number of new routes is equal to destination node storehouse stack top value;
6. path newly-generated merges one compound path of connecting of generation with the path of chained list front end;
(3) OR/ORN classes instruct:
1. generates a new path, the ladder diagram element of a contact types is included in path;
2. new routes source node number is equal to source node storehouse stack top value;
3. new routes destination node number is equal to destination node storehouse stack top value;
4. path newly-generated merges one compound path in parallel of generation with the path of chained list front end;
(4) ALD is instructed:
1. generates a new path, not comprising any element;
2. new routes source node number is equal to source node storehouse stack top value;
3. the source node number that linked list heads start the 2nd location paths is equal to destination node storehouse stack value;
4. source nodes storehouse ejects, with new route source node replacing source node number storehouse stack top value;
5. destination nodes storehouse ejects;
6. new routes destination node number is equal to destination node storehouse stack top value;
7. 2 paths that in order starts linked list head are moved to the subpath of new route;
8. path newly-generated is inserted into the front end of chained list;
(5) OLD is instructed:
1. generates a new path, not comprising any element;
2. source nodes storehouse ejects;
3. destination nodes storehouse ejects;
4. new routes source node number is equal to source node storehouse stack top value;
5. new routes destination node number is equal to destination node storehouse stack top value;
6. the source node number that linked list heads start the 1st, 2 location paths is equal to source node storehouse stack top value;
7. the destination node number that linked list heads start the 1st, 2 location paths is equal to destination node storehouse stack top value;
8. 2 paths that in order starts linked list head are moved to the subpath of new route;
9. path newly-generated is inserted into the front end of chained list;
(6) LPS is instructed:Replicate destination node storehouse stack top value and pop down;
(7) LRD is instructed:The value of the position of destination node storehouse the 2nd is replicated to stack top;
(8) LPP is instructed:Destination node storehouse ejects;
(9) coil class instructs:
1. generates a new path, the ladder diagram element of a coil-type is included in path;
2. new routes source node number is equal to source node storehouse stack top value;
3. new routes destination node number is equal to new node number;
4. path newly-generated is inserted into the front end of chained list;
(10) function box class instructs:
1. generates a new path, the ladder diagram element of One function box type is included in path;
2. new routes source node number is equal to source node storehouse stack top value;
3. new routes destination node number is equal to new node number;
4. path newly-generated is inserted into the front end of chained list;
The specific method that described step 5 lifts ladder diagram from the path chained list of generation is as follows:
Original path is only 1 ladder diagram element, without the path of subpath;By all original roads in the chained list of path
Ladder diagram element in footpath proposes, so that it may obtains the ladder diagram element corresponding to statement list and connects mutual annexation
;When ladder diagram element is extracted from original path, it then follows following principle:
1. being connected to access point corresponding to path source node number on the left of ladder diagrams element, it is connected on the right side of ladder diagram element
Access point corresponding to the door-plate node number of path;
2. the order in chained list or child list deposits ladder diagram element to by path.
Description behind step is by ladder diagram that following statement list decompiling is shown in Fig. 1:
LD A//by A are loaded into logic stack top
LD B//logic stack pushes 1 layer, and B is put into stack top
AND C//logic stack top is with C phases with being as a result put into stack top
LD D//logic stack pushes 1 layer, and B is put into stack top
AND E//logic stack top is with C phases with being as a result put into stack top
Bullet in next layer of phase of OLD//stack top and its or, logic stack, is as a result placed on stack top
OR F//logic stack top and H phases with
Bullet in next layer of phase of ALD//stack top and its or, logic stack, is as a result placed on stack top
AND G//logic stack top is with I phases with being as a result put into stack top
LPS//push logical stack, and keep stack top value constant
AND H//logic stack top is with J phases with being as a result put into stack top
If ADD//stack top is true, add operation is carried out
The value of LRD//duplication sublevel is to stack top
LD I//logic stack pushes 1 layer, and I is put into stack top
LD J//logic stack pushes 1 layer, and J is put into stack top
AND K//logic stack top is with K phases with being as a result put into stack top
Bullet in next layer of phase of OLD//stack top and its or, logic stack, is as a result placed on stack top
Next layer of phase of ALD//stack top and its is with bullet in logic stack, being as a result placed on stack top
If SUB//stack top is true, subtraction is carried out
Bullet in LPP//logic stack
If MUL//stack top is true, multiplying is carried out.