IEC 61131 Language Editor Programming

 

Topic Menu

Getting Started with IEC 6-1131 Ladder Logic in Cscape

See alsoGet Started with IEC Editors

See alsoEnhanced IEC 61131 Guide

IEC Workspace

Note: The Element Toolbar changes depending on which IEC logic is being used.

The below dialog shows the workspace windows used when editing IEC programs. Individual component windows can be enabled/disabled by selecting them in the in the Home menu.

See also: Shortcut Keys

Navigation Bar in IEC Editor

Quick buttons to navigate to various features in Cscape 10.

Save File

Hardware Configuration
Connection Wizard
Connect/Disconnect

Set Target Network ID

Run /Stop

See: Put Controller in Run, Stop/Idle, or Do I-O Mode

Do I/O Mode

See: Put Controller in Run, Stop/Idle, or Do I-O Mode

Download a Program to a Controller

Upload a Program from a Controller

  • Download online change to controller and switch new program control

  • Revert to stored program after online change

See: Online Change in EIEC*

See: Debugging Functions in Advanced Ladder

Check for Errors

See Data Watch in Debugging Functions in Advanced Ladder

Find and Replace

See: Edit Features in IEC

Simulation

See Breakpoints and Stepping in Enhanced IEC 61131 Guide

Resume Cycle to Cycle Mode

Execute a Single Cycle

Step In, Over, Out

See Breakpoints and Stepping inEnhanced IEC 61131 Guide

 

Set Breakpoint

Set Tracepoint

Remove all Breakpoints

See Breakpoints and Stepping in Enhanced IEC 61131 Guide

Project Navigator for IEC Editors
Project Toolbox for IEC

Enhanced IEC 61131 Guide

Variable Based Advanced Ladder
Enum Window, see Enhanced IEC 61131 Guide
Bitfields Window, see Enhanced IEC 61131 Guide
Structure Window, see Enhanced IEC 61131 Guide
Cscape Registration and Log In

Return to the Top: IEC 61131 Language Editor Programming

Basic IEC Editor Programming

The recommended order in which to start a new Cscape program is as follows:

  1. Configure Cscape to present the logic editor options required.

  2. Start a new Project or a new Program file in the logic editor of choice.

  3. Establish a connection to the controller if possible (not required).

  4. Configure the controller and I/O with the Hardware Configuration.

  5. Save the new program.

The order in which further parts of the programming process is carried out is somewhat less important:

  • Configure program and controller security

  • Name I/O points, variables, etc.

  • Write programming for the controller

  • Create screens if required

  • Set up communications

  • Set up datalogging and alarms

  • Save

Program Organization Units

An application is a list of programs. Programs are executed sequentially within the target cycle, according to the following model:

Programs are executed according to the order defined by the user. All SFC programs must be grouped (it is not possible to insert a program in FBD, LD, ST or IL in between two SFC programs). The number of programs in an application is limited to 255. Each program is entered using a language chosen when the program is created. Possible languages are Sequential Function Chart (SFC), Function Block Diagram (FBD), Ladder Diagram (LD), Structured Text (ST) or Instruction List (IL). Programs must have unique names. The name cannot be a reserved keyword of the programming languages and cannot have the same name as a standard function block. A program should not have the same name as a declared variable. The name of a program should begin by a letter or an underscore ("_") mark, followed by letters, digits or underscore marks. It is not allowed to put two consecutive underscores within a name. Naming is case insensitive. Two names with different cases are considered as the same.

Sub-programs

The list of programs may be completed by "Sub-programs". Sub-programs are described using FBD, LD, ST or IL language, and can be called by the programs of the application. Input and output parameters plus local variables of a sub-program are declared in the Program Variables Window as local variables of the sub-program. A sub-program may call another sub-program. Local variables of a sub program are not instantiated. This means that the sub-programs always work on the same set of local variables. Local variables of a sub-program keep their value among various calls. The code of a sub-program is not duplicated when called several times by parent programs. A sub-program cannot have more than 32 input parameters or 32 output parameters. A parameter of a sub-program cannot be an instance of a function block.

Bookmarks

Bookmarks are used for navigating in a document. The user can freely insert bookmarks everywhere in a document. Then the user can jump from a bookmark to another with a single command for browsing the document. Bookmarks are supported in all program editors plus the Program Variables Window.

Below are the available commands for using bookmarks:

  • Ctrl + F2 - Toggle the bookmark at the current position

  • Shift + F2 - Go to the next bookmark

Depending on the type of document, the possible locations for a bookmark are:

  • In the text editor, a bookmark is placed on a line of text.

  • In the SFC editor, a bookmark is placed on a SFC symbol (step, transition, jump...).

  • In the FBD editor, a bookmark is placed on any FBD object (not on a line).

  • In the LD editor, a bookmark is placed on a rung header.

  • In the Program Variables Window, a bookmark is placed on any line of the grid (variable or group).

Note: Bookmarks are valid only while the editing window is open, and are not stored in the document when the window is closed.

Return to the TopIEC 61131 Language Editor Programming

IEC Logic Editor Types

By default, newly installed Cscape software starts new programs in the Advanced Ladder with Register-Based Addressing editor and will not give further logic editor options for new programs.

IEC 61131 Language Editor: The IEC editor is a standardized logic editor entirely different from the Advanced Ladder editors, though IEC also uses Variable-Based Addressing as described above. The IEC editor allows interchangeable use of 5 separate programming languages:

Return to the TopIEC 61131 Language Editor Programming

Enhanced IEC 61131 Language Editor

While all products support the IEC languages, some products optionally allow the use of Enhanced IEC functionality as a licensed feature. The use of this editor is automatic if the licensing is in place and the option to allow it is selected. If needed, use the following steps to configure Cscape so that there are the options to create a new program in the IEC 61131 Language Editor or in the Advanced Ladder with Variable-Based Addressing Editor. See also: Enhanced IEC 61131 Guide

 

Create a New Project in IEC

The PROJECT is a centralized location or container for the information about and concerned with an entire installation. When a project is opened, all necessary information is made available. From Cscape 8.6 onwards, when a new or existing Cscape Project File is opened, a hidden folder will be created for each project inside the Cscape install folder. These folders will be internally named and are temporary hidden folders. The users must not store anything in these folders as they will be removed when the project(s) is (are) closed. To save or copy the programs that are part of project, or the project itself to a different location, use the Project Navigator or main menu.

Whenever the user adds an existing copy to a project in project navigator, a copy will be made to the temporary folder allocated to that project. The original file will be untouched. Therefore, if a program is added to one or more projects in project navigator, changes done to the program in each project will modify that project’s local copy only. The original file or copy in other project(s) will not be affected.

There are multiple ways to create a new program, through the Project Navigator, the Project Node, the Cscape icon, and keyboard shortcut.

Right-Click on Project Navigator to open the following menu. Select New Project.

  1. Open the Application dialog via System > IEC Logic User Settings > Application > Supported Program Types. Ensure Support IEC Editor Programs is selected. Select OK.

  2. Open a New Program

    1. Option 1: Through the Project Navigator Node.

    2. Option 2: Through the Project Node.

    3. Option 3: Cscape Icon

    4. Option 4Keyboard Shortcut - Create a new program through keyboard shortcut - Ctrl+N.

  3. Select Editor Type

The Editor Selection Type screen will appear:

Select the desired editor for this program and select OK. An untitled program will appear in the Project Navigator.

Return to the Top: IEC 61131 Language Editor Programming

Connect to the Controller

This step is optional. The controller type and onboard I/O can be automatically configured if a connection is present. Configuration can also be done manually without the need for a connection if the controller type is known.

Common connections between Cscape and a controller are:

  • USB – Use a USB-A to MiniUSB cable to connect to the controller. Drivers must be installed correctly and fully (2-stage installation doesn’t always automatically take place).

  • Ethernet – Requires proper IP Address assignment on the controller and a connection to the same subnet, or a direct connection to a PC that is properly, manually configured.

  • Serial via MJ1 port – Using a USB-to-Serial convertor (unless a 9-pin serial port already exists) and the proper programming cable, connect between the PC’s USB port and the controller’s MJ1 port.

If a controller is available and connected, use the Connection Wizard to establish communications between Cscape and the controller. See Connection Wizard for more details.

Return to the Top: IEC 61131 Language Editor Programming

Hardware Configuration

The first thing that should be done with any new Cscape program is to configure which controller and installed I/O is to be used via the Hardware Configuration. This will allow the Cscape software to present the proper options and configurations during the programming process, including I/O point types, features, screen size, etc. Every Cscape program will have its own Hardware Configuration; the configuration is not automatically carried from one program to the next. Hardware Configuration may be done partially automatically if a connection to the controller is first established (see previous section). Manual configuration is also possible if no controller is available to which to connect.

See Hardware Configuration for more details.

See General I/O Configuration for more details.

Return to the TopIEC 61131 Language Editor Programming

Save the Program

There are several different ways to save a Cscape program.

  1. Option 1: Save a program through the Cscape Icon Select the Cscape icon in the upper left corner, then click Save

  2. Option 2: Use the keyboard shortcut - Ctrl + S

    Pressing Ctrl + S will bring up the dialog below to name the file if this is the first time the file is being saved. Otherwise, it will automatically save the file as the filename that has previously been specified.

  3. Option 3: Use the Project Navigator

    Right-click on the Untitled Program name and select Save Program As... and name the program.

Set Security System

If desired or if required by company policy, Security Permissions can be set for both the Cscape file and the controller. From the Main Menu select Tools > Security.

Note: Security measures are optional. See also: Security & Passwords or Project Navigator for IEC Editors

Save the program.

Return to the Top: IEC 61131 Language Editor Programming

How to Write the Program - IEC

This is an IEC61131 program that will turn on an output when the START button is pressed and will hold itself on with a “holding contact”. The output is turned off if either the STOP button or the ESTOP switch interrupts power to the output. Written in IEC Structured Text Language.

Create the Program Environment

Create a new program using Editor Type: IEC61131 Language Editor

Create a new IEC Structured Text block by one of two means:

  1.  Using right-click options within the Project Navigator. Within the new program, expand Control >Logic Modules > Main Loop Modules [right-click] > New Logic Block IEC Structured Text Block.

  2. From Logic Editing ribbon select IEC Structured Text Block.

A new Structured Text module is created. Select the module to open the programming window.

Return to the Top: IEC 61131 Language Editor Programming

Placing Program Elements - IEC

When using the IEC editor, functions are dragged from the toolbar or from the variable table to be placed in logic. Some elements must be declared as a variable before using, while others must be used directly without declaring an instance of the function. Functions that require an instance may be dragged from the toolbox to the variable table directly. IEC Functions that can be used directly, without first declaring an instance, are denoted with either an ‘empty’ function block icon or a math-symbol icon to the left of the function name. These functions do not take up any data space in memory themselves and are simply an operation on the parameters they are given. For example, the Shift Left function and Less Than functions below are used as is and are not first be defined as a variable.

IEC Functions that require an instance to be declared before using are denoted with a function block icon full of dots. These functions require space in data memory for some part of their function. For example, the On Timer below must first be declared as a variable with the type “TON100ms” before being used in logic. The timer’s accumulator and associated time-tracking information resides in memory, therefore requiring an instance to be declared for each timer used. Dragging this function straight to a section of the variables table will make an entry of this function of the correct type. Dragging this variable to the logic editing area will insert the function.

Note: It is possible to drag a function that requires a declared instance directly to the logic editor. This will cause an error when compiled if left this way but can also be a way to quickly place and hover the mouse over the function to see the tooltip of required parameters without first declaring an instance of the function. The available elements are shown in Project Toolbox. See Project Toolbox for IEC or User Settings for IEC

Return to the Top: IEC 61131 Language Editor Programming

Creating New Variables

See Also: Program Variables in IEC

The IEC Program Variables window contains a list of the variables used in the IEC Programming section.

To open the Program Variables window, enable via Home menu > Program Variables.

This opens the dockable Program Variables window. For convenience, the variables list includes some pre-defined variables mapped to the corresponding register address of the I/O points, Function keys, System Bits and System Registers. These variables names do not need to be used, the programmer can create and use an alternative variable mapped to any of these I/O points instead.

In the Program Variables window, right-click and select Add Variable or press the INSERT key to create a new variable in the selected group.

The variable is added at the end of the group. Variables are created with a default name (‘NewVar’, ‘NewVar1’, etc). To edit a variable name or any other attribute, highlight it and press the ENTER key to open the variable setting box. When editing is completed press the ENTER key. The programmer can rename a new variable or change its attribute using the variable editing grid. This is activated using the SPACE bar. See Also: Variable list - Active grid in Program Variables in IEC

Create the following variables which are mapped to the I/O points shown.

Name

Type

Dim.

Mapping

Description

Estop

Bool

 

%I0001

 

Start

Bool

 

%K01

 

Stop

Bool

 

%K02

 

Run

Bool

 

%Q0001

 

Write the appropriate Structured Text code

The editor supports advanced graphic features such as drag and drop, syntax coloring and active tooltips for efficient input and test of programs written in Structured Text.

See Also: Structured Text

See Also: IEC Editors and Basic Operations

Return to the TopIEC 61131 Language Editor Programming

Defines Window

See also: Definitions in Program Variables in IEC

The Defines Window is a window where the constant values can be assigned and is for IEC only. There is a large list for predefined values to be used in programs. To see this list, click on the ‘+’ of ‘Library Defines’, and the list of predefined variables appears. It includes the Predefined system constants known as Library Defines (OEMClosed OEM Code – Original Equipment Manufacturer - Cscape allows user-defined sections of ladder Program Code to be marked as "Original Equipment Manufacturer" (OEM) or "proprietary". Code thus marked can be accessed only by a user with the proper security permissions and password.) as well as the Global defines which can be used in all the blocks and Local defines which are block specific. The Contents of a particular section of the defines editor can be edited by double-clicking that section or by selecting it and clicking the Configure button to bring up the Defines Editor Tabbed Window in the editing area.

A Defines Editor is opened for the Global Defines and for the block specific Local Defines where the variables can be viewed/edited in the logic editing and assigned a constant value.

Home > View > Defines Window

For example, to open a comm port, the Defines table allows a user to associate text like “RS-485Closed An EIA standard that specifies electrical characteristics of drivers and receivers for use in serial communications. Electrical signaling is balanced and multipoint systems are supported.” with the value of 1, or “RS-232” with the value of 0, to make the program more readable.

Also, instead of a Structured test line of code being “OpenPort (0,3,1,1,0), it can be “OpenPort (MJ1, RS485, Multidrop, Half, None, Modbus)”.

Check for Errors

IEC Programs are automatically compiled for syntactical errors before they are downloaded to the controller. The Output window is displayed with the results of the compilation.

Manually check a program for errors by selecting Program, Error Check from the Home ribbon.

If there are no errors, then a No-Error Message box appears, along with details in the Output Window:

Save the Program

See Save the Program for more details.

Download the Program to the OCS

See Download a Program to a Controller

Return to the Top: IEC 61131 Language Editor Programming

Debugging

See also: Debugging Functions in IEC

Debugging helps to find physical problems.

Once the program has been successfully cleared of errors, download it to the associated controller. Place the controller in RUN mode, and then start the debugger:

  • From the Main Menu select Debug > Debug/Monitor.

  • Use the right-click option at Debug > Monitor from the Program node in Project Navigator.

While in the debug mode, Cscape maintains a real-time connection to the associated controller. If Pass Through Connections are used, one can debug any controller through the network without being physically connected to the controller. See also: Put Controller in Run, Stop/Idle, or Do I-O Mode

Return to the TopIEC 61131 Language Editor Programming

Language Conversion or Change Language

This option is used for translation of IEC modules between different IEC languages except SFC. From the Project Navigator > Control > Logic Modules > Main Loop Modules > Right-Click on language > Change Language

Change Language option can be accessed by right-clicking on any of the existing modules. Selecting Change Language displays the option of languages to which the selected module can be translated as shown below:

The user can select any language to which translation needs to done. Once the user selects any language from the list, the following warning message is displayed:

Clicking on OK translates the module to the selected language.

Note: Change Language option is not available for SFC modules.

Return to the Top: IEC 61131 Language Editor Programming

Output Window

The Output Window is a dockable window which lists all the compilation errors in an application. Double clicking on the error in the list, goes to the error location without closing the output window.

Like all dockable windows, it can be placed in pinned, hidden, docking and floating mode anywhere in the working area. The output window lists out the errors present in each of the blocks by checking block by block.

Return to the Top: IEC 61131 Language Editor Programming