Skip to main content

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.

  1. Insert

    1. 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: _ld_icon_rectangle_grey.png

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

      • Rhombus: _ld_icon_rhombus_grey.png

        Insert position to the left of elements which have already been inserted

      • Triangle: _ld_icon_triangle_down_grey.png, _ld_icon_triangle_up_grey.png

        Insert position after a branch on a parallel connection which runs down (triangle points downwards) or up (triangle points upwards).

    2. Release the element over the desired insert position. Make sure the mouse pointer shows a plus symbol (_ld_img_cursor_insert_position.png).

    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.

  2. 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 _cds_icon_three_dots.png button to use the Input Assistant.

  3. 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.

  4. 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.

  5. 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.

    _ld_img_change_position.png
  6. 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.

  7. Adding a new network

    1. 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.

      _ld_img_insert_position_for_network.png
    2. Release the left mouse button.

      The new network will be inserted above the selected insert position.

Modifying a block, coil, or contact

  1. Select an element or an input or output.

    The modifying commands will be displayed in the context menu.

  2. Select the desired command.

    _ld_img_modified_elements.png

Branching a connection

Difference from the LD/FBD editor

In the LD2 editor of CODESYS Ladder, there are no elements for branches.

Procedure. Inserting elements in a row and then branching the connection

In a ladder diagram, connections are created automatically when elements are inserted and positioned.

  1. 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 xInput1 and xInput2.

    _ld_img_prepare_branch.png
  2. Select the xInput2 contact. Then drag it to the insert position which is marked with a downward-pointing triangle before the xInput1 contact.

    _ld_img_show_insert_positions_for_contact.png
  3. Release the left mouse button there.

    A branch will be created. Each branch will contain one contact.

    _ld_img_open_branches1.png

    Important

    The contact has not been newly inserted. The existing contact has been moved to a different position with the current configuration.

  4. 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.

    _ld_img_selected_insert_positions_for_parallel_connection.png
  5. Select the Close Parallel Branch command.

    The branch will close at the end. The contacts will be connected in parallel.

    _ld_img_closed_branch.png
  6. 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.

    _ld_img_open_branches1.png
Procedure. Inserting a new element in parallel
  1. Add two contacts in a row to a network.

  2. Select the Show Insert Positions command and select the network.

    All insert positions will be marked.

    _ld_img_show_insert_positions.png
  3. Select the downward-pointing triangle at the front of the connection.

  4. In the context menu, select the Insert Contact (parallel) command.

    A new contact will be inserted. The new connection will run in parallel and be open at the end.

    Parallel insertion will be available for all possible elements:

    Contact, Coil, Block, Jump, Return, Output, and ST Block

    Tip

    The keyboard shortcuts for insert and parallel insert are identical.

  5. 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.

    _ld_img_selected_insert_positions_for_parallel_connection.png
  6. Select the Close Parallel Branch command.

    The two connections will be merged.

    _ld_img_closed_branch.png
  7. 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.

    _ld_img_open_branches1.png

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.

Procedure. Selecting networks
  1. 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.

  2. 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.

  3. Press and hold down the Ctrl key while you click a selected network.

    This network will no longer be selected.

Procedure. Selecting elements
  1. Click an element. In the case of a block, click the square inside the block symbol.

    The element will be selected.

  2. Click another element.

    The last element you clicked will be selected.

  3. 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.

    _ld_img_outcommented_network.png

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.

    _ld_img_network_title_comment_label.png

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.