Programming in the Ladder (LD2) Editor
The following guide just describes individual actions when working in the editor. No specific program is created.
For more information, see the following: Navigation in LD2
Programming with one element
Requirement: In your project, you have created a POU in the Ladder (LD2) implementation language. You have this POU open and ready to be edited in the ladder editor.
Insert
In the ToolBox view of the editor, select the Contact element, for example, and drag it to the network. Press and hold the mouse button. When you drag it across the network with the cursor, all valid insert positions are indicated by the following icons:
Rectangle:

Insert position to the right of elements which have already been inserted
Rhombus:

Insert position to the left of elements which have already been inserted
Triangle:
, 
Insert position after a branch on a parallel connection which runs down (triangle points downwards) or up (triangle points upwards).
Release the element over the desired insert position. Make sure the mouse pointer shows a plus symbol (
).
The contact will be inserted into the processing line of the network.
Tip
Select the Show Insert Positions command. Then all insert positions will be displayed regardless of your mouse actions.
Insert Block
Insert a Block element in the network. Replace the three question marks (
???) in the element box with the name of the desired block from the project or a library. To do this, double-click the question marks and – ideally – click the
button to use the Input Assistant.Refreshing the block
Select a block. Then select the Update Parameters command.
The inputs and outputs of the block will be checked and adjusted if necessary. After changing the declaration of a function block, you should refresh the instances of this function block which are used in the ladder diagram.
Insert Input
Insert an Input element before the block. To assign variables, at the element replace the three question marks (
???) with the variable name. If necessary, the default Auto Declare dialog will open.Selecting and positioning
Reposition elements in the network. Select an element so that it is highlighted in red. In the case of a block, the square inside the block symbol must be displayed with a red background. Drag the element to another possible insert position until the cursor symbol becomes a square and then release the mouse button.

Replace
To replace an existing element with another one, drag the new element onto the one you want to replace. When the focus is on the element to be replaced, release the mouse button.
Adding a new network
Drag the Network element to the implementation part.
A rectangular insert position will be displayed in the left margin, where the networks are also numbered.

Release the left mouse button.
The new network will be inserted above the selected insert position.
Modifying a block, coil, or contact
Select an element or an input or output.
The modifying commands will be displayed in the context menu.
Select the desired command.
Command: Negate (for example, to negate an input)
Command: Set/Reset (for example, to add a set or reset memory to a coil
Command: Edge Detection – Rising Edge, Edge Detection – Falling Edge (for example, to modify a contact)

Branching a connection
Difference from the LD/FBD editor
In the LD2 editor of CODESYS Ladder, there are no elements for branches.
In a ladder diagram, connections are created automatically when elements are inserted and positioned.
From the ToolBox view, drag a contact to your network and then drag a second contact to the rectangular insert position at the end of the connection. Name the two contacts
xInput1andxInput2.
Select the
xInput2contact. Then drag it to the insert position which is marked with a downward-pointing triangle before thexInput1contact.
Release the left mouse button there.
A branch will be created. Each branch will contain one contact.

Important
The contact has not been newly inserted. The existing contact has been moved to a different position with the current configuration.
While holding down the Ctrl key, click each of the rectangular insert positions at the end of both connections.
Both ends will be selected. The selection will be indicated by red rectangles. The first selection will be displayed in gray.

Select the Close Parallel Branch command.
The branch will close at the end. The contacts will be connected in parallel.

There are two ways to reopen the closed connection:
Select one of the two branches. Then drag the red rectangle onto the rectangle of the other branch.
Select both branches. Then select the Open Parallel Branch command.
Tip
If you have a closed branch with multiple parallel branches, then you can always open all branches using the Open Parallel Branch command.

Add two contacts in a row to a network.
Select the Show Insert Positions command and select the network.
All insert positions will be marked.

Select the downward-pointing triangle at the front of the connection.
In the context menu, select the Insert Contact (parallel) command.
While holding down the Ctrl key, click each of the rectangular insert positions at the end of both connections.
The red rectangles will indicate the selection.

Select the Close Parallel Branch command.
The two connections will be merged.

In one of the two branches, select the insert position before the node which merges the connections. Then press the Del key.
The connection will open at the end.

Important
To switch the processing order in networks V1.2.0.0 and higher, see the following: Processing order and normalization
Selection and multiple selection
In the LD2 editor, you can select individual networks and individual elements within a network. In both cases, a multiple selection is also possible. All selected networks and elements are highlighted in red and outlined.
The commands from the Ladder menu and from the context menu act on all selected objects together. A command is available only if it is permitted for all selected objects.
In the ladder diagram, click a position where no element and no insert position is focused. This is in particular the area along the processing line in which the network number is displayed.
The network located within the clicked area will be highlighted in red and therefore selected.
Press and hold down the Shift key while you click another network.
All networks located between the first clicked and the second clicked network will be selected.
Press and hold down the Ctrl key while you click a selected network.
This network will no longer be selected.
Click an element. In the case of a block, click the square inside the block symbol.
The element will be selected.
Click another element.
The last element you clicked will be selected.
Press and hold down Ctrl while you click more elements in order to select and deselect them.
All clicked elements will be selected.
For a multiple selection of elements, the context menu provides the standard commands Cut, Copy, and Delete as well as the modifying commands (Negate, Set/Reset, edge detection), among others. The respective command acts on all selected elements for which it is permitted.
Tip
You can use the Command: Open Parallel Branch and Command: Close Parallel Branch commands to place several selected elements together in a parallel branch.
Commenting-out a network
Select a network so that it is completely displayed with a red background. In the context menu, select the Toggle network comment state command.
The network contents will be displayed in gray and the text in italics. The network will not be included during processing.

Adding a network title, network comment, and jump label
You can add a network title (1), a network comment (2), and a jump label (3) to a network. To do this, click in the first, second, or third line in the upper left corner of the network.

A jump label is used as a target for a Jump element.
The display of the network title and network comment is defined in the Ladder editor (LD2) category of the CODESYS options.