W447-E1-08 - CX-Programmer V8.1 Operation Manual Function Blocks Structured Text
W447-E1-08 - CX-Programmer V8.1 Operation Manual Function Blocks Structured Text
W447-E1-08 - CX-Programmer V8.1 Operation Manual Function Blocks Structured Text
W447-E1-08
SYSMAC
CX-Programmer
Ver. 8.1
WS02-CXPC1-V8
OPERATION MANUAL
Function Blocks/
Structured Text
CX-Programmer
Ver. 8.1
WS02-CXPC1-V8
Operation Manual
Function Blocks/Structured Text
Revised February 2009
iv
Notice:
OMRON products are manufactured for use according to proper procedures by a qualified operator
and only for the purposes described in this manual.
The following conventions are used to indicate and classify precautions in this manual. Always heed
the information provided with them. Failure to heed precautions can result in injury to people or damage to property.
!DANGER
Indicates an imminently hazardous situation which, if not avoided, will result in death or
serious injury. Additionally, there may be severe property damage.
!WARNING
Indicates a potentially hazardous situation which, if not avoided, could result in death or
serious injury. Additionally, there may be severe property damage.
!Caution
Indicates a potentially hazardous situation which, if not avoided, may result in minor or
moderate injury, or property damage.
Visual Aids
The following headings appear in the left column of the manual to help you locate different types of
information.
Note Indicates information of particular interest for efficient and convenient operation of the product.
1,2,3...
OMRON, 2008
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or
by any means, mechanical, electronic, photocopying, recording, or otherwise, without the prior written permission of
OMRON.
No patent liability is assumed with respect to the use of the information contained herein. Moreover, because OMRON is constantly striving to improve its high-quality products, the information contained in this manual is subject to change without
notice. Every precaution has been taken in the preparation of this manual. Nevertheless, OMRON assumes no responsibility
for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained in
this publication.
vi
Appendices
TABLE OF CONTENTS
PRECAUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxi
1
Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xxii
General Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xxii
Safety Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xxii
Application Precautions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xxiii
Part 1:
Function Blocks
SECTION 1
Introduction to Function Blocks . . . . . . . . . . . . . . . . . . . . . .
1-1
1-2
Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
1-3
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
1-4
23
1-5
Usage Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
1-6
25
SECTION 2
Function Block Specifications . . . . . . . . . . . . . . . . . . . . . . . .
29
2-1
30
2-2
41
2-3
Instance Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
2-4
Programming Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
51
2-5
56
2-6
Precautions for Instructions with Operands Specifying the First or Last of Multiple Words
65
2-7
68
2-8
70
2-9
76
SECTION 3
Creating Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . .
79
3-1
Procedural Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
80
3-2
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
ix
TABLE OF CONTENTS
Part 2:
Structured Text (ST)
SECTION 4
Introduction to Structured Text . . . . . . . . . . . . . . . . . . . . . . 131
4-1
ST Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
132
4-2
CX-Programmer Specifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
133
SECTION 5
Structured Text (ST) Language Specifications . . . . . . . . . . 135
5-1
136
5-2
137
5-3
Inputting ST Programs. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
138
5-4
ST Language Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
141
5-5
Statement Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
148
5-6
166
5-7
Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
167
SECTION 6
Creating ST Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
6-1
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
170
Appendices
A
181
183
Function Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
187
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Cat. No.
Contents
Explains how to use the CX-Programmer Ver. 8.1 softwares
W447
function block and structured text functions. For explanations
(this
manual) of other shared CX-Programmer functions, refer to the CXProgrammer Operation Manual (W446).
W446
Provides information on how to use the CX-Programmer for
all functionality except for function blocks.
W469
Explains how to use the SFC programming functions. For
explanations of other shared CX-Programmer functions, refer
to the CX-Programmer Operation Manual (W446).
W362
Information on setting up networks, such as setting data links,
routing tables, and unit settings.
W445
xi
Cat. No.
Contents
W472
Provides an outline of and describes the design, installation,
maintenance, and other basic operations for the CJ-series
CJ2 CPU Units.
SYSMAC CJ Series
CJ2H-CPU6@-EIP, CJ2H-CPU6@
Programmable Controllers
Software User's Manual
W473
W474
SYSMAC CJ Series
CJ1G-CPU@@, CJ1G/H-CPU@@H,
CJ1H-CPU@@H-R, CJ1G-CPU@@P,
CJ1M-CPU@@
Programmable Controllers
Operation Manual
W339
W393
xii
Name
Cat. No.
W394
W340
Contents
Describes programming and other methods to use the functions of the CS/CJ-series and NSJ-series PLCs.
The following information is included:
Programming
Tasks
File memory
Other functions
Use this manual together with the W339 or W393.
Describes the ladder diagram programming instructions supported by CS/CJ-series and NSJ-series PLCs.
When programming, use this manual together with the Operation Manual (CS1: W339 or CJ1: W393) and Programming
Manual (W394).
W342
Models
NSJ5-TQ@@(B)-G5D
NSJ5-SQ@@(B)-G5D
NSJ8-TV@@(B)-G5D
NSJ10-TV@@(B)-G5D
NSJ12-TS@@(B)-G5D
Name
NSJ Series
Operation
Manual
Description
Provides the following information about the NSJ-series NSJ Controllers:
Overview and features
Designing the system configuration
Installation and wiring
I/O memory allocations
Troubleshooting and maintenance
Use this manual in combination with the following manuals: SYSMAC CS Series Operation Manual (W339), SYSMAC CJ Series
Operation Manual (W393), SYSMAC CS/CJ Series Programming
Manual (W394), and NS-V1/-V2 Series Setup Manual (V083)
xiii
Models
FQM1-CM002
FQM1-MMP22
FQM1-MMA22
Name
FQM1 Series
Operation Manual
O013
FQM1-CM002
FQM1-MMP22
FQM1-MMA22
FQM1 Series
Instructions
Reference Manual
Description
Provides the following information about the FQM1-series Modules
(unit version 3.0):
Overview and features
Designing the system configuration
Installation and wiring
I/O memory allocations
Troubleshooting and maintenance
Individually describes the instructions used to program the FQM1.
Use this manual in combination with the FQM1 Series
Operation Manual (O012) when programming.
W462
CP1L-M@@@@-@
CP1L-L@@@@-@
W451
CP1H-X@@@@-@
CP1H-XA@@@@-@
CP1H-Y@@@@-@
CP1L-M@@@@-@
CP1L-L@@@@-@
Description
Provides the following information on the CP-series CP1H PLCs:
Overview/Features
System configuration
Mounting and wiring
I/O memory allocation
Troubleshooting
Use this manual together with the CP1H/CP1L Programmable
Controllers Programming Manual (W451).
SYSMAC CP Series Provides the following information on the CP-series CP1L PLCs:
CP1L CPU Unit Oper- Overview/Features
ation Manual
System configuration
Mounting and wiring
I/O memory allocation
Troubleshooting
Use this manual together with the CP1H Programmable Controllers Programming Manual (W451).
SYSMAC CP Series
CP1H/CP1L CPU
Unit Programming
Manual
xiv
Model
CXONE-AL@@C-V3/
AL@@D-V3
Manual name
CX-One Setup Manual
Contents
Installation and overview of CX-One FA
Integrated Tool Package.
Overview of Contents
Precautions provides general precautions for using the CX-Programmer Ver. 8.1.
Part 1
Part 1 contains the following sections.
Section 1 introduces the function block functionality of the CX-Programmer and explains the features
that are not contained in the non-function block version of CX-Programmer.
Section 2 provides specifications for reference when using function blocks, including specifications on
function blocks, instances, and compatible PLCs, as well as usage precautions and guidelines.
Section 3 describes the procedures for creating function blocks on the CX-Programmer.
Part 2
Part 2 contains the following sections.
Section 4 introduces the structure text programming functionality of the CX-Programmer and explains
the features that are not contained in the non-structured text version of CX-Programmer.
Section 5 provides specifications for reference when using structured text programming, as well as
programming examples and restrictions.
Section 6 explains how to create ST programs.
Appendices provide information on structured text errors and ST function descriptions.
!WARNING Failure to read and understand the information provided in this manual may result in personal injury or death, damage to the product, or product failure. Please read each section
in its entirety and be sure you understand the information provided in the section and
related sections before attempting any of the procedures or operations given.
xv
xvi
LIMITATIONS OF LIABILITY
(1) THE ABOVE WARRANTY SHALL CONSTITUTE THE USER'S SOLE AND EXCLUSIVE REMEDIES
AGAINST OMRON AND THERE ARE NO OTHER WARRANTIES, EXPRESSED OR IMPLIED,
INCLUDING BUT NOT LIMITED TO, WARRANTY OF MERCHANTABILITY OR FITNESS FOR A
PARTICULAR PURPOSE. IN NO EVENT WILL OMRON BE LIABLE FOR ANY LOST PROFITS OR
OTHER INDIRECT, INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF
USE OF THE SOFTWARE.
(2) OMRON SHALL ASSUME NO LIABILITY FOR DEFECTS IN THE SOFTWARE BASED ON
MODIFICATION OR ALTERATION OF THE SOFTWARE BY THE USER OR ANY THIRD PARTY.
(3) OMRON SHALL ASSUME NO LIABILITY FOR SOFTWARE DEVELOPED BY THE USER OR ANY
THIRD PARTY BASED ON THE SOFTWARE OR ANY CONSEQUENCE THEREOF.
xvii
Application Considerations
SUITABILITY FOR USE
THE USER SHALL NOT USE THE SOFTWARE FOR A PURPOSE THAT IS NOT DESCRIBED IN THE
ATTACHED USER MANUAL.
xviii
Disclaimers
CHANGE IN SPECIFICATIONS
The software specifications and accessories may be changed at any time based on improvements or for
other reasons.
EXTENT OF SERVICE
The license fee of the Software does not include service costs, such as dispatching technical staff.
xix
xx
PRECAUTIONS
This section provides general precautions for using the CX-Programmer and the Programmable Logic Controller.
The information contained in this section is important for the safe and reliable application of the CX-Programmer
and Programmable Controller. You must read this section and understand the information contained before
attempting to set up or operate the CX-Programmer and Programmable Controller.
1
2
3
4
Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
General Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Safety Precautions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Application Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xxii
xxii
xxii
xxiii
xxi
Intended Audience
Intended Audience
This manual is intended for the following personnel, who must also have
knowledge of electrical systems (an electrical engineer or the equivalent).
Personnel in charge of installing FA systems.
Personnel in charge of designing FA systems.
Personnel in charge of managing FA systems and facilities.
General Precautions
The user must operate the product according to the performance specifications described in the operation manuals.
Before using the product under conditions which are not described in the
manual or applying the product to nuclear control systems, railroad systems,
aviation systems, vehicles, combustion systems, medical equipment, amusement machines, safety equipment, and other systems, machines, and equipment that may have a serious influence on lives and property if used
improperly, consult your OMRON representative.
Make sure that the ratings and performance characteristics of the product are
sufficient for the systems, machines, and equipment, and be sure to provide
the systems, machines, and equipment with double safety mechanisms.
This manual provides information for programming and operating the product.
Be sure to read this manual before attempting to use the product and keep
this manual close at hand for reference during operation.
!WARNING It is extremely important that a PLC and all PLC Units be used for the specified purpose and under the specified conditions, especially in applications that
can directly or indirectly affect human life. You must consult with your OMRON
representative before applying a PLC System to the above-mentioned applications.
Safety Precautions
!WARNING Confirm safety sufficiently before transferring I/O memory area status from the
CX-Programmer to the actual CPU Unit. The devices connected to Output
Units may malfunction, regardless of the operating mode of the CPU Unit.
Caution is required in respect to the following functions.
Transferring from the CX-Programmer to real I/O (CIO Area) in the CPU
Unit using the PLC Memory Window.
Transferring from file memory to real I/O (CIO Area) in the CPU Unit using
the Memory Card Window.
!Caution Variables must be specified either with AT settings (or external variables), or
the variables must be the same size as the data size to be processed by the
instruction when specifying the first or last address of multiple words in the
instruction operand.
1. If a non-array variable with a different data size and without an AT setting
is specified, the CX-Programmer will output an error when compiling.
2. Array Variable Specifications
xxii
Application Precautions
Application Precautions
Observe the following precautions when using the CX-Programmer.
User programs cannot be uploaded to the CX-Programmer.
Observe the following precautions before starting the CX-Programmer.
Exit all applications not directly related to the CX-Programmer. Particularly exit any software such as screen savers, virus checkers, E-mail
or other communications software, and schedulers or other applications that start up periodically or automatically.
xxiii
Application Precautions
Disable sharing hard disks, printers, or other devices with other computers on any network.
With some notebook computers, the RS-232C port is allocated to a
modem or an infrared line by default. Following the instructions in documentation for your computer and enable using the RS-232C port as
a normal serial port.
With some notebook computers, the default settings for saving energy
do not supply the rated power to the RS-232C port. There may be both
Windows settings for saving energy, as well as setting for specific computer utilities and the BIOS. Following the instructions in documentation for your computer, disable all energy saving settings.
Do not turn OFF the power supply to the PLC or disconnect the connecting cable while the CX-Programmer is online with the PLC. The computer
may malfunction.
Confirm that no adverse effects will occur in the system before attempting
any of the following. Not doing so may result in an unexpected operation.
Changing the operating mode of the PLC.
Force-setting/force-resetting any bit in memory.
Changing the present value of any word or any set value in memory.
Check the user program for proper execution before actually running it on
the Unit. Not checking the program may result in an unexpected operation.
When online editing is performed, the user program and parameter area
data in CJ2, CS1-H, CJ1-H, CJ1M, and CP1H CPU Units is backed up in
the built-in flash memory. The BKUP indicator will light on the front of the
CPU Unit when the backup operation is in progress. Do not turn OFF the
power supply to the CPU Unit when the BKUP indicator is lit. The data will
not be backed up if power is turned OFF. To display the status of writing to
flash memory on the CX-Programmer, select Display dialog to show PLC
Memory Backup Status in the PLC properties and then select Windows PLC Memory Backup Status from the View Menu.
Programs including function blocks (ladder programming language or
structured text (ST) language) can be downloaded or uploaded in the
same way as standard programs that do not contain function blocks.
Tasks including function blocks, however, cannot be downloaded in task
units (uploading is possible).
If a user program containing function blocks created on the CX-Programmer Ver. 5.0 or later is downloaded to a CPU Unit that does not support
function blocks (CS/CJ-series CPU Units with unit version 2.0 or earlier),
all instances will be treated as illegal commands and it will not be possible
to edit or execute the user program.
If the input variable data is not in boolean format, and numerical values
only (e.g., 20) are input in the parameters, the actual value in the CIO
Area address (e.g., 0020) will be passed. Therefore, be sure to include an
&, #, or +, - prefix before inputting the numerical value.
Addresses can be set in input parameters, but an address itself cannot be
passed as an input variable. (Even if an address is set as an input parameter, the value passed to the function block will be that for the size of data
of the input variable.) Therefore, an input variable cannot be used as the
operand of an instruction in the function block when the operand specifies
the first or last of multiple words. With CX-Programmer version 7.0, use
xxiv
Application Precautions
xxv
Application Precautions
xxvi
Part 1:
Function Blocks
SECTION 1
Introduction to Function Blocks
This section introduces the function block functionality of the CX-Programmer and explains the features that are not
contained in the non-function block version of CX-Programmer.
1-1
1-2
1-1-1
1-1-2
1-1-3
1-1-4
Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
11
1-2-1
11
Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1-2-2
12
1-2-3
13
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
1-3-1
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
1-3-2
19
1-3-3
Variable Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
1-3-4
20
1-3-5
21
1-4
23
1-5
Usage Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
1-5-1
23
1-5-2
24
25
1-3
1-6
Section 1-1
1-1
1-1-1
The IEC 61131 standard was defined by the International Electrotechnical Commission (IEC) as an international programmable logic controller (PLC) standard. The standard is divided into 7 parts.
Specifications related to PLC programming are defined in Part 3
Textual Languages (IEC 61131-3).
Section 1-1
1-1-2
Item
Model number
Setup disk
Compatible CPU Units (PLC models)
Specifications
WS02-CXPC1-E-V7
CD-ROM
CS/CJ-series CS1-H, CJ1-H, and CJ1M CPU Units with unit version 3.0 or later
are
compatible.
Note The function block and structured
Device Type
CPU Type
text functions supported by CS/
CJ-series CPU Units with unit ver- CJ2H
CJ2H-CPU68/67/66/65/64/68-EIP/67-EIP/66-EIP/65-EIP
sion 4.0 or later can not be used
/64-EIP
in CS/CJ-series CPU Units with
CS1G-H
CS1G-CPU42H/43H/44H/45H
unit version 3.0 or earlier, CPCS1H-CPU63H/64H/65H/66H/67H
series PLCs, NSJ-series PLCs, or CS1H-H
CJ1G-H
CJ1G-CPU42H/43H/44H/45H
FQM1-series PLCs.
For details, refer to 1-6 Version
CJ1H-H
CJ1H-CPU65H/66H/67H/64H-R/65H-R/66H-R/67H-R
Upgrade Information.
CJ1M
CJ1M-CPU11/12/13/21/22/23
The following CP-series CPU Units are compatible.
CP1H
CP1H-X/XA/Y
CP1L
CP1L-M/L
Note If a user program containing function blocks created on the CX-Programmer Ver. 5.0 or later is downloaded to a CPU Unit that does not support
function blocks (CS/CJ-series CPU Units with unit version 2.0 or earlier),
all instances will be treated as illegal commands and it will not be possible to edit or execute the user program.
NSJ
Functions not
supported by
CX-Programmer Ver. 4.0
or earlier.
Item
Defining
and creating function blocks
Section 1-1
Specifications
Number of
CJ2H Units:
function
CJ2H-CPU6@(-EIP): 2,048 max. per CPU Unit
block definiCS1-H/CJ1-H CPU Units:
tions
Suffix -CPU44H/45H/64H/65H/66H/67H/64H-R/65H-R/66H-R/67H-R: 1,024
max. per CPU Unit
Suffix -CPU42H/43H/63H: 128 max. per CPU Unit
CJ1M CPU Units:
CJ1M-CPU11/12/13/21/22/23: 128 max. per CPU Unit
CP1H CPU Units:
All models: 128 max. per CPU Unit
CP1L CPU Units:
CP1L-M/L: 128 max. per CPU Unit
NSJ Controllers:
NSJ@-@@@@-G5D: 1,024 max. per Controller;
NSJ@-@@@@-M3D: 128 max. per Controller
FQM1 Flexible Motion Controllers:
FQM1-CM002/MMA22/MMP22: 128 max. per Controller
Function
64 characters max.
block
names
Section 1-1
Functions not
supported by
CX-Programmer Ver. 4.0
or earlier.
Item
Defining
Variables
and creating function blocks
Variable names
Variable types
Specifications
30,000 characters max.
Input variables (Inputs), output variables (Outputs), input-output variables (In Out), internal
variables (Internals), and external variables
(Externals)
Language
Creating
instances
Number of
instances
Storing
function
blocks as
files
Instance
names
Project files
Program
files
Function
block library
files
Note
The structured text (ST language) conforms to the IEC 61131-3 standard, but
CX-Programmer Ver. 5.0 supports only assignment statements, selection
statements (CASE and IF statements), iteration statements (FOR, WHILE,
REPEAT, and EXIT statements), RETURN statements, arithmetic operators,
logical operators, comparison functions, numeric functions, standard string
functions, numeric string functions, OMRON expansion functions, and comments. For details, refer to SECTION 5 Structured Text (ST) Language Specifications in Part 2: Structured Text (ST).
Section 1-1
1-1-3
PLC2
Note
When function blocks are nested, all of the nested (destination) function block
definitions are included in this function block library file (.cxf).
1-1-4
Instances created
in program
sections.
Data equivalent to that in project files created with CX-Programmer Ver. 6.0
(*.cxp) can be saved as CXT text files (*.cxt).
Main Menu
Main
menu
File
Submenu
Function Block
Shortcut
Function
Reads the saved function block library files (*.cxf).
Saves the created function block definitions to a file ([function block library file]*.cxf).
Section 1-1
View
Submenu
Update Function Block
---
To Lower Layer
---
---
Monitor FB Instance
---
To Lower Layer
---
To Upper Layer
---
Window
Insert
PLC
Program
Shortcut
FB Instance
Viewer
---
Memory Function
AllocaBlock/
tion
SFC
Memory
Function Block
/SFC Memory
Allocation
Function Block
/SFC Memory
Statistics
Function Block
Instance
Address
Optimize Function Block/SFC
Memory
Begin
Send Change
---
Cancel
---
Transfer FB
Source
Release FB
Online Edit
Access Rights
---
Online Edit
Function
When a function block definitions input variables, output
variables, or input-output variables have been changed
after the instance was created, an error will be indicated by
displaying the instances left bus bar in red. This command
updates the instance with the new information and clears
the error.
Jumps to the function block definition for the selected
instance.
Generates a ladder-programmed function block for the
selected program section while automatically determining
address application conditions.
When monitoring the program online, monitors ST variable
status as well as I/O bit and word status (I/O bit monitor) of
the ladder diagram in the instance.
(Supported by CX-Programmer Ver. 6.1 and later only).
Displays on the right side the contents of the function block
definition of the selected instance. (Supported by CX-Programmer Ver. 6.0 and later only.)
Returns to the calling instance (ladder diagram or ST).
(Supported by CX-Programmer Ver. 6.0 and later only.)
Displays the FB Instance Viewer. (When nesting, the display shows details such as the relationship between
instance nesting levels and allocated variable addresses in
the instances.)
Creates an instance in the program (section) at the present
cursor location.
When the cursor is located to the left of an input variable or
the right of an output variable, sets the variables input or
output parameter.
Sets the range of addresses (function block instance areas)
internally allocated to the selected instances variables.
---
---
---
-----
---
Section 1-1
Submenu
Simulation
Shortcut
Break Point |
Set/Clear
Break Point
Break Point |
Clear All Break
Point
Mode | Run
(Monitor Mode)
Mode | Stop
(Program
Mode)
Mode | Pause
Step Run
Step Run |
Step In
Step Run |
Step Out
Step Run |
Continuous
Step Run
Step Run |
Scan Run
Function
---
---
---
---
-------
---
---
---
Used with the Step Run or Continuous Step Run commands to automatically scroll the display and always show
the pause point.
Displays a list of the break points that have been set.
(Operation can be jumped to a specified point.)
Function
Creates a function block definition with a ladder programming language algorithm.
Creates a function block definition with an ST language algorithm.
Reads a function block definition from a function block library file (*.cxf).
10
Function
Displays the contents of the selected function block definition on the right side
of the window.
Saves the selected function block definition in a file.
Compiles the selected function block definition.
Starts online editing of a function block.
Transfers changes made during online editing of a function block.
Cancels changes made to a function block being edited online.
Transfers only the function block source.
Forcefully releases the access rights for function block online editing held by
another user.
Section 1-2
Function Blocks
Pop-up Menu for Function Block Variable Tables
Pop-up menu
Edit
Insert Variable
Insert Variable
Function
Replace
Delete
Rename
Above
Below
Cut
Copy
Paste
Find
Function
Edit
Update Invocation
When a function block definitions input variables, output variables, or input-output variables have been changed after the instance was created, an error will be indicated by
displaying the instances left bus bar in red. This command updates the instance with
the new information and clears the error.
When monitoring the program online, monitors I/O bit and word status (I/O bit monitor)
of the ladder diagram in the instance.
(Supported by CX-Programmer Ver. 6.0 and later only).
When monitoring the program online, monitors ST variable status as well as I/O bit and
word status (I/O bit monitor) of the ladder diagram in the instance.
(Supported by CX-Programmer Ver. 6.1 and later only).
Displays the FB variables registration Dialog Box in order to register a variable from the
selected instance to the Watch Window.
Displays the selected instances function block definition on the right side of the window.
Monitor FB Instance
Shortcut Keys
F Key: Pasting Function
Block Definitions in
Program
Move the cursor to the position at which to create the copied function block
instance in the Ladder Section Window, and press the F Key. This operation is
the same as selecting Insert - Function Block Invocation.
Position the cursor at the left of the input variable or input-output variable, or
at the right of the output variable and press the Enter Key. This operation is
the same as selecting Insert - Function Block Parameter.
1-2
1-2-1
Function Blocks
Outline
A function block is a basic program element containing a standard processing
function that has been defined in advance. Once the function block has been
defined, the user just has to insert the function block in the program and set
the I/O in order to use the function.
As a standard processing function, a function block does not contain actual
addresses, but variables. The user sets addresses or constants in those variables. These address or constants are called parameters. The addresses
used by the variables themselves are allocated automatically by the CX-Programmer for each program.
11
Section 1-2
Function Blocks
With the CX-Programmer, a single function block can be saved as a single file
and reused in other PLC programs, so standard processing functions can be
made into libraries.
Program 2
Copy of function block A
Function block A
Program 1
Variable
Standard
program section
written with
variables
Input
Variable Variable
Output
Output
Define in advance.
Insert in
program.
Set
Set
Function
block A
Input
Variable Variable
Output
1-2-2
Structured
Programming
Structured programs created with function blocks have better design quality
and require less development time.
The I/O operands are displayed as variable names in the program, so the program is like a black box when entering or reading the program and no extra
time is wasted trying to understand the internal algorithm.
Many different processes can be created easily from a single function block by
using the parameters in the standard process as input variables (such as
timer SVs, control constants, speed settings, and travel distances).
Coding mistakes can be reduced because blocks that have already been
debugged can be reused.
Black-boxing Know-how
Read-protection can be set for function blocks to prevent programming knowhow from being disclosed.
Data Protection
The variables in the function block cannot be accessed directly from the outside, so the data can be protected. (Data cannot be changed unintentionally.)
Creating Libraries
Processes that are independent and reusable (such as processes for individual steps, machinery, equipment, or control systems) can be saved as function block definitions and converted to library functions.
12
Section 1-2
Function Blocks
The function blocks are created with variable names that are not tied to actual
addresses, so new programs can be developed easily just by reading the definitions from the file and placing them in a new program.
Call (Nesting)
Function block (ST language)
1-2-3
Function Block
Definitions
Function block definitions are the programs contained in function blocks. Each
function block definition contains the algorithm and variable definitions, as
shown in the following diagram.
Function Block Definition
Example: CLOCK PULSE
Algorithm
tim_a
Variable definitions
ENO
2. Variable Definitions
Usage
Name
Internal
Internal
Input
Input
tim_a
tim_b
ON_TIME
OFF_TIME
Type
TIMER
TIMER
INT
INT
1. Algorithm
Standardized programming is written with variable names rather than real I/O
memory addresses. In the CX-Programmer, algorithms can be written in
either ladder programming or structured text.
2. Variable Definitions
The variable table lists each variables usage (input, output, input-output, or
internal) and properties (data type, etc.). For details, refer to 1-3 Variables.
Number of Function Block
Definitions
The maximum number of function block definitions that can be created for one
CPU Unit is either 128 or 1,024 depending on the CPU Unit model.
13
Section 1-2
Function Blocks
Instances
Standard
program unit
with variable
names a, b, c,
etc.
Instance
Program
Insert in
program.
Automatic
allocation
Input
data
b
c
Output data
Output data
2. Parameters
Table defining usage
and properties of
variables a, b, c, etc.
Memory
used
1. Algorithm
Automatic
allocation
Memory
for FB1_2
Insert in
program.
Instance FB1_2 of function block definition FB1
Input
data
b
c
Note
Memory
for FB1_1
Output data
Output data
Instances are managed by names. More than one instance with the same
name can also be inserted in the program. If two or more instances have the
same name, they will use the same internal variables. Instances with different
names will have different internal variables.
For example, consider multiple function blocks that use a timer as an internal
variable. In this case all instances will have to be given different names. If
more than one instance uses the same name, the same timer would be used
in multiple locations, resulting in duplicated use of the timer.
If, however, internal variables are not used or they are used only temporarily
and initialized the next time an instance is executed, the same instance name
can be used to save memory.
instance_A
TIMER_FB
Function Block Definition
TIMER_FB
Variable Definitions
Internal variable: WORK_NUM
instance_A
TIMER_FB
instance_B
TIMER_FB
Number of Instances
14
Section 1-2
Function Blocks
Parameters
Each time an instance is created, set the real I/O memory addresses or constants for input variables, output variables, and input-output variables used to
pass input data values to instances and obtain output data values from
instances. These addresses and constants are called parameters.
Instance of Function Block Definition A
Input 0.00
Input 3.00
Output 2.00
Input D100
Input D200
Output D300
Examples:
If m is type WORD, one word of data from D100 will be passed to the
variable.
If n is type DWORD, two words of data from D200 and D201 will be
passed to the variable.
If k is type LWORD, four words of data from the variable will be passed
to the D300 to D303.
Note
(1) Only addresses in the following areas can be used as parameters: CIO
Area, Auxiliary Area, DM Area, EM Area (banks 0 to C), Holding Area,
and Work Area.
The following cannot be used: Index and Data Registers (both direct and
indirect specifications) and indirect addresses to the DM Area and EM
Area (both in binary and BCD mode).
(2) Local and global symbols in the user program can also be specified as
parameters. To do so, however, the data size of the local or global symbol
must be the same as the data size of the function block variable.
(3) When an instance is executed, input values are passed from parameters
to input variables before the algorithm is processed. Output values are
15
Section 1-2
Function Blocks
passed from output variables to parameters just after processing the algorithm. If it is necessary to read or write a value within the execution cycle of the algorithm, do not pass the value to or from a parameter. Assign
the value to an internal variable and use an AT setting (specified addresses).
!Caution If an address is specified in an input parameter, the values in the address are
passed to the input variable. The actual address data itself cannot be passed.
!Caution Parameters cannot be used to read or write values within the execution cycle
of the algorithm. Use an internal variable with an AT setting (specified
addresses). Alternatively, reference a global symbol as an external variable.
Using Input-Output Variables (In Out)
When using an input-output variable, set the address for the input parameter.
A constant cannot be set. The address set for the input parameter will be
passed to the function block. If processing is performed inside the function
block using the input-output variable, the results will be written to I/O starting
at the address set for the size of the variable.
Program
Instance of function block definition A
Automatically set.
Input D200
Output D200
Address passed.
Address passed.
a changed by function
block processing.
D200
D201
Variable a
Note
16
Section 1-2
Function Blocks
Reference Information
Cyclic task 0
CASCADE_01
P_On
EN
&20
&10
CONTROL
ENO
1.0
ON_TIME
OFF_TIME
Algorithm
Variables
Example:
There are 3 FB
instances and each
has its own I/O and
internal variables.
Instance
CASCADE_02
Algorithm
CASCADE_02
P_On
EN
&15
Instance
CASCADE_03
Algorithm
&10
CONTROL
ENO
1.1
ON_TIME
OFF_TIME
Cyclic task 1
CASCADE_03
P_On
EN
&7
&8
CONTROL
ENO
1.2
ON_TIME
OFF_TIME
If internal variables are not used, if processing will not be affected, or if the
internal variables are used in other locations, the same instance name can be
used at multiple locations in the program.
Cyclic taskCASCADE
0
P_On
&100
&130
CONTROL
EN
ENO
1.0
PARA_1
PARA_2
Algorithm
Variables
Instance
CASCADE
Algorithm
Internal and I/O
variables
P_On
&50
&150
CASCADE
CONTROL
EN
ENO
1.1
PARA_1
PARA_2
Cyclic taskCASCADE
1
P_On
&100
&200
CONTROL
EN
ENO
1.2
PARA_1
PARA_2
Some precautions are required when using the same memory area. For
example, if the same instance containing a timer instruction is used in more
than one program location, the same timer number will be used causing coil
duplication, and the timer will not function properly if both instructions are executed.
17
Section 1-3
Variables
Registration of Instances
Each instance name is registered in the global symbol table as a file name.
Program
Instance (sample) of function block definition A
b
c
Data type
sample FB [FunctionBlock1]
Instance name
1-3
1-3-1
Address/
value
N/A[Auto]
Variables
Introduction
In a function block, the addresses (see note) are not entered as real I/O memory addresses, they are all entered as variable names. Each time an instance
is created, the actual addresses used by the variable are allocated automatically in the specified I/O memory areas by the CX-Programmer. Consequently, it isnt necessary for the user to know the real I/O memory addresses
used in the function block, just as it isnt necessary to know the actual memory allocations in a computer. A function block differs from a subroutine in this
respect, i.e., the function block uses variables and the addresses are like
black boxes.
Example:
Program
Function block definition A
c
MOV
a
c
AT
BOOL
BOOL
Usage: Outputs
Properties:
Name Type
BOOL
b
Note
18
AT
Input 0.00
Input 3.00
Output 2.00
Status of 0.00 (1 or 0) is
passed to a.
0.00 1
Status of b (1 or 0) is
passed to 2.00.
b
2.00
Status of 3.00 (1 or 0) is
passed to c.
Properties:
Name Type
Insert in
program.
3.00 0
Constants are not registered as variables. Enter constants directly in instruction operands.
Section 1-3
Variables
1-3-2
Variable Usage
Inputs:
Outputs:
In Out:
Input-output variables can input data from input parameters outside of the instance and can return the results of processing in a
function block instance to external parameters.
1-3-3
Variable Properties
Variables have the following properties.
Variable Name
The variable name is used to identify the variable in the function block. It
doesnt matter if the same name is used in other function blocks.
Note
Data Type
The variable name can be up to 30,000 characters long, but must not begin
with a number. Also, the name cannot contain two underscore characters in a
row. The character string cannot be the same as that of a an index register
such as in IR0 to IR15. For details on other restrictions, refer to Variable Definitions in 2-1-2 Function Block Elements.
Select one of the following data types for the variable:
BOOL, INT, UINT, DINT, UDINT, LINT, ULINT, WORD, DWORD, LWORD,
REAL, LREAL, TIMER, COUNTER, and STRING
For details on variable data types, refer to Variable Definitions in 2-1-2 Function Block Elements.
AT Settings (Allocation to
an Actual Addresses)
19
Section 1-3
Variables
A variable can be treated as a single array of data with the same properties.
To convert a variable to an array, specify that it is an array and specify the
maximum number of elements.
This property can be set for internal variables and input-output variables only.
Only one-dimensional arrays are supported by the CX-Programmer Ver. 5.0
and later versions.
Setting Procedure
Click the Advanced Button, select the Array Variable option, and input the
maximum number of elements.
When entering an array variable name in the algorithm in a function block
definition, enter the array index number in square brackets after the variable number.
For details on array settings, refer to Variable Definitions in 2-1-2 Function
Block Elements.
Initial Value
This is the initial value set in a variable before the instance is executed for the
first time. Afterwards, the value may be changed as the instance is executed.
For example, set a boolean (BOOL) variable (bit) to either 1 (TRUE) or 0
(FALSE). Set a WORD variable to a value between 0 and 65,535 (between
0000 and FFFF hex).
If an initial value is not set, the variable will be set to 0. For example, a boolean variable would be 0 (FALSE) and a WORD variable would be 0000 hex.
Retain
Select the Retain Option if you want a variables data to be retained when the
PLC is turned ON again and when the PLC starts operating.
Setting Procedure
Select the Retain Option.
Size
1-3-4
When a STRING variable is used, the size required to store the text string can
be set to between 1 and 255 characters.
Name
Data Type
AT (specified
address)
Array specification
Initial Value
Must be set.
Can be set.
Retained
Can be set.
Size
Can be set.
(See note 2.)
Variable usage
Inputs
Outputs
In Out
Must be set.
Must be set.
Must be set.
Must be set.
Must be set.
Must be set.
Cannot be set. Cannot be set. Cannot be set.
Cannot be set.
Cannot be set.
(See note 1.)
Cannot be set.
(See note 1.)
Cannot be set.
20
Cannot be set.
Section 1-3
Variables
1-3-5
Program
Instance of function block definition A
Non-retained area
Starting address
Input 0.00
15
CIO, H, W,
D, or E Area
Output 2.00
Size (words)
Output 5.00
Note: Variable c is an internal
variable, so it is not displayed.
Usage: Inputs
Properties:
Name Type AT
a
BOOL
Retained area
Starting address
15
H, D, or E
Area
Name Type
b
t
AT
Usage: Internals
Properties:
Name Type
c
AT
InitialValueRetained
BOOL 2000.00
T Area
Size (Completion
Flags)
C Area
Size (Completion
Flags)
Counter area
YES
BOOL
TIMER
Size (words)
Timer area
Starting address
Usage: Outputs
Properties:
Automatic allocation of
addresses by system
Starting
address
Example
2000.00
The user sets the function block instance areas in which addresses are allocated internally by the system. The variables are allocated automatically by
the system to the appropriate instance area set by the user.
Setting Procedure
Select Function Block/SFC Memory - Function Block/SFC Memory Allocation from the PLC Menu. Set the areas in the Function Block/SFC Memory
Allocation Dialog Box.
21
Section 1-3
Variables
Function Block Instance Areas
CJ2-series CPU Units
FB Instance
Area
Note
Non Retain
Default value
Start address End address
H512
H1407
Size
896
Retain
Timers
Counters
H1408
T3072
C3072
128
1024
1024
H1535
T4095
C4095
Applicable memory
areas
CIO, WR, HR, DM,
EM (See note.)
HR, DM, EM (See note.)
TIM
CNT
EM bank 3
EM banks 6 to 9
EM banks 7 to E
EM banks 11 to 18
Default value
Start address End address
H512
H1407
H1408
H1535
T3072
T4095
C3072
C4095
Size
896
128
1024
1024
Applicable memory
areas
CIO, WR, HR, DM, EM
HR, DM, EM
TIM
CNT
Default value
Start address End address
5000
5999
None
T206
T255
C206
C255
Applicable memory
areas
Size
1000
CIO, WR, DM
50
50
TIM
CNT
Note
Non Retain
Default value
Start address End address
H512
H1407
Size
896
Retain
Timers
Counters
H1408
T3072
C3072
128
1024
1024
DM area of CP1L-L
Address
D0000 to D9999
D10000 to D31999
D32000 to D32767
22
H1535
T4095
C4095
CP1L-L
Provided
Not Provided
Provided
Applicable memory
areas
CIO, WR, HR, DM (See
note.)
HR, DM (See note.)
TIM
CNT
Section 1-4
1-4
The Function Block Holding Area words are allocated from H512 to H1535.
These words are different to the standard Holding Area used for programs
(H000 to H511) and are used only for the function block instance area (internally allocated variable area). These words cannot be specified as instruction
operands. They are displayed in red if input when a function block is not being
created. Although the words can be input when creating a function block, an
error will occur when the program is checked. If this area is specified not to be
retained in the Function Block Memory Allocation Dialog Box, turn the power
ON/OFF or clear the area without retaining the values when starting operation.
Project
Function block definition
Example: CLOCK_PULSE
1. Algorithm
1. Algorithm
Save
tim_b
Read
tim_b
TIMX tim_a OFF_TIME
tim_a
tim_a
ENO
ENO
2. Variable Definitions
Usage
Name
Internal
Internal
Input
Input
1-5
tim_a
tim_b
ON_TIME
OFF_TIME
2. Variable Definitions
Usage
Name
Type
Internal
Internal
Input
Input
TIMER
TIMER
INT
INT
tim_a
tim_b
ON_TIME
OFF_TIME
Type
TIMER
TIMER
INT
INT
Function block
definition file (.cxf)
Usage Procedures
Once a function block definition has been created and an instance of the algorithm has been created, the instance is used by calling it when it is time to
execute it. Also, the function block definition that was created can be saved in
a file so that it can be reused in other projects (PLCs).
1-5-1
1. First, create the function block definition including the algorithm and variable definitions in ladder program or ST language. Alternatively, insert a
function block library file that has been prepared in advance.
Note (a) Create the algorithm entirely with variable names.
(b) When entering the algorithm in ladder programming language,
project files created with versions of CX-Programmer earlier than
Ver. 5.0 can be reused by reading the project file into CX-Programmer Ver. 5.0 or higher and copying and pasting useful parts.
(c) Existing ladder programming can be automatically turned into a
function block using Edit - Function Block (ladder) generation.
2. When creating the program, insert copies of the completed function block
definition. This step creates instances of the function block.
3. Enter an instance name for each instance.
23
Section 1-5
Usage Procedures
4. Set the variables input source addresses and/or constants and output
destination addresses and/or constants as the parameters to pass data for
each instance.
5. Select the created instance, select Function Block Memory - Function
Block Memory Allocation from the PLC Menu, and set the internal data
area for each type of variable.
6. Transfer the program to the CPU Unit.
7. Start program execution in the CPU Unit and the instance will be called and
executed if their input conditions are ON.
Function block definition A
Program
Input
condition
1. Algorithm
Standard
program section
with variable
names a, b, c,
etc.
The instance is
executed if the input
condition is established.
Insert in
program.
Input 0.00
Output 3.00
2. Variables
Table defining usage
and properties of
variables a, b, c, etc.
1-5-2
1. Select the function block that you want to save and save it as a function
block definition file (*.cxf).
2. Open the other PLCs project and open/read the function block definition
file (*.cxf) that was saved.
3. Insert the function block definition in the program when creating the new
program.
Function block definition A
Program
1. Algorithm
Input
condition
Standard
program section
with variable
names a, b, c,
etc.
Input 1.00
2. Variables
Table defining usage
and properties of
variables a, b, c, etc.
Output 5.00
Output 6.00
Read and
insert.
Save
Function
block
definition
A
Function block
definition file (*.cxf)
Note
24
In the CX-Programmer Ver. 5.0, each function block definition can be compiled and checked as a program. We recommend compiling to perform a program check on each function block definition file before saving or reusing the
file.
Section 1-6
1-6
Version 7.2
The ST language can be used in programs (task allocation) other than
function blocks. (ST programs can be allocated to tasks.)
Other programming languages can be combined freely in a single user
program. With this capability, numerical calculations can be written as
ST programs, and other processing can be written as ladder or SFC
programs.
Note Structured text is supported only by CS/CJ-series CPU Units with
unit version 4.0 or later. It is not supported by CP-series CPU
Units.
Version 7.2
Function block definitions can be compared. With this capability, it is
easy to check for differences in function block definitions in programs.
ST programs can also be compared.
25
Section 1-6
Version 7.0
One or more program sections can be selected from the program and
then Function Block (ladder) generation selected from the menu to
automatically create a function block definition and automatically allocate variables according to symbols and addresses in the program sections. (Allocations can later be changed as required.) This enables
legacy programming to be easily converted to function blocks.
Version 7.0
The algorithms and variables tables for function blocks can be changed
while the PLC is operation. (See note.) This enables debugging and
changing function block definitions in systems that cannot be stopped,
such as systems that operate 24 hours a day.
Operation: Right-click the function block definition in the Work Space
and select FB Online Edit - Begin from the pop-up menu.
Note Function block instances cannot be added.
Note This function cannot be used for simulations on CX-Simulator.
Support for STRING Data Type and Processing Functions in Standard Text Programs
Version 6.1
Version 7.0
The STRING data type (text) cannot be used in The STRING data type (text) can be used in ST programming. This
enables, for example, substituting a text string for a variable (e.g., a :=
ST programming. (See note.)
'@READ';) to easily set a variable containing text (i.e., ASCII charac There are no text processing functions supters). In doing this, the user does not have to be concerned with the
ported for ST programming.
ASCII code or code size.
Even in a ladder program, the user has to con
Text processing functions are supported for ST programming, includsider the ASCII code and code size of text for
display messages and no-protocol communica- ing text extraction, concatenation, and searching. This enables easily
tions (see note) when executing string process- processing text strings and display messages in ST programming
inside function blocks.
ing instructions, data conversion instructions,
Functions are also supported for sending and receiving text strings.
and serial communications instructions.
This enables easily processing no-protocol communications using ST
Note The user can use the PLC memory funcprogramming in functions blocks without being concerned with ASCII
tion of the CX-Programmer to input text
strings in I/O memory. The data size in I/O codes.
memory, however, must be considered.
26
Version 7.0
Input-output variables can be used in function blocks.
Input-output variables can be specified as arrays.
Addresses are passed from input parameters to input variables
instead of values. This enables using input-output variable arrays
inside function blocks to enable easily passing large amounts of data
to function blocks using the input parameters.
Section 1-6
The PLC model (device type) can be set to NSJ and the CPU type can be
set to the G5D.
The new models of the FQM1 Flexible Motion Controller are now supported
(i.e., the FQM1-CM002 Coordinator Module and the FQM1-MMA22/MMP22
Motion Control Modules).
27
Section 1-6
28
SECTION 2
Function Block Specifications
This section provides specifications for reference when using function blocks, including specifications on function blocks,
instances, and compatible PLCs, as well as usage precautions and guidelines.
2-1
2-2
2-3
2-4
30
2-1-1
30
2-1-2
31
41
2-2-1
41
2-2-2
41
Instance Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
2-3-1
Composition of an Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
2-3-2
Parameter Specifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
47
2-3-3
Operating Specifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
49
Programming Restrictions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
51
2-4-1
51
2-4-2
ST Programming Restrictions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
53
2-4-3
Programming Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
54
56
2-5-1
56
2-5-2
57
2-5-3
59
2-5-4
59
2-5-5
61
2-5-6
62
2-6
65
2-7
68
2-8
70
2-8-1
Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
70
2-8-2
2-5
2-9
75
76
2-9-1
76
2-9-2
77
29
Section 2-1
2-1
2-1-1
Number of instances
Number of instance
nesting levels
Number of variables
used in a function block
(not including internal
variables, external variables, EN, and EN0)
30
Description
CJ2H Units:
CJ2H-CPU6@(-EIP): 2,048 max. per CPU Unit
CS1-H/CJ1-H CPU Units:
Suffix -CPU44H/45H/64H/65H/66H/67H/64H-R/65H-R/
66H-R/67H-R: 1,024 max. per CPU Unit
Suffix -CPU42H/43H/63H: 128 max. per CPU Unit
CJ1M CPU Units:
CJ1M-CPU11/12/13/21/22/23: 128 max. per CPU Unit
CP1H CPU Units:
CP1H-XA/X/Y: 128 max. per CPU Unit
CP1L CPU Units:
CP1L-M/L: 128 max. per CPU Unit
NSJ Controllers:
All models: 1,024 max. per Controller
FQM1 Flexible Motion Controllers:
FQM1-CM002/MMA22/MMP22: 128 max. per Controller
CJ2H Units:
CJ2H-CPU6@(-EIP): 2,048 max. per CPU Unit
CS1-H/CJ1-H CPU Units:
Suffix -CPU44H/45H/64H/65H/66H/67H/64H-R/65H-R/
66H-R/67H-R: 2,048 max. per CPU Unit
Suffix -CPU42H/43H/63H: 256 max. per CPU Unit
CJ1M CPU Units:
CJ1M-CPU11/12/13/21/22/23: 256 max. per CPU Unit
CP1H CPU Units:
CP1H-XA/X/Y: 256 max. per CPU Unit
CP1L CPU Units:
CP1L-M/L: 256 max. per CPU Unit
NSJ Controllers:
All models: 2,048 max. per Controller
FQM1 Flexible Motion Controllers:
FQM1-CM002/MMA22/MMP22: 256 max. per Controller
CX-Programmer Ver. 5.0:
Nesting is not supported.
CX-Programmer Ver. 6.0 and later versions:
Supports nesting up to 8 levels. (The instance called from
the program is counted as one nesting level.)
Maximum number of variables per function block definition
Input-output variables: 16 max.
Input variables + input-output variables: 64 max.
Output variables + input-output variables: 64 max.
Section 2-1
2-1-2
Description
The name of the function block definition
Language
The programming language used in the function block definition. Select ladder programming or structured text
Variable settings, such as operands and return values,
required when the function block is executed
Type (usage) of the variable
Name of the variable
Data type of the variable
Initial value of the variable
Enter the programming logic in ladder or structured text.
Enter the programming logic using variables.
Input constants directly without registering in variables.
Function blocks can have comments.
Variable definitions
Algorithm
Comment
Function Block
Definition Name
Each function block definition has a name. The names can be up to 64 characters long and there are no prohibited characters. The default function block
name is FunctionBlock@, where @ is a number (assigned in order).
Function block definition name
CLOCK PULSE
EN
ENO
(BOOL) (BOOL)
ON_TIME
(INT)
OFF_TIME
(INT)
Language
Variable Definitions
Variable Names
Define the operands and variables used in the function block definition.
Variable names can be up to 30,000 characters long.
Variables name cannot contain spaces or any of the following characters:
! # $ % & ( ) = - ~ ^ \ | @ { [ + ; * : } ] < , > . ? /
Variable names cannot start with a number (0 to 9).
Variable names cannot contain two underscore characters in a row.
The following characters cannot be used to indicate addresses in I/O
memory.
A, W, H (or HR), D (or DM), E (or EM), T (or TIM), C (or CNT) followed
by the numeric value (word address)
31
Section 2-1
Variable table
Usage
Internal
Internal
Input
Input
Name
Type
TIMER
TIMER
tim_a
tim_b
ON_TIME
OFF_TIME
INT
INT
Output variables
Input variables
tim_b
TIMX tim_a OFF_TIME
tim_a
TIMX tim_b OFF_TIME
ENO
Internal
variables
Outputs
Operands to the
instance
Status of value
at next execution
Display
Note
Variable type
In Out
The value is
passed on to the
next execution.
Displayed on the
right side of the
instance.
64 max. per function block (excluding ENO)
No
No
Supported
ENO (Enable Output):
Outputs the function blocks execution status.
Internals
Variables used
only within
instance
Externals
(See note 1.)
Global symbols
registered as variables beforehand
with the CX-Programmer or userdefined global
symbols.
The value of the
variable registered
externally
Not displayed.
Unlimited
No
Supported
No
Supported
Supported
Supported
No
No
No
None
None
32
Section 2-1
P_On
1.0
FB
EN
ENO
D0
D100
PV
CV
Example
0.0
ADD_INT_DINT
EN
ENO
D100
IN16
OUT32
10.0
Algorithm (Body)
P_On
SIGN IN16
+L IN32
D200
tmp OUT32
IN32
Note
tmp
D1000
Variable table
Usage
Name
Internal tmp
EN
Input
IN16
Input
IN32
Input
Output ENO
Output OUT32
Type
DINT
BOOL
INT
DINT
BOOL
DINT
1. The same name cannot be assigned to an input variable and output variable. If it is necessary to receive a value from an external variable, change
the variable inside the function block, and then return the result to the external variable, use an input-output variable.
2. When the instance is executed, input values are passed from parameters
to input variables before the algorithm is processed. Consequently, values
cannot be read from parameters to input variables within the algorithm. If
it is necessary to read a value within the execution cycle of the algorithm,
do not pass the value from a parameter. Assign the value to an internal
variable and use an AT setting (specified addresses). Alternatively, reference the global symbol as external variables.
Initial Value
Initial values can be set for input variables, but the value of the input parameter will be enabled (the input parameter value will be set when the parameter
for input variable EN goes ON and the instance is executed).
Note
The input parameter setting cannot be omitted when using the CXProgrammer.
EN (Enable) Variable
When an input variable is created, the default input variable is the EN variable.
The instance will be executed when the parameter for input variable EN is ON.
Output Variables
Output variables pass return values from the instance to external applications.
The output variables are displayed on the right side of the instance.
After the instance is executed, the value of the output variable is passed to the
specified parameter.
33
Section 2-1
P_On
EN
D0
1.0
FB
ENO
PV
CV
D100
Example
0.0
ADD_INT_DINT
EN
ENO
D100
IN16
D200
OUT32
10.0
Algorithm (Body)
EN
SIGN IN16 tmp
D1000
+L IN32
IN32
Variable table
Usage
Name
Internal tmp
EN
Input
IN16
Input
IN32
Input
Output ENO
Output OUT32
tmp OUT32
Data type
DINT
BOOL
INT
DINT
BOOL
DINT
Like internal variables, the values of output variables are retained until the
next time the instance is executed (i.e., when EN turns OFF, the value of the
output variable is retained).
Example:
In the following example, the value of output variable CV will be retained until
the next time the instance is executed.
Product A counter
CTD
CD
LD
PV
Note
CV
D150
1. The same name cannot be assigned to an input variable and output variable. If it is necessary to receive a value from an external variable, change
the variable inside the function block, and then return the result to the external variable, use an input-output variable.
2. When the instance is executed, output variables are passed to the corresponding parameters after the algorithm is processed. Consequently, values cannot be written from output variables to parameters within the
algorithm. If it is necessary to write a value within the execution cycle of the
algorithm, do not write the value to a parameter. Assign the value to an internal variable and use an AT setting (specified addresses).
Initial Value
An initial value can be set for an output variable that is not being retained, i.e.,
when the Retain Option is not selected. An initial value cannot be set for an
output variable if the Retain Option is selected.
The initial value will not be written to the output variable if the IOM Hold Bit
(A50012) is ON.
Auxiliary Area control bit
IOM Hold Bit (A50012)
ON
34
Initial value
The initial value will not be set.
Section 2-1
The ENO variable is created as the default output variable. The ENO output
variable will be turned ON when the instance is called. The user can change
this value. The ENO output variable can be used as a flag to check whether or
not instance execution has been completed normally.
Input-Output Variables
Input-output variables use addresses to pass data to and from a function
block instance. An input-output variable is displayed on both the left and right
side of the instance. The value of the input-output variable immediately after
the instance is executed is not stored in the addresses internally allocated to
the input-output variable by the system, but rather the value is stored in the
address (and following addresses depending on the data size) of the parameter used to pass data to and from the input-output variable.
P_ON
D200
1.0
FB
EN
ENO
CAL
CAL
D200
Note
CLOCK PULSE
EN
ENO
1.0
&20
ON_TIME
&10
Variable table
Name
Usage
Internal tim_a
Internal tim_b
ON_TIME
Input
OFF_TIME
Input
Data type
TIMER
TIMER
INT
INT
OFF_TIME
Pulse_4sON_1sOFF
P_On
CLOCK PULSE
EN
ENO
1.1
&40
ON_TIME
&10
OFF_TIME
35
Section 2-1
0.0
ADD_INT_DINT
EN
ENO
D100
IN16
D200
OUT32
10.0
Algorithm (Body)
EN
SIGN IN16 tmp
D1000
+L IN32
IN32
tmp OUT32
Variable table
Name
Internal tmp
EN
Input
IN16
Input
IN32
Input
Output ENO
Output OUT32
Type
DINT
BOOL
INT
DINT
BOOL
DINT
Condition
Start of operation
Power ON
Status
Retained
Retained
When the Retain Option is not selected, the value of the variable will not be
held when the power is interrupted or operation starts. Even variables not set
to be retained, however, can be held at the start of operation by turning ON
the IOM Hold Bit (A50012) and can be held during power interruptions by setting the PLC Setup, as shown in the following table.
Variables
Condition
OFF
Variables not
set to Retain
Note
The IOM Hold Bit (A50012) is supported for compatibility with previous models. To hold the values of variables in function blocks, however, use the Retain
Option and not the IOM Hold Bit.
Initial Value
An initial value can be set for an internal variable that is not being retained
(i.e., when the Retain Option not selected). An initial value cannot be set for
an internal variable if the Retain Option is selected.
Internal variables that are not being retained will be initialized to 0.
The initial value will not be written to the internal variable if the IOM Hold Bit
(A50012) is ON.
Auxiliary Area control bit
IOM Hold Bit (A50012)
ON
OFF
36
Initial value
The initial value will not be set.
The initial value will be set.
Section 2-1
External variables are either system-defined variables that have been registered in CX-Programmer before hand, or variables that externally reference
user-defined variables in the global symbol table.
For details on system-defined variables, refer to Appendix A Systemdefined external variables supported in function blocks.
To externally reference user-defined variables in the global symbol table,
the variables of the same name and data type must be registered as an
external variable.
However, it is impossible to externally reference the variables userdefined as a network symbol.
Variable Properties
Variable Name
The variable name is used to identify the variable in the function block. The
name can be up to 30,000 characters long. The same name can be used in
other function blocks.
Note
A variable name must be input for variables, even ones with AT settings (specified address).
Data Type
Any of the following types may be used.
Data type
BOOL
INT
UNIT
DINT
UDINT
LINT
ULINT
WORD
DWORD
LWORD
REAL
LREAL
TIMER
Content
Bit data
Integer
Unsigned integer
Double integer
Unsigned double integer
Long (4-word) integer
Unsigned long (4-word) integer
16-bit data
32-bit data
64-bit data
Real number
Long real number
Timer (See note 1.)
COUNTER
STRING
Note
Size
1 bit
16 bits
16 bits
32 bits
32 bits
64 bits
64 bits
16 bits
32 bits
64 bits
32 bits
64 bits
Flag: 1 bit
PV: 16 bits
Flag: 1 bit
PV: 16 bits
Variable
Inputs
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
Not supported
Not supported
Not supported
Outputs
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
Not supported
Not supported
Not supported
In Out
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
Not supported
Not supported
Not supported
Internals
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
OK
(1) The TIMER data type is used to enter variables for timer numbers (0 to
4095) in the operands for TIMER instructions (TIM, TIMH, etc.). When
this variable is used in another instruction, the Timer Completion Flag (1
bit) or the timer present value (16 bits) is specified (depending on the instruction operand). The TIMER data type cannot be used in structured
text function blocks.
(2) The COUNTER data type is used to enter variables for counter numbers
(0 to 4095) in the operands for COUNTER instructions (CNT, CNTR,
etc.). When this variable is used in another instruction, the Counter Completion Flag (1 bit) or the counter present value (16 bits) is specified (depending on the instruction operand). The COUNTER data type cannot be
used in structured text function blocks.
37
Section 2-1
When the AT setting is used, the function block loses its flexibility. This function should thus be used only when necessary.
Array Setting
With internal variables and input-output variables, a variable can be defined
as an array.
Note
38
Number of elements
2,048
2,048
Section 2-1
Number of elements
1,024
512
INT, DINT, LINT, UINT, UDINT, or ULINT can be used as the variable data type.
An array is a collection of data elements that are the same type of data. Each
array element is specified with the same variable name and a unique index.
(The index indicates the location of the element in the array.)
A one-dimensional array is an array with just one index number.
Example: When an internal variable named SCL is set as an array variable
with 10 elements, the following 10 variables can be used:
SCL[0], SCL[1], SCL[2], SCL[3], SCL[4], SCL[5], SCL[6], SCL[7], SCL[8], and
SCL[9]
SCL
0
1
2
3
4
5
6
7
8
9
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
Note
Use an array variable when specifying the first or last of multiple words in an
instruction operand to enable reusing the function block if an internal variable
with a AT property cannot be set for the operand and an external variable cannot be set. When using an array setting for an input-output variable, specify
the address of the first word for the input parameter (CX-Programmer version
7.0 or higher). When using an array setting for an internal variable, prepare an
array variable with the number of elements for the required size, and after set-
39
Section 2-1
ting the data in each array element, specify the first or last element in the
array variable for the operand.
Example:
Function block definition
Instance
SCL
Variable
SCL
EN
ENO
WORD[10]
100
Algorithm
SCL-BODY
SCL
LD P_On
MOV #0000 SCL[0]
MOV &0SCL[1]
MOV #0300 SCL[2]
MOV &4000 SCL[3]
SCL S SCL[0]
D
0
1
2
3
#0000
&0
#0300
&4000
Note
For details, refer to 2-6 Precautions for Instructions with Operands Specifying
the First or Last of Multiple Words.
Initial Values
When an instance is executed the first time, initial values can be set for input
variables, internal variables, and output variables. For details, refer to Initial
Value under the preceding descriptions of input variables, internal variables,
and output variables.
Algorithm
Operand Input
Restrictions
40
Section 2-2
Comment
2-2
2-2-1
Data type
BOOL
INT
DINT
LINT
UINT
UDINT
ULINT
REAL
Content
Bit data
Integer
Double integer
Long (8-byte) integer
Unsigned integer
Unsigned double integer
Unsigned long (8-byte)
integer
Real number
LREAL
Size
1
16
32
64
16
32
64
Range of values
0 (FALSE), 1 (TRUE)
32,768 to +32,767
2,147,483,648 to +2,147,483,647
9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
&0 to 65,535
&0 to 4,294,967,295
&0 to 18,446,744,073,709,551,615
32
64
WORD
DWORD
LWORD
16-bit data
32-bit data
64-bit data
16
32
64
STRING
TIMER
Variable
Flag: 1 bit
PV: 16 bits
COUNTER
Counter
Flag: 1 bit
PV: 16 bits
FUNCTION
BLOCK
---
Note
2-2-2
The TIMER and COUNTER data types cannot be used in structured text function blocks.
41
Section 2-3
Instance Specifications
2-3
2-3-1
Instance Specifications
Composition of an Instance
The following table lists the items that the user must set when registering an
instance.
Item
Instance name
Language
Variable definitions
Function block instance areas
Comments
Instance Name
Description
Name of the instance
The programming and variables are the same as in
the function block definition.
The ranges of addresses used by the variables
A comment can be entered for each instance.
Pulse_2sON_2sOFF
&20
CLOCK PULSE
EN
ENO
ON_TIME
&10
Function Block
Instance Areas
OFF_TIME
To use a function block, the system requires memory to store the instances
internal variables, input variables, output variables, and input-output variables.
These areas are known as the function block instance areas and the user
must specify the first addresses and sizes of these areas. The first addresses
and area sizes can be specified in 1-word units.
When the CX-Programmer compiles the function, it will output an error if there
are any instructions in the user program that access words in these areas.
42
Section 2-3
Instance Specifications
CJ2-series CPU Units
FB Instance
Area
Note
Non Retain
Default value
Start address End address
H512
H1407
Size
896
Retain
Timers
Counters
H1408
T3072
C3072
128
1024
1024
H1535
T4095
C4095
Applicable memory
areas
CIO, WR, HR, DM,
EM (See note.)
HR, DM, EM (See note.)
TIM
CNT
EM bank 3
EM banks 6 to 9
EM banks 7 to E
EM banks 11 to 18
Default value
Start address End address
H512
H1407
H1408
H1535
T3072
T4095
C3072
C4095
Size
896
128
1024
1024
Applicable memory
areas
CIO, WR, HR, DM, EM
HR, DM, EM
TIM
CNT
Default value
Start address End address
5000
5999
None
T206
T255
C206
C255
Applicable memory
areas
Size
1000
CIO, WR, DM
50
50
TIM
CNT
Note
Non Retain
Default value
Start address End address
H512
H1407
Size
896
Applicable memory
areas
Retain
Timers
H1408
T3072
H1535
T4095
128
1024
Counters
C3072
C4095
1024
CNT
DM area of CP1L-L
Address
D0000 to D9999
D10000 to D31999
D32000 to D32767
CP1L-L
Provided
Not Provided
Provided
43
Section 2-3
Instance Specifications
Function Block Instance
Area Types
The following settings are made in the function block instance area:
CS/CJ-series CPU Units Ver. 3.0 or Later, CP-series PLCs, and NSJ
Controllers
Non-retained Areas
Item
Allocated variables
Applicable areas
Setting unit
Allocated words
(default)
Note
Contents
Variables for which the retain property for power OFF and
operation start is set as non-retained (See note 1.)
H (Function block Special Holding Area), I/O (CIO Area), H
(Holding Area), W (Internal Relay Area), D (Data Memory
Area) (see note 2), E (Extended Data Memory Area) (See
notes 2 and 3.)
Set in words
H512 to H1407
Setting unit
Allocated words
(default)
Note
Contents
Variables for which the retain property for power OFF and
operation start is set as retained (See note 1.)
H (Function block Special Holding Area), H (Holding Area), D
(Data Memory Area) (see note 1), E (Extended Data Memory
Area) (See notes 2 and 3.)
Set in words
H1408 to H1535
Contents
Variables with TIMER set as the data type.
T (Timer Area) Timer Flag (1 bit) or timer PVs (16 bits)
T3072 to T4095 Timer Flag (1 bit) or timer PVs (16 bits)
Counter Area
44
Item
Allocated variables
Contents
Variables with COUNTER set as the data type.
Applicable areas
Allocated words
(default)
Section 2-3
Instance Specifications
Function Block Holding Area (H512 to H1535)
The default allocation of Function Block Holding Area words set as retained
and non-retained words is H512 to H1535. These words are different to the
standard Holding Area used for programs (H000 to H511), and are used only
for the function block instance area (internally allocated variable area).
These words cannot be specified in AT settings for internal variables.
These words cannot be specified as instruction operands.
These words are displayed in red if they are input when a function
block is not being created.
Although the words can be input when creating a function block, an
error will occur when the program is checked.
If this area is specified as non-retained, turn the power ON/OFF or clear
the area without retaining the values when starting operation.
Note
Default value
Start address End address
5000
5999
None
T206
T255
C206
C255
Applicable memory
areas
Size
1000
CIO, WR, DM
50
50
TIM
CNT
Non-retained Areas
Item
Allocated variables
Applicable areas
Setting unit
Allocated words
(default)
Note
Contents
Variables for which the retain property for power OFF and
operation start is set as retained. (See note 1.)
I/O (CIO), W (Work Area), and D (DM Area) (See note 2.)
Set in words
CIO 5000 to CIO 5999
Contents
Variables with TIMER set as the data type.
T (Timer Area) Timer Flag (1 bit) or timer PVs (16 bits)
T206 to T255 Timer Flag (1 bit) or timer PVs (16 bits)
Counter Area
Item
Allocated variables
Contents
Variables with COUNTER set as the data type.
45
Section 2-3
Instance Specifications
Item
Applicable areas
Allocated words
(default)
Contents
C (Counter Area) Counter Flag (1 bit) or counter PVs (16 bits)
C206 to C255 Counter Flag (1 bit) or counter PVs (16 bits)
W0.00
FB
ENO
1.0
address
3.0
Non Retain
Retain
Timers
Counters
W0
Size
512
Compile error
Note
Comments
The allocations in the function block instance area for variables are automatically reallocated when a variable is added or deleted. A single instance
requires addresses in sequence, however, so if addresses in sequence cannot be obtained, all variables will be allocated different addresses. As a result,
unused areas will be created. If this occurs, execute the optimization operation to effectively use the allocated areas and remove the unused areas.
A comment of up to 30,000 characters long can be entered.
Creating Multiple
Instances
Calling the Same Instance
A single instance can be called from multiple locations. In this case, the internal variables will be shared.
46
Section 2-3
Instance Specifications
Program 2 (manual operation)
Product B counter
Product A counter
CTD
CD
CTD
Q
CD
LD
LD
PV
D100
CV
PV
Product B counter
CV
D150
CTD
CD
LD
PV
CV
Program 1
Instance A
FB
D200
Instance A
I/O variables,
Internal
variables
FB definition
Body
Variable
definitions
Instance B
FB
Body
Instance B
I/O variables,
Internal
variables
Program 2
Instance A
Body
FB
2-3-2
Parameter Specifications
The data that can be set by the user in the input parameters and output
parameters is as follows:
Item
Input parameters
Applicable data
Values (See note 1.), addresses, and program symbols (global symbols and local symbols) (See note 2.)
Note The data that is passed to the input variable from the
parameter is the actual value of the size of the input
variable data. (An address itself will not be passed even
if an address is set in the parameter.)
Note Input parameters must be set. If even one input parameter has not been set, a fatal error will occur and the
input parameters will not be transferred to the actual
PLC.
Output parameters
Addresses, program symbols (global symbols, local symbols)
(See note 2.)
Input-output parame- Addresses, program symbols (global symbols, local symbols)
ters
Note
Input
variable
data type
BOOL
Contents
Bit data
(1) The following table shows the methods for inputting values in parameters.
Size
1 bit
Setting range
0 (FALSE), 1 (TRUE)
47
Section 2-3
Instance Specifications
Input
variable
data type
INT
DINT
LINT
Contents
Size
Integer
Double integer
Long (8-byte) integer
16 bits
32 bits
64 bits
16 bits
32 bits
64 bits
REAL
Unsigned integer
Unsigned double integer
Unsigned long (8-byte)
integer
Real number
LREAL
64 bits
WORD
16-bit data
16 bits
DWORD
32-bit data
32 bits
LWORD
64-bit data
64 bits
UINT
UDINT
ULINT
32 bits
Setting range
#0000000000000000 to
FFFFFFFFFFFFFFFF or &0 to
18,446,744,073,709,551,615
(2) The size of function block input variables and output variables must
match the size of program symbols (global and local), as shown in the following table.
Size
1 bit
16 bits
32 bits
64 bits
Note
48
The program symbol NUMBER can be set only in the input parameters. The value that is input must be within the size range for the
function block variable data type.
Section 2-3
Instance Specifications
2-3-3
Operating Specifications
Calling Instances
The user can call an instance from any location. The instance will be executed
when the input to EN is ON.
Instance
1.0
0.0
EN
D0
D10
A
In this case, the input to EN is bit 0.0 at the left of the diagram.
ENO
B
The system calls a function block when the input to the function blocks EN
input variable is ON. When the function block is called, the system generates
the instances variables and copies the algorithm registered in the function
block. The instance is then executed.
Pulse_2sON_1sOFF
P_On
CLOCK PULSE
EN
ENO
&20
tim_b
TIMX tim_a OFF_TIME
1. The FB is called.
ON_TIME
&10
Algorithm (Body)
1.0
tim_a
TIMX tim_b ON_TIME
OFF_TIME
ENO
Name
200-100ms_PULSE_tim_a
200-100ms_PULSE_tim_b
200-100ms_PULSE_ON_TIME
200-100ms_PULSE_OFF_TIME
Value
----&20
&10
Algorithm (Image)
Pulse_2sON_1sOFF tim_b
Pulse_2sON_1sOFF tim_a
Pulse_2sON_1sOFF OFF_TIME
Pulse_2sON_1sOFF tim_a
Pulse_2sON_1sOFF tim_b
Pulse_2sON_1sOFF ON_TIME
Pulse_2sON_1sOFF ENO
Parameters
Parameters
49
Section 2-3
Instance Specifications
Operation when the
Instance Is Not Executed
When the input to the function blocks EN input variable is OFF, the function
block is not called, so the internal variables of the instance do not change (values are retained). In the same way the output variables do not change when
EN is OFF (values are retained).
Program
FB definition
Body
P_Off
1.0
FB
EN
P_On
ENO
ENO
Internal
variable a
Execution results:
Output variable 1.0 is turned OFF, but
internal variable a retains its previous value.
Program
P_Off
P_On
1.0
Internal
variable a
!Caution An instance will not be executed while its EN input variable is OFF, so Differentiation and Timer instructions will not be initialized while EN is OFF. If Differentiation or Timer instructions are being used, use the Always ON Flag
(P_On) for the EN input condition and include the instructions input condition
within the function block definition.
Nesting
With CX-Programmer Ver. 6.0 and later versions, a function block can be
called from another function block, i.e., nesting is supported. Function blocks
can be nested up to 8 levels (including the function block called from the program).
The calling function block and called function block can be either ST language, ladder language, or either combination of the two.
FB0: Ladder diagram
Program
INSTANCE_FB0
INSTANCE_FB1
FB0
FB1
1st
INSTANCE_FB2
2nd
FB2
FB0 (ST)
Example:
FB8
7th
FB1 (ST)
;
INSTANCE_FB1 (A:=FB1__OUT1,B=:>FB1_IN1)
INSTANCE_FB8
8th
FB7 (ST)
Example:
Example:
INSTANCE_FB2 (...,..)
INSTANCE_FB8 (...,..)
FB8 (ST)
Example:
"INSTANCE_FB1," "INSTANCE_FB2," etc., are the FUNCTION BLOCK data type instance names.
Note: Any combination of ladder diagrams and structured text programming can be used between the called and the calling function block.
The function block nesting levels can also be displayed in a directory tree format with the FB Instance Viewer function.
The nested function blocks function block definitions are included in the function block library file (.cxf) containing the calling function blocks definitions.
50
Section 2-4
Programming Restrictions
2-4
2-4-1
Programming Restrictions
Ladder Programming Restrictions
There are some restrictions on instructions used in ladder programs.
Instructions Prohibited in
Function Block Definitions
AT Setting Restrictions
(Unsupported Data Areas)
Addresses in the following data areas cannot be used as parameters for input
variables, output variables, and input-output variables.
Index Registers (neither indirect nor direct addressing is supported) and
Data Registers
Indirect addressing of DM or EM Area addresses (Neither binary-mode
nor BCD-mode indirect addressing is supported.)
Interlock Restrictions
When a function block is called from an interlocked program section, the contents of the function block definition will not be executed. The interlocked function block will behave just like an interlocked subroutine.
P_Off
IL
FB_BODY
FB
ILC
Interlocked
Differentiation
Instructions in Function
Block Definitions
An instance will not be executed while its EN input variable is OFF, so the following precautions are essential when using a Differentiation Instruction in a
function block definition. (Differentiation Instructions include DIFU, DIFD, and
any instruction with an @ or % prefix.)
As long as the instances EN input variable is OFF, the execution condition
will retain its previous status (the last status when the EN input variable
was ON) and the Differentiation Instruction will not operate.
51
Section 2-4
Programming Restrictions
When the instances EN input variable goes ON, the present execution
condition status will not be compared to the last cycles status. The
present execution condition will be compared to the last condition when
the EN input variable was ON, so the Differentiation Instruction will not
operate properly. (If the EN input variable remains ON, the Differentiation
Instruction will operate properly when the next rising edge or falling edge
occurs.)
Example:
Body
0.0
FB1
EN
ENO
IN1
OUT1
LD EN
OR IN1
SET OUT1
If Differentiation Instructions are being used, always use the Always ON Flag
(P_On) for the EN input condition and include the instructions input condition
within the function block definition.
Body
P _On
FB1
0.00
EN
ENO
O UT1
LD a
OR I N1
SET OUT1
IN 1
The EN input condition is always ON, so
these Differentiation Instructions operate
normally.
Input a decimal numerical value after # when specifying the first operand
of the following instructions.
MILH(517), MILR(518), MILC(519), DIM(631), MSKS(690), MSKR(692),
CLI(691), FAL(006), FALS(007), TKON(820), TKOF(821)
Note
An instance will not be executed while its EN input variable is OFF, so the following precautions are essential when using a Timer Instruction in a function
block definition.
The Timer Instruction will not be initialized even though the instances EN
input variable goes OFF. Consequently, the timers Completion Flag will not be
turned OFF if the EN input variable goes OFF after the timer started operating.
52
Section 2-4
Programming Restrictions
Body
0.00
FB1
EN
ENO
LD EN
TI M t i m U P
UP
If Timer Instructions are being used, always use the Always ON Flag (P_On)
for the EN input condition and include the instructions input condition within
the function block definition.
Body
P _On
FB1
EN
0.00
ENO
LD a
TI M t i m U P
UP
2-4-2
ST Programming Restrictions
Restrictions when
Using ST Language in
Function Blocks
53
Section 2-4
Programming Restrictions
2-4-3
Programming Restrictions
Branches are not allowed on the left side of the instance. Branches are
allowed on the right side.
Incorrect
Correct
FB
FB
Instruction
Instruction
Incorrect
Correct
FB
FB
No Function Block
Connections
FB
A function blocks input cannot be connected to another function blocks output. In this case, a variable must be registered to transfer the execution status
from the first function blocks output to the second function blocks input.
0.0
0.0
FB1
FB1
EN
XOUT
FB2
XIN1
EN
XOUT
D3000
0.0
D100
XIN2
FB2
EN
D3000
Temporary variables
transfer the value from
FB1 to FB2.
XIN1
D100
XIN2
Downloading in Task
Units
Programming
Console Displays
Online Editing
Restrictions
The following online editing operations cannot be performed on the user program in the CPU Unit.
Changing or deleting function block definitions (variable table or algorithm)
Inserting instances or changing instance names
Note
54
Section 2-4
Programming Restrictions
Error-related
Restrictions
If a fatal error occurs in the CPU Unit while a function block definition is being
executed, ladder program execution will stop at the point where the error
occurred.
Program
FB definition
Instance name
0.0
D100
10.0
FB
EN
ENO
AAA
BBB
D200
Body
LD P_On
++ AAA
Fatal error occurs here.
MOV AAA BBB
In this case, the MOV AAA BBB instruction will not be executed and output
variable D200 will retain the same value that it had before the function block
was executed.
Prohibiting Access to
FB Instance Areas
To use a function block, the system requires memory areas to store the
instances internal variables, input variables, output variables, and input-output variables.
CJ2-series CPU Units
Function block instance Initial value of
area
start address
Non-retained
H512
Note
Retained
H1408
Timer
Counter
T3072
C3072
Initial value
Allowed data areas
of size
896
CIO, WR, HR, DM,
EM (See note.)
128
HR, DM, EM (See
note.)
1024
TIM
1024
CNT
EM bank 3
EM banks 6 to 9
EM banks 7 to E
EM banks 11 to 18
Initial value of
start address
H512
H1408
T3072
C3072
Initial value
of size
896
128
1,024
1,024
Default value
Start address End address
5000
5999
None
T206
T255
C206
C255
Applicable memory
areas
Size
1000
CIO, WR, DM
50
50
TIM
CNT
55
Section 2-5
Note
H1408
T3072
C3072
Initial value
Allowed data areas
of size
896
CIO, WR, HR, DM
(See note.)
128
HR, DM (See note.)
1024
TIM
1024
CNT
DM area of CP1L-L
Address
D0000 to D9999
D10000 to D31999
D32000 to D32767
CP1L-L
Provided
Not Provided
Provided
2-5
2-5-1
Use the following data types when handling single numbers in 1, 2, or 4-word
units.
INT and UINT
DINT and DINT
LINT and ULINT
Note
Use signed integers if the numbers being used will fit in the range.
Use the following data types when handling groups of data (non-numeric
data) in 1, 2, or 4-word units.
WORD
DWORD
LWORD
56
Section 2-5
2-5-2
To paste a function block into the program and then change the value (not the
address itself) to be passed to the function block for each instance, use an
input variable.
Program
Instance for function block definition A
The value itself is
passed
&3
Unit No.
&50
PARA
DATA_2
XFER
&10
DATA_1
DATA_2
The address can be specified, but the address itself is not passed.
Values are passed in a batch from the input parameters to the input variables before algorithm execution (not at the same time as the instruction
in the algorithm is executed). Therefore, to pass the value from a parameter to an input variable when the instruction in the function block algorithm
is executed, use an internal variable or external variable instead of an
input variable.
57
Section 2-5
To paste into the program and then pass values outside (the program) from
the function block for each instance, or monitor values, use output variables.
Program
Instance for function block definition A.
The actual value is
passed.
OK_Flag
W0.00
NG_ Flag
W0.01
D100
Input-Output Array
Variables to Pass Large
Amounts of Data
Input-output variables can be set as arrays (which is not possible for input
variables and output variables). If an input-output array variable is used, a
range of addresses of the specified size starting from the address set for the
input parameter can be used inside the FB. Input-output variables should thus
be used when its necessary to pass large quantities of data to a function
block.
Program Section
Instance of FB definition A
Specify an address for the input parameter;
the address will be passed to the FB.
D200
Data
Data
D200
D200
D201
D209
58
Data
WORD data
Array setting
10 elements
Section 2-5
Condition Flags (e.g., Always ON Flag, Equals Flag), Clock Pulses (e.g., 1.0
second clock pulse bit), pre-registered Auxiliary Area Bits (e.g., First Cycle
Flag), and global symbols used in the program are all external variables
defined by the system.
Internal Variables:
Internally Allocated
Variables and Variables
Requiring AT Settings
Variables that are not specified as Inputs, Outputs, In Out, or Externals are
Internals. Internal variables include variables with internally allocated
addresses and variables requiring addresses with AT settings (e.g., I/O allocation addresses, addresses specially allocated for Special I/O Units). Variables
requiring array settings include input-output variables and internal variables.
For details on conditions requiring AT settings or array settings, refer to 2-5-3
AT Settings for Internal Variables, and 2-5-4 Array Settings for Input-Output
Variables and Internal Variables.
2-5-3
The method for specifying Index Registers for Special I/O Unit allocation addresses requires AT settings to be specified for the first
address of the allocation area. (For details, refer to 2-5-5 Specifying
Addresses Allocated to Special I/O Units.)
When Auxiliary Area bits that are not pre-registered to external variables
are used, and these bits are registered to global symbols that are not
specified as external variables.
When setting the first destination word at the remote node for SEND(090)
and the first source word at the local node for RECV(098).
When the instruction operand specifies the first or last of multiple words,
and an array variable cannot be specified for the operand (e.g., the number of array elements cannot be specified).
2-5-4
Note
1,2,3...
59
Section 2-5
Note
2. Set the data in each of the array elements using the MOV instruction in the
function block definition.
3. Specify the first (or last) element of the array variable for the operand. This
enables specification of the first (or last) address in a range of words.
Examples are provided below.
Handling a Single String of Data in Multiple Words
In this example, an array contains the directory and filename (operand S2) for
an FREAD instruction.
Variable Table
Input-output variable or internal variable, data type = WORD, array setting
with 10 elements, variable names = filename[0] to filename[9]
Data Settings and Internal Function Block Processing
Input-output variables:
Set the input parameter to the address of the first word in the data (example: D100). The data (#5C31, #3233, #0000, etc.) is set in D100 to
D109 in advance from the main user program.
FREAD (omitted) (omitted) read_num[0] (omitted)
Internal variables:
Use ladder programming within the function block to set data into the
array.
MOV #5C31 file_name[0]
Set data in each array element.
MOV #3233 file_name[1]
MOV #0000 file_name[2])
Specify the first element
FREAD (omitted) (omitted) file_name[0] (omitted)
of the array in the instruction
operand.
Internal variables:
Use ladder programming within the function block to set data into the
array.
Ladder Programming
MOVL &100 read_num[0] (No._of_words)
MOVL &0 read_num[1] (1st_source_word)
60
Section 2-5
Internal variables:
FREAD (omitted) (omitted) (omitted) read_data[0]
Note
2-5-5
A two-element array can be used to store the result from a ladder programs
SIGNED BINARY DIVIDE (/) instruction. The result from the instruction is D
(quotient) and D+1 (remainder). This method can be used to obtain the remainder from a division operation in ladder programming.
When ST language is used, it isnt necessary to use an array to receive the
result of a division operation. Also, the remainder cant be calculated directly
in ST language. The remainder must be calculated as follows:
Remainder = Dividend (Divisor Quotient)
For details on using Index Registers in function blocks, refer to 2-5-6 Using
Index Registers.
Examples
Example 1: Specifying the CIO Area within a Function Block (Same for DM
Area)
Special I/O Units
Variables: Use the unit number as an input variable, and specifying the first
allocation address as an internal variable with the AT set to CIO 2000.
Programs: Use the following procedure.
1,2,3...
1. Multiply the unit number (input variable) by &10, and create the unit number offset (internal variable, DINT data type).
2. Use the MOVR(560) (MOVE TO REGISTER) instruction to store the real I/
O memory address for the first allocation address (internal variable, AT =
CIO 2000) in the Index Register (e.g., IR0).
3. Add the unit number offset to the real I/O memory address within the Index
Register (e.g., IR0).
Example 2: Specifying the Designated Bit in the CIO Area (e.g., CIO Word
n+a, Bit b)
Programs: Use either of the following methods.
61
Section 2-5
Word addresses: Specify the constant offset of the Index Register using
an indirect specification (e.g., +a,IR0).
Bit addresses: Specify an instruction that can specify a bit address within
a word (e.g., &b in second operand of SETB instruction when writing and
TST instruction when reading).
Example: Special I/O Units
Instance for function block definition A.
&3
Unit No.
1) Specify the first CIO Area word n (n = CIO 2000 + unit number 10)
Used constants:
Unit number (input variable, INT data type)
Offset (internal variable, DINT data type)
Relay (internal variable, WORD data type, 400 array elements, AT
setting = 2000)
&10
Unit No.
Offset
MOVR
Relay
IR0
+L
IR0
Offset
IR0
SETB
+1,IR0
&2
2-5-6
62
After storing the real I/O memory addresses in the Index Registers using the
MOVR(560) instruction, Index Registers can be indirectly specified using general instructions. This enables all I/O memory areas to be specified dynamically.
Section 2-5
MOVR(560)
IR@
Index Register
Example: Specifying +5,IR0 using
Specify address
constant offset specification, not
in IR0
variable name
Function block
Indirect +5 offset
specifiInstruction
cation
Specify ad+5,IR0
dress at +5
a
IR0
offset from
IR0.
Note
I/O memory
(1) When Index Registers IR0 to IR15 are used within function blocks, using
the same Index Register within other function blocks or in the program
outside of function blocks will create competition between the two instances and the program will not execute properly. Therefore, when using
Index Registers (IR0 to IR15), always save the value of the Index Register
at the point when the function block starts (or before the Index Register
is used), and when the function block is completed (or after the Index
Register has been used), incorporate processing in the program to return
the Index Register to the saved value.
Example: Starting function block (or before using Index Register):
1. Save the value of IR (e.g., A).
Value A
Value A
IR0
(2) Always set the value before using Index Registers. Operation will not be
stable if Index Registers are used without the values being set.
63
Application Examples
The following examples are for using Index Registers IR0 to IR15 within function blocks.
Example
Saving the Index Register Value before Using Index Register
Store IR0 temporarily in backup buffer
Section 2-5
Details
When Index Registers are used within this
function block, processing to save the Index
Register value is performed when the function starts (or before the Index Register is
used) to enable the value to be returned to
the original Index Register value after the
function block is completed (or after the
Index Register is used).
Example: Save the contents of Index Register IR0 by storing it in SaveIR[0] (internal
variable, data type DINT, 1 array element).
Example: The real I/O memory address for
the first word of CIO 1500 + unit number
25 allocated in the CPU Bus Unit allocation
area based on the CPU Bus Units unit
number (&0 to &15) passed from the function block is stored in IR0.
Procedure:
Assumes that unit numbers &0 to &15 have
already been input (from outside the function block) in UnitNo (input variables, INT
data type).
1. Multiple UnitNo by &25, and store in Offset (internal variable, DINT data type)
2. Store the real I/O memory address for
SCPU_Relay (internal variable, WORD
data type, (if required, specify the array as
400 elements (see note), AT setting =
1500)) in Index Register IR0.
Note Specifying an array for SCPU_relay,
such as SCPU_relay [2], for example,
enables the address CIO 1500 +
(UnitNo &25) + 2 to be specified.
This also applies in example 2 below.
3. Increment the real I/O memory address
in Index Register IR0 by the value for the
variable Offset (variable UnitNo &25).
64
Precautions for Instructions with Operands Specifying the First or Last of Multiple Words
Example
2) Specifying constant offset of Index Register (Specifying a bit between
CIO n+0 to n+24)
Section 2-6
Details
The real I/O memory address for CIO 1500
+ (UnitNo &25) is stored in Index Register
IR0 by the processing in step 1 above.
Therefore the word address is specified
using the constant offset from IR0.
For example, specifying +2,IR0 will specify
CIO 1500 + (UnitNo &25) + 2.
Note CIO 1500 + (UnitNo &25) + 2 can
also by specified by specifying
SCPU_relay [2] using the array setting with SCPU_relay.
Specify bit addresses using instructions that
can specify bit addresses within words
(e.g., second operand of TST(350/351)/
SETB(532) instructions).
Example: Variable NodeSelf_OK turns ON
when NetCheck_OK (internal variable,
BOOL data type) is ON and bit 15 of the
word at the +6 offset from IR0 (CIO 1500 +
UnitNo &25 +6) is ON.
2-6
1,2,3...
1. If a non-array variable is specified without AT setting and without a matching data size, the CX-Programmer will output an error when compiling.
2. The following precautions apply to when an array variable is specified.
65
Precautions for Instructions with Operands Specifying the First or Last of Multiple Words
Section 2-6
If the operand specifying the first address (or last address) of multiple words
uses a non-array variable data type with a size that does not match the data
size required by the instruction and an AT setting is also not used, the CX-Programmer will output a compile error.
Example: BLOCK TRANSFER(070) instruction: XFER W S D
(W: Number of words, S: First source word; D: First destination word)
When &10 is specified in W, variable a with data type WORD is specified in S,
and variable b with data type WORD is specified in D: XFER &10 a
b
The XFER(070) instruction will transfer the data in the 10 words beginning from
the automatically allocated address in variable a to the 10 words beginning
with the automatically allocated address in variable b. Therefore, the CX-Programmer will output a compile error.
Variable a (1 word)
Example: H7@@
10 words are
transferred regardless of the size of
variable a.
66
Variable b (1 word)
Section 2-6
Precautions for Instructions with Operands Specifying the First or Last of Multiple
Array Variables
D N
b[0]
S D
a[0]
b[0]
Even though the array variables a[0] and b[0] are both 10 words, the
XFER(070) instruction will execute transfer processing for the 20 words specified in W. As a result, the XFER(070) instruction will perform read/write processing for the I/O memory area following the number of array elements that
was allocated, as shown in the following diagram.
Therefore, if a[10 elements] is internally allocated words (e.g., H700 to H709),
and b[10 elements] is internally allocated words (e.g., H800 to H809),
XFER(070) will transfer data in words H700 to H719 to words H800 to H819.
In this operation, if another internally allocated variable (e.g., c), is allocated
words in H810 to H819, the words will be overwritten, causing unexpected
operation to occur. To transfer 20 words, make sure that the number of elements is specified as 20 elements for both array variable a and b.
67
Section 2-7
Example: H700
10 words
Array variable
a (10 words)
Example: H710
Example: H719
20 words
Array variable
a (10 words)
10 words
Example: H810
20 words will be
transferred regardless of the size of array variables a and b.
Example: H819
2-7
Instruction Support
Restrictions on Operands
Instructions that are not supported for use in function block definitions by the
CX-Programmer, CP-series CPU Units, and CS/CJ-series CPU Units with unit
version 3.0 are given as Not supported in function blocks in the Symbol column.
Operands that specify the first or last of multiple words, thereby requiring
AT setting or specification of array variables, are indicated as follows in
the AT setting or array required column.
Yes: An AT setting (or external specification) or array variable must be
specified for the operand to specify the first or last of multiple words.
The value within parentheses is the fixed size used by the instruction
for reading, writing, or other processing. This size indicates either the
data type size or the size required for the array variable specified in
word units. For array variables, this size must be the same as the number of elements. Otherwise, the CX-Programmer will output an error
when compiling.
68
Section 2-7
If not fixed is indicated in parentheses, the size used by the instruction for reading, writing, or other processing can be changed. Make
sure that the maximum size required for the number of array elements
is provided.
Even if the number of array elements in an operand with unfixed size
does not match the size specified in another operand, the CX-Programmer will not output an error when compiling. The instruction will
operate according to the size specified in the other operand, regardless of the number of array variable elements.
---: Operands that do not require an AT setting or specification of array variables.
Note
When specifying the first or last word of multiple words in an instruction operand, input parameters cannot be used to pass data
to or from variables. Either an AT setting must be used or one of the
following must be used: 1) An input-output variable set to an array
must be used and the address of the first word must be set for the
input parameter (CX-Programmer version 7.0 or higher) or 2) An
array variable with the required number of elements must be prepared, and after the array data is set in the function block definition,
the first or last element in the array variable must be specified for
the operand.
Any operands for which an AT setting must be specified for an I/O memory address on a remote node in the network are indicated as Specify
address at remote node with AT setting in the AT setting or array required
column.
The following table lists all of the instructions supported by the CS/CJ-series
CPU Units, CP-series CPU Units, NSJ-series NSJ Controllers, and FQM1
Flexible Motion Controllers (unit version 3.0 or later).
Some instructions are supported only by FQM1 Flexible Motion Controllers (unit version 3.0 or later). These are indicated by FQM1 only under
the mnemonic.
There are also instructions that are supported only by the CS/CJ-series
CPU Units, CP-series CPU Units, and NSJ-series NSJ Controllers, i.e.,
that cannot be used by the FQM1 Flexible Motion Controllers (unit version
3.0 or later). Refer to the FQM1 Instructions Reference Manual (Cat. No.
O013) to confirm the instructions that are supported.
For details, refer to the Programmable Controllers Instructions Reference
Manual (Cat. No. W474).
69
Section 2-8
2-8
2-8-1
Specifications
Item
CJ2H-CPU68
(-EIP)
CJ2H-CPU67
(-EIP)
Specification
CJ2H-CPU66
(-EIP)
CJ2H-CPU65
(-EIP)
CJ2H-CPU64
(-EIP)
I/O points
Program capacity
(steps)
Data memory
Extended Data
Memory
2,560
400K
250K
150K
100K
50K
32K words 25
banks
E0_00000 to
E18_32767
Force-set/ EM 11 to EM 18
reset
enabled
area
Function Maxi1,024
blocks
mum
number of
definitions
Maxi2,048
mum
number of
instances
3.5MB (See note.)
Source/ Symbol
Comtables/
comment
areas
ments/
program
indexes
Note
32K words 15
banks
E0_00000 to
EE_32767
EM 7 to EM E
32K words 10
banks
E0_00000 to
E9_32767
EM 6 to EM9
32K words 4
banks
E0_00000 to
E3_32767
EM3
32K words 4
banks
E0_00000 to
E3_32767
EM3
Specification
CS1HCS1HCS1HCS1HCS1HCS1GCPU67H CPU66H CPU65H CPU64H CPU63H CPU45H
5,120
250K
120K
60K
30K
20K
60K
32K words
32K
32K
words words
13 banks 7 banks
32K
words
3 banks
70
CS1GCPU44H
1,280
30K
CS1GCS1GCPU43H CPU42H
960
20K
10K
Section 2-8
Specification
1,024
1,024
1,024
1,024
128
1,024
1,024
128
128
2,048
2,048
2,048
2,048
256
2,048
2,048
256
256
2,048
2,048
1,280
1,280
1,280
1,280
704
704
704
1,664
1,664
1,024
512
512
1,024
512
512
512
128
128
64
64
64
64
64
64
64
128
128
64
64
64
64
64
64
64
128
128
128
64
64
128
64
64
64
CJ1HCPU67H/
CPU67HR
I/O points
Program capacity
(steps)
Data memory
Extended Data
Memory
2,560
250K
32K words
32K words
13
banks
E0_00000
to
EC_32767
Function Maxi1,024
blocks
mum
number of
definitions
Maxi2,048
mum
number of
instances
Total for
2,048
Comment
all files
Memory (Kbytes)
Unit (ver.
4.0 or
later)
CJ1HCPU66H/
CPU66HR
120K
CJ1HCPU65H/
CPU65HR
60K
Specification
CPU64H- CJ1GR
CPU45H
30K
1,280
60K
CJ1GCPU44H
CJ1GCPU43H
CJ1GCPU42H
30K
960
20K
10K
32K words 32K words 32K words 32K words 32K words 1 bank
7 banks 3 banks 1 bank 3 banks E0_00000 to E0_32767
E0_00000 E0_00000 E0_00000 E0_00000
to
to
to
to
E6_32767 E2_32767 E2_32767 E2_32767
1,024
1,024
1,024
1,024
1,024
128
128
2,048
2,048
2,048
2,048
2,048
256
256
2,048
1,280
1,280
1,280
1,280
1,280
704
71
Section 2-8
Function
block program
memory
(Kbytes)
Comment files
(Kbytes)
Program
index files
(Kbytes)
Variable
tables
(Kbytes)
Specification
1,664
1,664
1,024
512
1,024
512
512
512
128
128
64
64
64
64
64
64
128
128
64
64
64
64
64
64
128
128
128
64
128
64
64
64
Internal outputs
72
Specification
Units with internal I/O functions
Units without internal I/O functions
CJ1M-CPU23 CJ1M-CPU22 CJ1M-CPU21 CJ1M-CPU13 CJ1M-CPU12 CJ1M-CPU11
640
320
160
640
320
160
20K
10K
5K
20K
10K
5K
1 max.
1 max.
32K words
None
63 s (without
acceleration/
deceleration)
100 s (with
acceleration/
deceleration)
1
2
1,024
1
256
None
1,024
256
1,024
256
1,024
256
46 s (without acceleration/
deceleration)
70 s (with acceleration/deceleration)
---
10 points
-- 4 interrupt inputs (pulse catch)
2 high-speed counter inputs (50-kHz phase difference or 100-kHz single-phase)
--6 points
6 points
2 pulse outputs (100 kHz)
2 pulse outputs
2 PWM outputs
(100 kHz)
1 PWM output
Section 2-8
Specification
Units without internal I/O functions
128
256
704
256
64
64
64
X models
XA models
CP1H-X40DR-A
CP1H-XA40DR-A
CP1H-X40DT-D
CP1H-XA40DT-D
CP1H-X40DT1-D
CP1H-XA40DT1-D
320 points (40 built-in points + 40 points/Expansion
Rack x 7 Racks)
Y models
CP1H-Y20DT-D
20K
32K words
7 Units (CP-series Expansion Units and Expansion I/O Units)
128
256
256
64
64
64
73
Section 2-8
M models
CP1LCP1LCP1LM60D@-@
M40D@-@
M30D@-@
150 points
160 points
180 points
(30 built-in
(40 built-in
(60 built-in
points + 40 points + 40 points + 40
points/
points/
points/
Expansion
Expansion
Expansion
Rack x 3
Rack x 3
Rack x 3
Racks)
Racks)
Racks)
10K
32K words (D00000 to D32767)
L models
CP1LCP1LCP1LL20D@-@
L14D@-@
L10D@-@
10 points
54 points
60 points
(14 built-in
(20 built-in
points + 40 points + 40
points/
points/
Expansion
Expansion
Rack x 1
Rack x 1
Racks)
Rack)
5K
10K words (D00000 to D09999, and
D32000 to D32767)
1 Unit (CP-series ExpanNone
sion Unit or Expansion I/O
Unit)
128
256
256
64
64
64
NSJ5-TQ0@-G5D, NSJ5-SQ0@-G5D,
NSJ8-TV0@-G5D, NSJ10-TV0@-G5D,
NSJ12-TS0@-G5D,
1,280
60K
32K words
32K words 3 banks
E0_00000 to E2_32767
Maximum num- 1,024
ber of definitions
74
NSJ5-TQ0@-M3D, NSJ5-SQ0@-M3D,
NSJ8-TV0@-M3D
640
20K
None
128
256
256
64
64
64
128
64
Section 2-8
2-8-2
Coordinator Module
FQM1-CM002
344 points (24 built-in
points + 320 points on
Basic I/O Units)
10K
32K words
128
256
256
64
64
64
If this option is selected, all timers will operate the same regardless of timer
number, as shown in the following table.
Timer Operation for Timer Numbers T0000 to T4095
Refresh
When instruction is
executed
Description
The PV is refreshed each time the instruction is executed.
If the PV is 0, the Completion Flag is turned ON. If it is not 0,
the Completion Flag is turned OFF.
When execution of all All PV are refreshed once each cycle.
tasks is completed
Every 80 ms
If the cycle time exceeds 80 ms, all PV are refreshed once
every 80 ms.
If this option is not selected, the refreshing of timer instructions with timer
numbers T0000 to T2047 will be different from those with timer numbers
T2048 to T4095, as given below. This behavior is the same for CPU Units that
do not support function blocks. (Refer to the descriptions of individual instruction in the CS/CJ Series Instruction Reference for details.)
75
Section 2-9
Description
The PV is refreshed each time the instruction is executed.
If the PV is 0, the Completion Flag is turned ON. If it is not 0,
the Completion Flag is turned OFF.
When execution of all All PV are refreshed once each cycle.
tasks is completed
Every 80 ms
If the cycle time exceeds 80 ms, all PV are refreshed once
every 80 ms.
Description
The PV is refreshed each time the instruction is executed.
If the PV is 0, the Completion Flag is turned ON. If it is not 0,
the Completion Flag is turned OFF
When execution of all PV are not updated.
tasks is completed
Every 80 ms
PV are not updated even if the cycle time exceeds 80 ms.
Select the Apply the same spec as TO-2047 to T2048-4095 Option to ensure
consistent operation when using the timer numbers allocated by default to
function block variables (T3072 to T4095).
2-9
2-9-1
Note
The number of instruction steps in the function block definition (p) will not be
diminished in subsequence instances when the same function block definition
is copied to multiple locations (i.e., for multiple instances). Therefore, in the
above equation, the number of instances is not multiplied by the number of
instruction steps in the function block definition (p).
The following table applies only to CP-series CPU Units with unit version Ver.
1.0 or later and CS/CJ-series CPU Units with unit version Ver. 3.0 or later,
NSJ Controllers, and FQM1 Flexible Motion Controllers.
76
m
n
Section 2-9
Contents
Number of steps
Call part
--57 steps
I/O parameter
1-bit (BOOL) input vari6 steps
transfer part
able or output variable
The data type is
6 steps
1-word (INT, UINT, or
shown in parenthe- WORD) input variable or
ses.
output variable
2-word (DINT, UDINT,
6 steps
DWORD, or REAL) input
variable or output variable
4-word (LINT, ULINT,
12 steps
LWORD, or LREAL) input
variable or output variable
Input-output variables
18 steps
Number of instruc- The total number of instruction steps (same as standard
tion steps in func- user program) + 27 steps.
tion block definition
Example:
Input variables with a 1-word data type (INT): 5
Output variables with a 1-word data type (INT): 5
Function block definition section: 100 steps
Number of steps for 1 instance = 57 + (5 + 5) 6 steps + 100 steps + 27 steps
= 244 steps
When the program is written in ST language, the actual number of steps cannot be calculated. The number of instruction steps in each function block definition can be found in the function block definitions properties.
2-9-2
77
Section 2-9
8.8 s
Startup time
CJ1M-CPU@@
CP1H-X@@@-@
CP1H-XA@@@-@
CP1H-Y@@@-@
CP1L-M@@@-@
CP1L-L@@@-@
15.0 s
1.0 s
0.8 s
1.1 s
2.2 s
Example: CJ1H-CPU67H-R
Input variables with a 1-word data type (INT): 3
Output variables with a 1-word data type (INT): 2
Total instruction processing time in function block definition section: 10 s
Execution time for 1 instance = 3.3 s + (3 + 2) 0.19 s + 10 s = 14.25 s
Note
78
SECTION 3
Creating Function Blocks
This section describes the procedures for creating function blocks on the CX-Programmer.
3-1
3-2
Procedural Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
80
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
3-2-1
Creating a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
82
3-2-2
82
3-2-3
85
3-2-4
97
3-2-5
99
3-2-6
102
3-2-7
104
3-2-8
106
3-2-9
106
106
107
107
108
109
112
112
113
113
121
79
Section 3-1
Procedural Flow
3-1
Procedural Flow
The following procedures are used to create function blocks, save them in
files, transfer them to the CPU Unit, monitor them, and debug them.
1,2,3...
1,2,3...
1,2,3...
1,2,3...
1,2,3...
Refer to 3-2-4 Creating Instances from Function Block Definitions for details.
1,2,3...
Inserting Instances in the Ladder Section Window and then Inputting the
Instance Name
1. Place the cursor at the location at which to create an instance (i.e., a copy)
of the function block and press the F Key.
2. Input the name of the instance.
3. Select the function block definition to be copied.
1,2,3...
80
Section 3-1
Procedural Flow
3. Select the name of the instance that was registered from the pull-down
menu on the FB Instance Field.
Allocate External I/O to
the Function Block
1,2,3...
Refer to 3-2-5 Setting Function Block Parameters Using the Enter Key for
details.
1. Place the cursor at the position of the input variable or output variable and
press the P Key.
2. Input the source address for the input variable or the destination address
for the output variable.
81
Section 3-2
Procedures
3-2
3-2-1
Procedures
Creating a Project
1. Start the CX-Programmer and select New from the File Menu.
2. In the Change PLC Window, select a Device Type that supports function
blocks. These are listed in the following table.
Device
CJ2H
CS1G-H
CS1H-H
CJ1G-H
CJ1H-H
CJ1M
CP1H
CP1L
NSJ
FQM1-CM
FQM1-MMA
FQM1-MMP
CPU
CPU68/67/66/65/64/68-EIP/67-EIP/66-EIP/65-EIP/64-EIP
CPU42H/43H/44H/45H
CPU63H/64H/65H/66H/67H
CPU42H/43H/44H/45H
CPU65H/66H/67H/64H-R/65H-R/66H-R/67H-R
CPU11/12/13/21/22/23
CP1H-XA/X/Y
CP1L-M/L
G5D (Used for the NSJ5-TQ0@-G5D, NSJ5-SQ0@-G5D, NSJ8TV0@-G5D, NSJ10-TV0@-G5D, and NSJ12-TS0@-G5D)
M3D (Used for the NSJ5-TQ0@-M3D, NSJ5-SQ0@-M3D, and
NSJ8-TV0@-M3D)
FQM1-CM002
FQM1-MMA22
FQM1-MMP22
3. Press the Settings Button and select the CPU Type. For details on other
settings, refer to the CX-Programmer Operation Manual (W446).
3-2-2
1. When a project is created, a Function Blocks icon will appear in the project
workspace as shown below.
2. Function block definitions are created by inserting function block definitions after the Function Blocks icon.
Creating Function Block
Definitions
82
Function blocks can be defined by the user using either ladder programming
or structured text.
Section 3-2
Procedures
Note
To specify the default folder (file location) in the Function Block Library File Dialog Box, select Tools - Options, click the General
Tab and the select the default file in the OMRON FB library storage
location field.
3. Specify the folder in which the OMRON FB Library file is located, select the
library file, and click the Open Button. The library file will be inserted as a
function block definition after the
83
Section 3-2
Procedures
Function Block Definitions
Creating Function Block
Definitions
One of the following windows will be displayed when the newly created Function Block 1 icon is double-clicked (or if it is right-clicked and Open is selected
from the pop-up menu). A variable table for the variables used in the function
block is displayed on top and an input area for the ladder program or structured text is displayed on the bottom.
Ladder Program
Variable table
Ladder input area
Structured Text
Variable table
ST input area
84
Double-click the inserted function block library (or right-click and select Open
from the pop-up menu) to display the variable table that has finished being
created at the top right window, and the ladder program that has finished
being created in the bottom right window. Both windows are displayed in gray
and cannot be edited.
Section 3-2
Procedures
Variable table
Ladder program
Note
3-2-3
Function block definitions are not displayed in the default settings for OMRON
FB Library files (.cxf). To display definitions, select the Display the inside of
FB option in the function block properties. (Select the OMRON FB Library file
in the project workspace, right-click, select Properties, and select the Display the inside of FB option in the General Tab.)
The variables are divided by type into five sheets in the variable table: Internals, Inputs, Outputs, Input-Output, and Externals.
These sheets must be switched while registering or displaying the variables.
1,2,3...
1. Make the sheet for the type of variable to be registered active in the variable table. (See note.) Place the cursor in the sheet, right-click, and perform either of the following operations:
To add a variable to the last line, select Insert Variable from the popup menu.
To add the variable to the line above or below a line within the list, select Insert Variable - Above or Below from the pop-up menu.
Note
85
Section 3-2
Procedures
Input the name of the
function block variable
Note (a) For user-defined external variables, the global symbol table can
be browsed by registering the same variable name in the global
symbol table.
(b) External variables defined by the system are registered in the external variable table in advance.
2. For example, input aaa as the variable name and click the OK Button.
As shown below, a BOOL variable called aaa will be created on the Inputs
Sheet of the Variable Table.
Note
86
Section 3-2
Procedures
Creating the Algorithm
1,2,3...
2. Click the OK Button. A contact will be entered with the function block internal variable aaa as the operand (variable type: internal).
The rest of the ladder program is input in exactly the same way as for standard programs with CX-Programmer.
Note
Note
87
Section 3-2
Procedures
Note
(1) Tabs or spaces can be input to create indents. They will not affect the algorithm.
(2) The display size can be changed by holding down the Ctrl Key and turning the scrolling wheel on a wheel mouse.
(3) When an ST language program is input or pasted into the ST input area,
syntax keywords reserved words will be automatically displayed in blue,
comments in green, errors in red, and everything else in black.
(4) To change the font size or colors, select Options from the Tools Menu
and then click the ST Font Button on the Appearance Tab Page. The font
names, font size (default is 8 point) and color can be changed.
(5) For details on structured text specifications, refer to SECTION 5 Structured Text (ST) Language Specifications in Part 2: Structured Text (ST).
When using a ladder diagram, a dialog box will be displayed to register the
variable whenever a variable name that has not been registered is input. The
variable is registered at that time.
Use the following procedure.
1,2,3...
1. Press the C Key and input a variable name that has not been registered,
such as aaa, in the New Contact Dialog Box.
Note
2. Click the OK Button. The New Variable Dialog Box will be displayed. With
special instructions, a New Variable Dialog Box will be display for each operand in the instruction.
88
Section 3-2
Procedures
The properties for all input variables will initially be displayed as follows:
Usage: Internal
Data Type: BOOL for contacts and WORD for channel (word)
Initial Value: The default for the data type.
Retain: Not selected.
3. Make any required changes and click the OK Button.
4. As shown below, the variable that was registered will be displayed in the
variable table above the program.
5. If the type or properties of a variable that was input are not correct, doubleclick the variable in the variable table and make the required corrections.
Reference Information
AT Settings (Specified Address)
AT settings can be made in the variable properties to specify allocation
addresses for Basic I/O Units, Special I/O Units, or CPU Bus Units, or Auxiliary Area addresses not registered using the CX-Programmer. A variable
name is required to achieve this. Use the following procedure to specify an
address.
1,2,3...
1. After inputting the variable name in the New Variable Dialog Box, click the
Advanced Button. The Advanced Settings Dialog Box will be displayed.
2. Select AT (Specified Address) under AT Settings and input the desired address.
Select AT.
Input address.
The variable name is used to enter variables into the algorithm in the function block definition even when they have an address specified for the AT
settings (the same as for variables without a specified address).
For example, if a variable named Restart has an address of A50100 specified for the AT settings, Restart is specified for the instruction operand.
Array Settings
An array can be specified to use the same data properties for more than one
variable and manage the variables as a group.
Use the following procedure to set an array.
89
Section 3-2
Procedures
1,2,3...
1. After inputting the variable name in the New Variable Dialog Box, click the
Advanced Button. The Advanced Settings Dialog Box will be displayed.
2. Select Array Variable in the Array Settings and input the maximum number
of elements in the array.
When the name of an array variable is entered in the algorithm in the function block definition, square brackets surrounding the index will appear after the array name.
For example, if you create a variable named PV with a maximum of 3 elements, PV[0], PV[1], and PV[2] could be specified as instruction operands.
There are three ways to specify indices.
Directly with numbers, e.g., PV[1] in the above example (for ladder programming or ST language programming)
With a variable, e.g., PV[a] in the above example, where a is the
name of a variable with a data type of INT (for ladder programming or
ST language programming)
With an equation, e.g., PV[a+b] or PV[a+1} in the above example,
where a and b are the names of variables with a data type of INT
(for ST language programming only)
Using Structured Text
When using structured text, a dialog box will not be displayed to register the
variable whenever a variable name that has not been registered is input. Be
sure to always register variables used in standard text programming in the
variable table, either as you need them or after completing the program.
(Place the cursor in the tab page on which to register the variable, right-click,
and select Insert Variable from the pop-up menu.
Note
90
Addresses are not registered in the function block definition variable tables.
After pasting, the addresses will be displayed in the operand in red. Doubleclick on the instruction and input the variable name into the operand.
Index Registers (IR) and Data Registers (DR), however, do not require modification after pasting and function in the operand as is.
Section 3-2
Procedures
Source Instruction
Operand: Address and I/O
Comment
Note
The prefix AutoGen_ is not added to Index Registers (IR) and Global Data
Registers (DR), and they cannot be registered in the original global symbol
table.
Automatically generate symbol name Option Not Selected in Symbols
Tab under Options in Tools Menu
Addresses and I/O comments are not registered in the function block definition variable tables. Addresses are displayed in the operand in red. I/O comments will be lost. Double-click on the instruction and input the symbol name
into the operand.
Index Registers (IR) and Data Registers (DR), however, do not require modification after pasting and function in the operand as is.
Source Instruction
Operand: Symbol
CHANNEL
NUMBER
UINT BCD
UDINT BCD
ULINT BCD
Symbol data types CHANNEL, NUMBER, UINT BCD, UDINT BCD, or ULINT
BCD, however, cannot be copied from the symbol table (not the program) and
then pasted into the variable table in the function block definition.
91
Section 3-2
Procedures
Note
This function is designed to help you create function block definitions based
on existing ladder programming. It does not automatically generate finish definitions. After generating a function block definition with this function, always
check the warning messages in the FB Variable Allocation Dialog Box and
Output Window and check the program that was generated, and be sure to
make any required changes.
1,2,3...
1. Right-click one or more program circuits in the user program and select
Function Block (ladder) generation from the pop-up menu.
92
Section 3-2
Procedures
The addresses of the operands used in the instructions in the selected program circuits will be automatically allocated as listed below depending on
application conditions.
Application
Application inside selected program circuits
outside selected Not used
Used in
Used in
Used in input
program circuits
input
output
and output
section
section
sections
Not used
--Internal vari- Internal vari- Internal variable
(See note.)
able
able
Used
--Input variable Output variInput-output variable
able
Note
Note
Names will be automatically set for addresses without symbol names as follows: AutoGen_address. AT specifications will be automatically removed.
3. Change the allocations to internal, input, output, or input-output variables
as required. Right-click the variable and select the desired variable type
from the Change usage Menu.
If necessary, double-click any variable in the variable list and change the
name or comment. The array and AT settings can also be changed.
4. Click the OK Button. The following Function Block (Ladder) Generation Dialog Box will be displayed.
Input the FB definition name and comment, and then click the OK Button.
5. The function block definition will be generated based on the settings and
will appear under the function blocks in the Workspace.
Function Blocks
FunctionBlock1
6. The following dialog box will be displayed asking if you want to insert an
instance of the function block definition below the original program circuits.
93
Section 3-2
Procedures
7. Click the Yes Button to insert an instance and click the No Button to not
insert an instance.
8. The following New Function Block Invocation Dialog Box will appear if the
Yes Button was clicked.
Enter the function block instance name and click the OK Button. An instance of the function block definition will be inserted below the original
program circuits as shown below.
9. Enter the input conditions and parameters for the instance that was inserted.
Note
94
Section 3-2
Procedures
Program Circuits That
Must Be Altered before
Generating a Function
Block Definition
In the following case, the program circuits must be altered before a function
block definition can be automatically generated.
Addresses Used Both as Bits and Words
The bit and word addresses will be registered as different variables. The program can be altered in advance to avoid this.
Example: MOV(021) for W0 and SET for W0.02
95
Section 3-2
Procedures
As shown below, the variables must be changed to specify the first word in an
array and a specific word in the same array after the function block definition
has been generated.
Example: DT_WORD is set as a WORD array variable with 2 elements.
DT_WORD[0] is specified for MOVL(498) and DT_WORD[1] is specified for
MOV(021).
As shown below, the variables must be changed to specify the first word in an
array and a specific word in the same array after the function block definition
has been generated.
Example: DT_WORD is set as a WORD array variable with 10 elements.
DT_WORD[0] is specified for the first operand and DT_WORD[9] is specified
for the second operand of BSET(071).
96
Section 3-2
Procedures
Operands with Sizes Affected by Other Operands
Example: Five Transfer Words, D0 Specified for the First Source Word, and
D100 Specified for the First Destination Word for XFER(070)
As shown below, the variables must be changed to set the first elements in
two different arrays after the function block definition has been generated.
Example: DT_WORD1 and DT_WORD2 are set as WORD array variables
with 5 elements each. DT_WORD1[0] is specified for the first word for the first
operand and DT_WORD2[0] is specified for first word for the second operand
of XFER(070).
3-2-4
When using ST language, a function block can be called by selecting FUNCTION BLOCK as the variables data type, using the desired instance name, and entering a function block call statement.
97
Section 3-2
Procedures
Method 1: Using the F Key in the Ladder Section Window and Inputting
the Instance Name
1,2,3...
1. In the Ladder Section Window, place the cursor in the program where the
instance is to be inserted and press the F Key. (Alternately, select Function Block Invocation from the Insert Menu.) The New Function Block Invocation Dialog Box will be displayed.
When using ST language, a function block can be called by selecting
FUNCTION BLOCK as the variables data type, using the desired instance name, and entering the following function block call statement.
Specify arguments in parentheses after the instance name (to pass input
variable values from the calling function block to input variables in the
called function block) and also specify return values (to receive output variable values from the called function block to output variables in the calling
function block). The instance name can be set to any internal variable with
the FUNCTION BLOCK data type.
2. Input the instance name, select the function block from which to create an
instance, and click the OK Button.
Instance name
Function block definition
An instance called sample
is created from the function
block definition called
FunctionBlock1.
98
Section 3-2
Procedures
1,2,3...
1. For a ladder diagram, select a data type of Function block in the global
symbol table, input the instance name, and registered the instance.
For ST, select a data type of Function block, use the instance name, and
use a call statement for the function block as follows to call the function
block:
Input the instance name (any internal variable name with a function block
data type) followed by the arguments in parentheses (i.e., specify the input
variable values of the calling function block to pass to the input variables of
the called function block). Also include the return values (i.e., specify the
output variable values of the called function block to pass back to the output variables of the calling function block).
2. Press the F Key in the Ladder Section Window. The Function Block Invocation Dialog Box will be displayed.
3. Select the instance name that was previously registered from the pulldown
menu on the FB Instance Field. The instance will be created.
Restrictions
Observe the following restrictions when creating instances. Refer to 2-4 Programming Restrictions for details.
No more than one function block can be created in each program circuit.
The rung cannot be branched to the left of an instance.
Instances cannot be connected directly to the left bus bar, i.e., an EN
must always be inserted.
Note
3-2-5
If changes are made in the I/O variables in a variable table for a function block
definition, the bus bar to the left of all instances that have been created from
that function block definition will be displayed in red to indicate an error. When
this happens, select the function block, right-click, and select Update Invocation. The instance will be updated for any changes that have been made in
the function block definition and the red bus bar display indicating an error will
be cleared.
1. Inputs are located on the left of the instance and outputs on the right. Place
the cursor where the parameter is to be set and press the Enter Key. (Alternately, select Function Block Parameter from the Insert Menu.) The
New Parameter Dialog Box will be displayed as shown below.
99
Section 3-2
Procedures
Instance name
Function block definition
Press the P Key with the cursor on the left
of the instance. The New Parameter
Dialog Box will be displayed.
2. Set the source address from which to pass the address data to the input
variable. Also set the destination address to which the address data will be
passed from the output variable.
Note
Set the data in all the input parameters. If even a single input parameter
remains blank, the left bus bar for the instance will be displayed in red to indicate an error. If this happens, the program cannot be transferred to the CPU
Unit.
1 bit
16 bits
DINT
Double integer
32 bits
LINT
UINT
UDINT
Unsigned integer
Unsigned double
integer
Unsigned long (4word) integer
ULINT
100
Size
Input method
Setting range
16 bits
32 bits
P_Off, P_On
0 (FALSE), 1 (TRUE)
Positive value: & or + followed 32768 to +32767
by integer
2147483648 to +2147483647
Negative value: followed by
9223372036854775808 to
integer
+9223372036854775807
Positive value: & or + followed &0 to 65535
by integer
&0 to 4294967295
64 bits
&0 to 18446744073709551615
Section 3-2
Procedures
Input variable data
type
Content
Size
REAL
Real number
32 bits
LREAL
64 bits
WORD
16-bit data
16 bits
DWORD
32-bit data
32 bits
LWORD
64-bit data
64 bits
Note
Input method
Setting range
0, +2.22507385850720 10 308
to +1.79769313486232 10308
# followed by hexadecimal
number (4 digits max.)
& or + followed by decimal
number
# followed by hexadecimal
number (8 digits max.)
& or + followed by decimal
number
# followed by hexadecimal
number (16 digits max.)
& or + followed by decimal
number
#0000000000000000 to
FFFFFFFFFFFFFFFF or &0 to
18446744073709551615
If a non-boolean data type is used for the input variable and only a numerical
value (e.g., 20) is input, the value for the CIO Area address (e.g, CIO 0020)
will be passed, and not the numerical value. To set a numerical value, always
insert an &, #, + or prefix before inputting the numerical value.
Example Programs:
Instance for function block definition A
10
( INT )
DATA_1
&10
( INT )
DATA_1
If the data format for DATA_1 is INT, and the prefix &
is added so that "&10" is input, the numerical value
will be passed.
If the input variable data type is boolean and a numerical value only (e.g.,
0 or 1) is input in the parameter, the value for CIO 000000 (0.00) or
CIO 000001 (0.01) will be passed. Always input P_Off for 0 (OFF) and
P_On for 1 (ON).
101
Section 3-2
Procedures
3-2-6
1. Select the instance in the Ladder Section Window or in the global symbol
table, and then select Function Block/SFC Memory - Function
Block/SFC Memory Allocation from the PLC Menu.
The Function Block/SFC Memory Allocation Dialog shown below will appear.
2. Set the FB instance areas.
Non-retained area
Retained area
Timer area
Counter area
First
address
Last
address
Size
The non-retained and retained areas are set in words. The timer and
counter areas are set by time and counter numbers.
The default values are as follows:
CJ2-series CPU Units
FB Instance
Area
Note
Non Retain
Default value
Start address End address
H512
H1407
Applicable memory
areas
Size
896
Retain
Timers
H1408
T3072
H1535
T4095
128
1024
Counters
C3072
C4095
1024
CNT
EM bank 3
EM banks 6 to 9
EM banks 7 to E
EM banks 11 to 18
Note
102
Default value
Start address End address
H512 (See
H1407 (See
note 2.)
note 2.)
H1408 (See
note 2.)
T3072
C3072
H1535 (See
note 2.)
T4095
C4095
Applicable memory
areas
Size
896
128
HR, DM, EM
1024
1024
TIM
CNT
(1) Bit data can be accessed even if the DM or EM Area is specified for the
non-retained area or retained area.
Section 3-2
Procedures
(2) The Function Block Holding Area words are allocated in H512 to H1535.
These words cannot be specified in instruction operands in the user program. These words can also not be specified in the internal variables AT
settings.
(3) Words H512 to H1535 are contained in the Holding Area, but the addresses set as non-retained will be cleared when the power is turned
OFF and ON again or when operation is started.
(4) To prevent overlapping of instance area addresses and addresses used
in the program, set H512 to H1535 (Function Block Holding Area words)
for the non-retained area and retained area. If there are not sufficient
words, use words in areas not used by the user program. If another area
is set, the addresses may overlap with addresses that are used in the
user program.
If the addresses in the function block instance areas overlap with any of
the addresses used in the user program, an error will occur when compiling. This error will also occur when a program is downloaded, edited online, or checked by the user.
If addresses are duplicated and an error occurs, either change the function
block instance areas or the addresses used in the user program.
FQM1 Flexible Motion Controllers
FB Instance
Area
Non Retain
(See note.)
Retain
Timers
Counters
Note
Default value
Start address End address
5000
5999
Size
1000
CIO, WR, DM
None
T206
C206
50
50
TIM
CNT
T255
C255
Applicable memory
areas
Bit data can be accessed even if the DM Area is specified for the non-retained
area.
CP-series CPU Units
FB Instance
Area
Non Retain
Default value
Start address End address
H512
H1407
Size
896
Retain
Timers
Counters
H1408
T3072
C3072
128
1024
1024
H1535
T4095
C4095
Applicable memory
areas
CIO, WR, HR, DM (See
note.)
HR, DM (See note.)
TIM
CNT
103
Section 3-2
Procedures
Note
DM area of CP1L-L
Address
D0000 to D9999
D10000 to D31999
D32000 to D32767
3-2-7
CP1L-L
Provided
Not Provided
Provided
Right-click on the instance name and select Function Block Instance Address.
3. The FB Interface Memory Dialog Box will be displayed. Check the I/O
memory addresses internally allocated to variables here.
Example: Addresses used internally
for the input variables.
104
Section 3-2
Procedures
Method Used for Checking Addresses Internally Allocated to Variables
Program
Instance of function block definition A,
instance name: sample
a
b
c
Address/
Value
N/A [Auto]
Instance name
Inputs
Name Type
a
BOOL
Address
W400.00
Outputs
Name Type
b
BOOL
c
BOOL
Address
W401.00
W401.02
The following procedure can be used to check the number of addresses allocated to variables and the number still available for allocation in the function
block instance areas.
1. Select the instance in the Ladder Section Window, right-click, and select
Memory Allocation - Function Block/SFC Memory - Function
Block/SFC Memory Statistics from the PLC Menu.
2. The Function Block/SFC Memory Statistics Dialog Box will be displayed as
shown below. Check address usage here.
Optimizing Function
Memory
1,2,3...
105
Section 3-2
Procedures
2. Click the OK Button. Allocations to the function block instance areas will
be optimized.
3-2-8
3-2-9
106
Section 3-2
Procedures
FB Instance Viewer
The Used #, Free #, and Max # fields under Function Block refer to the
number of function block definitions.
107
Section 3-2
Procedures
1,2,3...
Select the function block definition, right-click, and select Compile from the
pop-up menu. (Alternately, press the Ctrl + F7 Keys.)
The function block will be compiled and the results of the program check will
be automatically displayed on the Compile Table Page of the Output Window.
1. Double-click the function block definition to be printed, and with the variable table and algorithm displayed, select Print from the File Menu. The
following Target Print Rung Dialog Box will be displayed.
2. Select the All Rung or Select Rung option. When the Select Rung option
is selected, specify the start rung and end rung numbers. When a page
number has been specified in the header and footer fields in File - Page
Setup, the first page number can be specified.
3. Select either of the following options for the function block printing range.
Symbol table and program (default)
Symbol table
Program
4. Click the OK Button, and display the Print Dialog Box. After setting the
printer, number of items to print and the paper setting, click the OK button.
108
Section 3-2
Procedures
5. The following variable table followed by the algorithm (e.g, ladder programming language) will be printed.
Note
For details on print settings, refer to the section on printing in the CX-Programmer Operation Manual (W446).
This password protection level restricts both writing (changing) and displaying
the contents of the function block definition.
To set read/write protection, select Prohibit writing and display as the Protection type in the function blocks properties. This level of protection prevents
unintended program changes/modifications and also protects against misappropriation of program materials.
Password Protection on
Writing Only
This password protection level restricts writing (changing) the contents of the
function block definition.
To set write protection, select Prohibit writing as the Protection type in the
function blocks properties. This level of protection prevents unintentional program changes/modifications.
Use the following procedure to set the password protection for an individual
function block definition.
1. In the project workspace, select the function block definition, right-click,
and select Properties from the pop-up menu. (Alternately, select Properties from the View Menu.)
109
Section 3-2
Procedures
2. The Function Block Properties Dialog Box will be displayed. Click the Protection Tab and click the Set Button.
3. The Function Block Protect Setting Dialog Box will be displayed. Select the
protection level in the Protection Type Field.
The following table shows the functions restricted in each protection level.
Function
Protect Type
Prohibit writing and
Prohibit writing
display
Prohibited
Allowed
Allowed
Prohibited
Allowed
4. Input the password in the Password Field of the Function Block Protect
Setting Dialog Box. Input the same password again in the confirmation
field to verify the password and click the Set Button.
The password can be up to 8 characters long and only alphanumeric characters can be used.
5. When a function block definition has been password protected, the function block definitions icon will change to indicate that it is protected. The
icon also indicates the protection level, as shown below.
: Prohibit writing and display (same for ladder and ST)
: Prohibit writing (ladder)
: Prohibit writing (ST)
Protecting Multiple
Function Block Definitions
Use the following procedure to set the password protection for two or more
function block definitions at the same time.
1,2,3...
110
Section 3-2
Procedures
2. The Function Block Protection Collective Setting Dialog Box will be displayed. Select the names of the function blocks that you want to protect,
select the Protection Type (protection level), input the password, and click
the Set Button.
Clearing Password
Protection on Multiple
Function Blocks
1,2,3...
Use the following procedure to clear the password protection on two or more
function block definitions at the same time.
1. Select Function Blocks in the project workspace, right-click, and select
Function Block Protection - Release from the pop-up menu.
111
Section 3-2
Procedures
2. The Function Block Protection Collective Release Dialog Box will be displayed. Select the names of the function blocks that you want to be unprotected, input the password, and click the Release Button.
3. If the password input matches the selected function blocks passwords, the
protection will be cleared for all of the function block definitions at once.
(1) Before saving to file, or reusing in another project, compile the function
block definition and perform a program check.
(2) When function blocks are being nested, the function block definition of the
called (nested) function blocks are included and saved in the function
block library file.
Use the following procedure to read a function block library file (*.cxf) into a
project.
1. Select the function block definition item under the PLC directory in the
Project Workspace, right-click, and select Insert Function Block - From
File from the pop-up menu (or select File - Function Block - Load Function Block from File).
2. The following dialog box will be displayed. Select a function block library
file (*.cxf) and click the Open Button.
112
Section 3-2
Procedures
Note
With the CX-Programmer Ver. 6.0 and later versions, it is possible to monitor
the status of bits and content of words in a ladder program within an instance
when monitoring the program. To monitor I/O bits and words (I/O Bit Monitor),
either double-click the instance or right-click the instance and select Monitor
FB Ladder Instance from the pop-up menu. At this point, it is possible to
monitor bits and words, change PVs, force-set/reset bits, and perform differentiation monitoring.
(1) It is not possible to perform online editing or change timer/counter SVs.
Also, although monitoring the status of bits and words is possible for input-output variables, changing PVs and force-setting/resetting bits is not
possible.
Double-click
113
Section 3-2
Procedures
(2) If an array variable is used in a function block and a symbol is used for the
array variables arguments, the present value cannot be monitored if that
array variable is used as the operand of an input condition or special instruction. In this case, the input condition or instruction will be displayed
in red.
Monitoring Variables of ST
Programs within
Instances
With the CX-Programmer Ver. 6.1 and later versions, it is possible to monitor
the ST programs within an instance when monitoring the program. To monitor
I/O bits and words (I/O Bit Monitor), either double-click the instance or rightclick the instance and select Monitor FB Instance from the pop-up menu.
To return to the original instance, right-click in the ST program monitor window
and select To Upper Layer from the pop-up menu.
Double-click
the instance.
The ST program and variable
monitoring areas are displayed.
Left side:
ST program monitor window
Right side:
ST variable monitor window
The ST program is displayed in the left side of the window (called the ST program monitor window).
114
Section 3-2
Procedures
The values of variables used in the ST program are displayed in the right side
of the window (called the ST variable monitor window).
At this point, it is possible to monitor variable values, change PVs, force-set or
force-reset bits, and copy/paste variables in the Watch Window. (These operations are described below.)
Monitoring Variables
Variable values are displayed in blue in the ST variable monitor window.
Changing PVs
To change a PV, select the desired variable in the ST variable monitor window
(displayed in reverse video when selected), right-click, and select Set - Value
from the pop-up menu.
Select the variable.
The Set New Value Dialog Box will be displayed. Input the new value in the
Value field.
Force-setting and Force-resetting Bits
To force-set, force-reset, or clear the forced status, select the desired variable
in the ST variable monitor window (displayed in reverse video when selected),
right-click, and select Force - On, Force - Off, Force - Cancel, or Force Cancel All Forces from the pop-up menu.
Copying and Pasting in the Watch Window
1,2,3...
1. To copy a variable to the Watch Window, select the desired variable in the
ST variable monitor window (displayed in reverse video when selected),
right-click, and select Copy from the pop-up menu.
2. Right-click in the Watch Window and select Paste from the pop-up menu.
115
Section 3-2
Procedures
Use the following procedure to check the program in the function block definition for an instance during monitoring.
1,2,3...
Right-click the instance and select To Lower Layer from the pop-up menu.
The function block definition will be displayed.
Monitoring Instance
Variables in the Watch
Window
1,2,3...
116
b.
c.
Section 3-2
Procedures
3. Select Usage - Data Type. The FB Instance setting can also be selected.
The default Usage is N: Internal and the other available selections are I:
Input, O: Output, and E: External.
The default Data Type is A: All. Special data types BOOL and INT can also
be selected.
4. Click the OK Button. The selected variable will be registered in the Watch
Window and the value will be displayed as shown below.
Select Register in Watch
Windows.
or
Copy the instance and
paste it in the Watch
Window.
or
Right-click an empty row in
the Watch Window and
select Register in Watch
Windows.
117
Section 3-2
Procedures
Monitoring Input Variables
and Output Variables in
Instances
The present values of input variables and output variables (parameters) are
displayed below the parameters.
Simulation of Ladder/ST
Programs in Instances
The CX-One Ver 1.1 (CX-Programmer Ver. 6.1) and later versions have a simulation function that can simulate the operation of a ladder program or ST program within a function block instance. Both step execution and break point
operation are supported.
To return to the original instance, right-click in the ST program monitor window
and select To Upper Layer from the pop-up menu.
1,2,3...
Note
Set the duration of the step execution for Continuous Step Run operation by
selecting the CX-Programmers Tools - Options command and setting the
Continuous Step Interval on the PLCs Tab Page.
Step In
Use the following procedure to begin step execution of a ladder/ST program
within an instance (called Step Run operation).
1,2,3...
118
Section 3-2
Procedures
Moves to here.
Stopped here.
With an ST program, an
arrow is displayed to the left Click the Step In Icon to
start Step In execution.
of the stopped position.
Note
Moves to here.
When the program is being executed at a point outside of the function block
instance, the processing is the same as normal Step Run operation.
Step Out
Use the following procedure to pause step execution of a ladder/ST program
within an instance (Step Run operation) and return to one level higher in the
program (the program or instance that was the source of the call).
1,2,3...
1. During Step Run operation, move the cursor to any stopping point in the
instance.
2. Click the Step Out Icon or select Tools - Simulation - Mode - Step Out.
119
Section 3-2
Procedures
Example:
Returning from an ST Program to the Calling Program or Instance
Moves to here.
Stopped here.
Note
The Step Out command can be executed only in a ladder/ST program within
an instance.
Color (default)
Pink
Regular color
Break point
Note
Blue
Program execution
Details
status
Simulator paused
Paused by Step Run
status
operation or the Pause
Button
Not executed due to Step is not being executed because of an
interlock or other
instruction such as IL,
function.
MILR/MILH, JMP0, or
FOR/BREAK.
Simulator instruction Paused (break status) by
break
a break point.
Note
120
When a break point is set for an instance, the break point is valid for that
instance only. (The break point is not valid for other instances created from
the same function block definition.)
Section 3-2
Procedures
With CS/CJ-series CPU Units with unit version 3.0, online editing
can be used to change peripheral aspects of function block instances.
Parameters passing data to/from instances can be changed, instructions not in instances can be changed, and instances can be
deleted.
Instances cannot be added, instance names cannot be changed,
and changes cannot be made to variable tables or algorithms in
function block definitions.
3. Enter the size of memory to reserve in each field in the Memory Size Edit
for FB Online Edit Dialog Box.
121
Section 3-2
Procedures
Editing and Transferring a Function Block Definition
1,2,3...
1. While online with the PLC, right-click a function block definition in the
Workspace (see note) and select FB online Edit - Begin from the pop-up
menu.
Note
Online editing can also be started from the Function Block Definition Window, the Instance Ladder/ST Monitor Window, or a function
block call instruction (from the normal ladder program or from a ladder program in a function block).
The following dialog box will be displayed before the FB Online Editor is
started.
At the same time, a list of instances that will be affected is displayed in the
Output Window.
Note
User Program
Affected
Programming
changed.
Affected
122
Section 3-2
Procedures
3. After editing the contents of the function block definition, select FB online
Edit - Send Changes. The following FB Online Edit - Transfer Dialog Box
will be displayed.
4. Select one of the following transfer modes and click the Yes Button.
Normal Mode
Quick Mode
Refer to Transfer Modes on page 124 and Selecting a Transfer Mode on
page 125 for details on the transfer modes.
123
Section 3-2
Procedures
The new function block definition will be transferred to the buffer memory
in the CPU Unit and the progress of the transfer will be displayed in a dialog
box.
(At this point, the CPU Unit will still be operating with the previous function
block definition.)
The following dialog box will appear when the transfer has been completed.
(At this point, the CPU Unit will still be operating with the previous function
block definition.)
5. Click the Yes Button. The user program in the CPU Unit will be updated
with the new function block definition from the buffer memory of the CPU
Unit. (If the No Button is click, the new function block definition in the buffer
memory will be discarded and the program will not be changed.)
In either case, the program will return to the status in which function block
definitions cannot be edited. To edit another function block definition, select FB online Edit - Begin and begin the online editing procedure from
the beginning.
Transfer Modes
Normal Mode
In Normal Mode, both the source code and object code are transferred to the
CPU Unit. Some time may be required for Normal Mode transfers because of
the quantity of data that must be sent. Other editing or transfer operations
cannot be performed until the transfer has been completed.
Note
Quick Mode
In Quick Mode, only the object code is transferred to the CPU Unit. The
source code is not transferred, making Quick Mode faster than Normal Mode.
After transferring the object code either 1) select Program - Transfer FB
Source to transfer the source code or 2) transfer the source code according
to instructions displayed in a dialog box when you go offline.
After transferring the object code, FB Source will be displayed in yellow at
the bottom of the window to indicate that the source code has not yet been
transferred. This message will disappear when the source code is transferred.
124
Section 3-2
Procedures
Selecting a Transfer Mode
Note
Normal Mode
5s
10 s
Quick Mode
1s
2s
a. The following dialog box will be displayed the next time the CX-Programmer is started.
b.
c.
Go online with the CPU Unit to which a transfer was made using Quick
Mode.
e. Click the Yes Button and then following the instructions provided in the
dialog boxes. The source code automatically backed up in the computer can be compared to the object code in the CPU Unit and if they
match, the source code can be transferred.
125
Section 3-2
Procedures
Note
The maximum extensions to the cycle time are given in the following table.
During online editing
During backup
12 ms max.
4% of cycle time
Note
126
Procedures
Section 3-2
Internal variables can be added, internal variable comments can be
changed, and internal variables can be deleted from the variable table in
the function block definition. To add an internal variable, however, memory
must be reserved in advance. Refer to Editing Reserved Memory to Add
an Internal Variable with Online Editing on page 121 for details.
The previous status flags for all differentiated instructions (DIFU(013), @
instructions, DIFD(014), and % instructions) will be initialized (i.e., turned
OFF) when online editing is finished.
After performing online editing, do not turn OFF the power supply to the
PLC until the CPU Unit has finished backing up data to the built-in flash
memory (i.e., until the BKUP indicator stops flashing). If the power supply
is turned OFF before the data is backed up, the data will not be backed up
and the program will return to the status it had before online editing was
performed.
127
Procedures
128
Section 3-2
Part 2:
Structured Text (ST)
SECTION 4
Introduction to Structured Text
This section introduces the structure text programming functionality of the CX-Programmer and explains the features that
are not contained in the non-structured text version of CX-Programmer.
4-1
4-2
ST Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
132
4-1-1
Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
132
CX-Programmer Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
133
4-2-1
133
4-2-2
Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
133
131
Section 4-1
ST Language
4-1
ST Language
This section explains the specifications and operating procedures for ST programs directly allocated to CX-Programmer tasks (ST tasks). Refer to the following sections for information on functions and operations specific to ST
programs used in other programs (function blocks or SFC).
ST programs used in function block instances:
Refer to Part 1: Function Blocks in this manual.
ST programs used in SFC:
Refer to the CX-Programmer Operation Manual: SFC (W469).
4-1-1
Overview
The ST (Structured Text) language is a high-level language code for industrial
controls (mainly PLCs) defined by the IEC 61131-3 standard. The standard
control statements, operators, and functions make the ST language ideal for
mathematical processing that is difficult to write in ladder programming. (The
ST language does not support all of the processing that can be written in ladder language.)
The ST language supported by CX-Programmer Ver. 7.2 or higher conforms
with the IEC 61131-3 standard, and these ST-language programs can be allocated to tasks.
The PLC must be a CS/CJ-series CPU Unit with unit version 4.0 or later, or a
CJ2-series CPU Unit.
The following list shows the features of the ST language.
Programs can be written like high-level languages such as C, and comments can be included to make the program easy to read.
ST Program
IF score > setover THEN
underNG := FALSE;
OK := FALSE;
overNG := TRUE;
(*If score>setover*)
(*Turn OFF underNG*)
(*Turn OFF OK*)
(*Turn ON overNG*)
ELSIF score < setunder THEN (*If score=<setover and score < setunder*)
overNG := FALSE;
(*Turn ON overNG*)
OK := FALSE;
(*Turn OFF OK*)
underNG := TRUE;
(*Turn ON underNG*)
ELSE
underNG := FALSE;
overNG := FALSE;
OK := TRUE;
(*If setover>score>setunder*)
(*Turn OFF underNG*)
(*Turn OFF overNG*)
(*Turn OFF OK*)
END_IF;
(*End of IF statement*)
ST programs can be uploaded and downloaded just like ordinary programs, but ST program tasks cannot be uploaded and downloaded in task
units.
Section 4-2
CX-Programmer Specifications
4-2
CX-Programmer Specifications
This section describes the operating environment for CX-Programmer ST programs (ST tasks). For details on the basic CX-Programmer operating environment, refer to the CX-Programmer Operation Manual (W446).
For details on the CX-Programmer operating environment used with other
programs (function block or SFC), refer to Part 1: Function Blocks in this
manual, or the CX-Programmer Operation Manual: SFC (W469).
4-2-1
4-2-2
CS1H-CPU67H/66H/65H/64H/63H
CJ1G-CPU45H/44H/43H/42H
CJ1H-CPU67H/66H/65H/67H-R/66H-R/65H-R/64H-R
CJ1M-CPU23/22/21/13/12/11
Specifications
Item
Specification
Program languages that can SFC, ladder, or ST (These programs can be combined
be allocated to tasks
freely.)
ST program units
Task units
Up to 288 tasks (32 cyclic tasks, and 256 extra cyclic
tasks)
Tasks to which ST programs Cyclic tasks and extra cyclic tasks
can be allocated
Online editing
ST chart editing
Array variables
133
CX-Programmer Specifications
134
Section 4-2
SECTION 5
Structured Text (ST) Language Specifications
This section provides specifications for reference when using structured text programming, as well as programming
examples and restrictions.
5-1
5-2
5-3
5-4
5-5
5-6
5-7
136
5-1-1
136
137
5-2-1
137
5-2-2
137
Inputting ST Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
138
5-3-1
Syntax Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
138
5-3-2
140
ST Language Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
141
5-4-1
Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
141
5-4-2
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
142
5-4-3
Inputting Constants. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
142
5-4-4
Operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
142
5-4-5
Standard Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
143
5-4-6
146
Statement Descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
148
5-5-1
Assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
148
5-5-2
Control Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
148
166
5-6-1
166
Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
167
5-7-1
Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
167
5-7-2
167
135
Section 5-1
5-1
5-1-1
ST Language
Configuration
ST Language Configuration
An ST language program is composed from statements. There are two kinds
of statements: assignment and control.
Assignment statement: This statement uses an equation to store a calculation result in a variable.
Control statement: Includes statements such as selection statements and
iteration statements.
For details on each kind of statement, refer to 5-4 ST Language Configuration.
Statement Contents
Statements are composed of the following elements.
Variables (Refer to 5-4-2 Variables.)
Constants (Refer to 5-4-3 Inputting Constants.)
Operators (Refer to 5-4-4 Operators.)
Functions (Refer to 5-4-5 Standard Functions and 5-4-6 OMRON Expansion Functions.)
Example of a Control Statement
Statement (e.g., CASE):
Configured using variables,
Variable Constant
equations, etc.
CASE COLOR OF
1: NofRed := NofRed + 1;
2: NofBlue := NofBlue+1;
END IF;
Statement (e.g., IF):
Configured using variables,
equations, etc.
Note
136
Comment:
A comment can be attached to a statement.
Configured using (* before the
comment and *) after the comment.
Section 5-2
5-2
5-2-1
Data type
BOOL
INT
DINT
LINT
UINT
UINT BCD
UDINT
UDINT BCD
Content
Size
Range of values
Bit data
Integer
Double integer
Long (8-byte) integer
Unsigned integer
Unsigned BCD integer
Unsigned double integer
Unsigned double BCD
integer
1
16
32
64
16
--32
---
0 (FALSE), 1 (TRUE)
32,768 to +32,767
2,147,483,648 to +2,147,483,647
9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
&0 to 65,535
(See note 1.)
&0 to 4,294,967,295
(See note 1.)
64
&0 to 18,446,744,073,709,551,615
---
REAL
32
LREAL
64
WORD
DWORD
LWORD
16-bit data
32-bit data
64-bit data
16
32
64
STRING
FUNCTION
BLOCK
CHANNEL
NUMBER
Text string
Function block instance
Variable
---
Word
Constant or number
-----
ULINT
ULINT BCD
Note
(1) In ST programs, these data types are recognized as the following data
types.
UNIT BCD is recognized as WORD.
UDINT BCD is recognized as DWORD.
ULINT BCD is recognized as LWORD.
CHANNEL is recognized as WORD.
(2) This data type cannot be used in an ST program. A program error will occur if this data type is specified.
5-2-2
137
Section 5-3
Inputting ST Programs
5-3
5-3-1
Inputting ST Programs
Syntax Rules
Statement Delimiters
Comments
Example
(*comment*)
Note
Spaces, Carriage Returns,
Tabs
Special characters:
If a space, carriage return, or tab is used between any of the above tokens,
the parts of the token on either side will be treated as separate tokens.
Therefore, make sure that spaces, carriage returns, or tabs are not used
within a single token.
138
Section 5-3
Inputting ST Programs
Operator Priority
31 32
33 34
35 36
00 00
Description
Indicates the text string A (ASCII 41).
Indicates a text string containing a single space (ASCII 20).
Indicates an empty text string.
Two hexadecimal digits following a dollar sign ($) are interpreted as hexadecimal values.
Notation
$02
$03
Description
The hexadecimal number 02 (start code)
The hexadecimal number 03 (end code)
139
Section 5-3
Inputting ST Programs
Description
The dollar sign (ASCII 24)
A single quotation mark (ASCII 27)
Line feed (ASCII 0A)
Carriage return + line feed (ASCII 0D 0A)
New page (ASCII 0C)
Carriage return (ASCII 0D)
Tab (ASCII 09)
$$
$
$L or $l
$N or $n
$P or $p
$R or $r
$T or $t
When a text string is being stored from the ladder program in an ST function blocks STRING variable, append a NULL character (#00) to the end
of the text string.
Example: Passing string data to the function block STRING variable StrX:
Ladder program that stores "123456" in STRING variable StrX:
MOV #3132 D100
MOV #3334 D101
MOV #3536 D102
MOV #0000 D103
STRING data is stored to the function block by the ladder program above.
D100
5-3-2
(STRING)
StrX
(STRING)
StrX
D100
Changing Fonts
140
To change font sizes or display colors, select Tools - Options, click the
Appearance Tab, and then click the ST Font Button. The font name, font size
(default is 8 point), and color can be changed.
Section 5-4
ST Language Configuration
5-4
5-4-1
ST Language Configuration
Statements
Statement
End of statement
Comment
Assignment
Assignment statement
Control
IF, THEN, ELSIF, ELSE,
statements END_IF
Function
Ends the statement
All text between (* and *) is treated as
a comment.
Substitutes the results of the expression, variable, or value on the right for
the variable on the left.
Evaluates an expression when the
condition for it is true.
Example
;
(*comment*)
A:=B;
IF (condition_1) THEN
(expression 1);
ELSIF (condition_2) THEN
(expression 2);
ELSE
(expression 3);
END_IF;
CASE (variable) OF
1: (expression 1);
2: (expression 2);
3: (expression 3);
ELSE
(expression 4);
END_CASE;
FOR (identifier) := (initial_value) TO
(final_value) BY (increment) DO
(expression);
END_FOR;
WHILE (condition) DO
(expression);
END_WHILE;
REPEAT
(expression);
UNTIL (condition)
END_REPEAT;
EXIT;
RETURN;
REPEAT, UNTIL,
END_REPEAT
EXIT
RETURN
141
Section 5-4
ST Language Configuration
5-4-2
Variables
For details on variable specifications and setting methods, refer to the CXProgrammer Operation Manual (W469).
5-4-3
Inputting Constants
Numerical values can be expressed in decimal, hexadecimal, octal, or binary,
as shown in the following examples.
Notation
Method
Example
(for the decimal value 12)
Decimal:
12
Note
5-4-4
Octal:
8#14
Binary:
2#1100
Text string:
Operators
Operation
Symbol
Parentheses and
brackets
Function evaluation
(expression),
array[index]
identifier
Exponential
Complement
Multiplication
Division
Addition
Subtraction
Comparisons
**
NOT
*
/
+
Equality
Non-equality
<>
Boolean AND
Boolean AND
Boolean exclusive
OR
Boolean OR
&
AND
XOR
OR
Note
142
Priority
1: Lowest
11: Highest
1
2
3
4
5
5
6
6
7
8
8
9
9
10
11
Section 5-4
ST Language Configuration
type variables A=3 and B= 2, if the operation (A/B)*2 is performed, the result
of A/B is 1 (1.5 with the value below the decimal discarded), so (A/B)*2 = 2.
5-4-5
Standard Functions
Function type
Numerical Functions
Arithmetic Functions
Data Type Conversion Functions
Number-String Conversion Functions
Syntax
Absolute values, trigonometric functions, etc.
Exponential (EXPT)
Source_data_type_TO_New_data_type (Variable_name)
Source_data_type_TO_STRING (Variable_name)
STRING_TO_New_data_type (Variable_name)
Numerical Functions
Function
ABS (argument)
SQRT (argument)
REAL, LREAL
Return value
data type
INT, DINT, LINT,
UINT, UDINT,
ULINT, REAL,
LREAL
REAL, LREAL
LN (argument)
REAL, LREAL
REAL, LREAL
LOG (argument)
REAL, LREAL
REAL, LREAL
EXP (argument)
REAL, LREAL
REAL, LREAL
SIN (argument)
REAL, LREAL
REAL, LREAL
COS (argument)
REAL, LREAL
REAL, LREAL
TAN (argument)
REAL, LREAL
REAL, LREAL
ASIN (argument)
REAL, LREAL
REAL, LREAL
ACOS (argument)
REAL, LREAL
REAL, LREAL
ATAN (argument)
REAL, LREAL
REAL, LREAL
Description
Absolute value [argument]
Example
a: = ABS (b)
(*absolute value of variable
b stored in variable a*)
Square root:
argument
a: = SQRT (b)
(*square root of variable b
stored in variable a*)
Natural logarithm: LOGe a: = LN (b)
argument
(*natural logarithm of variable b stored in variable a*)
a: = LOG (b)
Common logarithm:
LOG10 argument
(*common logarithm of variable b stored in variable a*)
ara: = EXP (b)
Natural exponential: e
gument
(*natural exponential of variable b stored in variable a*)
Sine: SIN argument
a: = SIN (b)
(*sine of variable b stored in
variable a*)
Cosine: COS argument
a: = COS (b)
(*cosine of variable b stored
in variable a*)
Tangent: TAN argument a: = TAN (b)
(*tangent of variable b stored
in variable a*)
1 argument a: = ASIN (b)
Arc sine: SIN
(*arc sine of variable b
stored in variable a*)
a:
= ACOS (b)
143
Section 5-4
ST Language Configuration
Function
EXPT (base, exponent)
REAL,
LREAL
Exponent INT,
DINT,
LINT,
UINT,
UDINT,
ULINT
Note
Return value
data type
REAL, LREAL
Description
Example
The data type returned for numerical functions is the same as that used in the
argument. Therefore, variables substituted for function return values must be
the same data type as the argument.
The following functions can be used with CS/CJ-series CPU Units with unit
version 4.0 or later, or CJ2-series CPU Units.
LEN(String)
String
STRING
LEFT(<Source_string>,
<Number_of_characters>)
Source_
string
STRING
Description
Return
value
data type
INT
Detects the length
of a text string.
STRING
Number_of_ INT,
characters
UINT
Example
a: = LEN (b)
(*number of characters in string
b stored in variable a*)
Extracts characa: = LEFT (b,c)
ters from a text
(*number of characters specified
string starting from by variable c extracted from the
the left.
left of text string b and stored in
variable a*)
Extracts characa: = RIGHT (b,c)
ters from a text
(*number of characters specified
string starting from by variable c extracted from the
the right.
eight of text string b and stored
in variable a*)
a: = MID (b,c,d)
Extracts characters from a text
(*number of characters specified
string.
by variable c extracted from text
string b starting at position specified by variable d and stored in
variable a*)
RIGHT(<Source_string>,
<Number_of_characters>)
Source_
STRING
string
Number_of_ INT,
characters
UINT
STRING
MID(<Source_string>,
<Number_of_characters>,
<Position>)
Source_
string
Number_of_
characters
Position
STRING
STRING
CONCAT(<Source_string_1>,<S
ource_string_2>,...) *Up to
32 source strings.*
INSERT(<Source_string>,
<Insert_string>,<Position>)
Source_
string
INT,
UINT
INT,
UINT
STRING
STRING
Concatenates text
strings.
a: = CONCAT (b,c...)
(*text strings b, c... are joined
and stored in variable a*)
STRING
STRING
a: = INSERT (b,c,d)
(*text string c inserted into text
string b at position specified by
variable d and resulting string
stored in variable a*)
STRING
DELETE(<Source_string>,
<Number_of_characters>,
<Position>)
144
Source_
string
Insert_
string
Position
STRING
INT,
UINT
STRING
Source_
string
Number_of_ INT,
characters
UINT
Position
INT,
UINT
Section 5-4
ST Language Configuration
Function
REPLACE(<Source_string
>,<Replace_string>,
<Number_of_characters>,
<Position>)
FIND(<Source_string>,
<Find_string>)
Source_
string
Replace_
string
Number_of_
characters
Position
Source_
string
Find_string
STRING
Return
value
data type
Description
STRING
INT
Finds characters
a: = FIND (b,c)
within a text string. (*first occurrence of text string c
found in text string b and position stored in variable a; 0 stored
if text string c is not found.*)
STRING
INT,
UINT
INT,
UINT
STRING
Example
STRING
The following data type conversion functions can be used in structured text.
Syntax
Source_data_type_TO_New_data_type (Variable_name)
Example: REAL_TO_INT (C)
In this example, the data type for variable C will be changed from REAL to
INT.
The combinations of data types that can be converted are given in the following table.
(YES = Conversion possible, No = Conversion not possible)
FROM
TO
BOOL
INT
DINT
LINT
UINT
UDINT
ULINT
WORD
DWORD LWORD
REAL
LREAL
BCD_
WORD
BCD_
DWORD
No
BOOL
No
No
No
No
No
No
No
No
No
No
No
No
No
INT
No
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
DINT
No
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
LINT
No
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
No
No
UINT
No
YES
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
UDINT
No
YES
YES
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
ULINT
No
YES
YES
YES
YES
YES
No
YES
YES
YES
YES
YES
No
No
WORD
No
YES
YES
YES
YES
YES
YES
No
YES
YES
No
No
No
No
DWORD
No
YES
YES
YES
YES
YES
YES
YES
No
YES
No
No
No
No
LWORD
No
YES
YES
YES
YES
YES
YES
YES
YES
No
No
No
No
No
REAL
No
YES
YES
YES
YES
YES
YES
No
No
No
No
YES
No
No
LREAL
No
YES
YES
YES
YES
YES
YES
No
No
No
YES
No
No
No
WORD_
BCD
No
YES
YES
No
YES
YES
No
No
No
No
No
No
No
No
DWORD_ No
BCD
YES
YES
No
YES
YES
No
No
No
No
No
No
No
No
Number-String
Conversion Functions
Syntax
Source_data_type_TO_STRING (Variable_name)
Example: INT_TO_STRING (C)
In this example, the integer variable C will be changed to a STRING variable.
STRING_TO_New_data_type (Variable_name)
Example: STRING_TO_INT (C)
145
Section 5-4
ST Language Configuration
The combinations of data types that can be converted are given in the following table.
(YES = Conversion possible, No = Conversion not possible)
FROM
TO
BOOL
INT
DINT
LINT
UINT
UDINT
ULINT
WORD
DWORD
LWORD
No
No
REAL
No
No
No
No
No
No
No
INT
No
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
DINT
No
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
LINT
No
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
No
UINT
No
YES
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
UDINT
No
YES
YES
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
ULINT
No
YES
YES
YES
YES
YES
No
YES
YES
YES
YES
YES
No
WORD
No
YES
YES
YES
YES
YES
YES
No
YES
YES
No
No
YES
DWORD
No
YES
YES
YES
YES
YES
YES
YES
No
YES
No
No
YES
LWORD
No
YES
YES
YES
YES
YES
YES
YES
YES
No
No
No
No
REAL
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
No
No
No
LREAL
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
No
No
No
STRING
No
YES
YES
No
YES
YES
No
YES
YES
No
No
No
No
No
Function type
Memory Card Functions
Communications Functions
Angle Conversion Functions
Memory Card
Functions
Function
WRITE_TEXT(<Write_string>,
<Directory_name_and_file_
name>,<Delimiter>,<Parameter>)
Communications
Functions
Function
Description
Functions that write data to Memory Cards
Functions that send and received text strings
Functions that convert between degrees and radians.
The following functions can be used with CS/CJ-series CPU Units with unit
version 4.0 or later, or CJ2-series CPU Units.
Argument data type
Write_string
Directory_
name_and_
file_name
Delimiter
Parameter
Return
Description
value
data type
--Writes a text
string to a
Memory
Card.
STRING
STRING
STRING
INT,
UINT,
WORD
Example
WRITE_TEXT(a,b,c,d)
(*text string a is written to a file
with the file name and directory
specified by variable b; if variable
d is 0, the text string is added to
the file along with delimiter specified by variable c; if variable d is 1,
a new file is created*)
The following functions can be used with CS/CJ-series CPU Units with unit
version 4.0 or later, or CJ2-series CPU Units.
Argument data type
TXD_CPU(<Send_string>) Send_string
STRING
TXD_SCB(<Send_string>, Send_string
<Serial_port>)
Serial_port
STRING
INT,
UINT,
WORD
146
No
STRING
No
5-4-6
No
LREAL
BOOL
Return
Description
value
data type
--Sends a text string to
the RS-232C port on
the CPU Unit.
---
Example
TXD_CPU(a)
(*text string a is sent from
the RS-232C port on the
CPU Unit*)
TXD_SCB(a,b)
(*text string a is sent from
the serial port specified by
variable b on the Serial
Communications Board*)
Section 5-4
ST Language Configuration
Function
TXD_SCU(<Send_string>, Send_string
<SCU_unit_number>,
SCU_unit_
<Serial_port>,<Internal_
number
logic_port>)
RXD_CPU(<Storage_
location>,<Number_of_
characters>)
STRING
INT,
UINT,
WORD
Serial_port
INT,
UINT,
WORD
Internal_logic INT,
_port
UINT,
WORD
Storage_
STRING
location
Number_of_
characters
Storage_
RXD_SCB(<Storage_
location
location>,<Number_of_
characters>,<Serial_port>) Number_of_
characters
Serial_port
RXD_SCU(<Storage_
location>,<Number_of_
characters>,<SCU_unit_
number>,<Serial_port>,
<Internal_logic_port>)
Angle Conversion
Instructions
Storage_
location
Number_of_
characters
Return
value
data type
---
---
---
---
INT,
UINT,
WORD
STRING
---
INT,
UINT,
WORD
INT,
UINT,
WORD
STRING
---
INT,
UINT,
WORD
SCU_unit_
INT,
number
UINT,
WORD
Serial_port
INT,
UINT,
WORD
Internal_logic INT,
_port
UINT,
WORD
Description
RXD_SCU(a,b,c,d,e)
(*number of characters
specified by variable b are
received from the serial port
specified by variable d on
the Serial Communications
Unit specified by variable c
using the internal logic port
specified by variable e and
stored in variable a*. The
variable e indicates the
internal logic port number.)
The following functions can be used with CS/CJ-series CPU Units with unit
version 4.0 or later, or CJ2-series CPU Units.
Function
Argument
Return value
Description
data type
data type
DEG_TO_RAD(argument) REAL, LREAL REAL, LREAL Converts an angle from
degrees to radians.
RAD_TO_DEG (argument)
Example
Example
a:=DEG_TO_RAD(b)
(*an angle in degrees in variable
b is converted to radians and
stored in variable a*)
a:=RAD_TO_DEG(b)
(*an angle in radians in variable
b is converted to degrees and
stored in variable a*)
147
Section 5-5
Statement Descriptions
5-5
5-5-1
Statement Descriptions
Assignment
Summary
The left side of the statement (variable) is substituted with the right side of the
statement (equation, variable, or constant).
Reserved Words
:=
Combination of colon (:) and equals sign (=).
Statement Syntax
Variable: = Equation, variable, or constant;
Usage
Use assignment statements for inputting values in variables. This is a basic
statement for use before or within control statements. This statement can be
used for setting initial values, storing calculation results, and incrementing or
decrementing variables.
Description
Substitutes (stores) an equation, variable, or constant for the variable.
Examples
Example 1: Substitute variable A with the result of the equation X+1.
A:=X+1;
Example 2: Substitute variable A with the value of variable B.
A:=B;
Example 3: Substitute variable A with the constant 10.
A:=10;
Precautions
The data type of the equation, variable, or constant to be assigned must be
the same as the data type of the variable to be substituted. Otherwise, a syntax error will occur.
5-5-2
Control Statements
IF Statement (Single
Condition)
Summary
This statement is used to execute an expression when a specified condition is
met. If the condition is not met, a different expression is executed.
Reserved Words
IF, THEN, (ELSE), END_IF
Note
148
Section 5-5
Statement Descriptions
Process Flow Diagram
Condition
False
True
Expression 1
Expression 2
Usage
Use the IF statement to perform a different operation depending on whether a
single condition (condition equation) is met.
Description
Condition = If true, execute expression_1
Condition = If false, execute expression_2
Precautions
IF must be used together with END_IF.
The condition must include a true or false equation for the evaluation
result.
Example: IF(A>10)
The condition can also be specified as a boolean variable only rather than
an equation. As a result, the variable value is 1 (ON) = True result, 0
(OFF) = False result.
Statements that can be used in expression_1 and expression_2 are
assignment statements, IF, CASE, FOR, WHILE, or REPEAT.
Example:
IF <condition_1> THEN
IF <condition_2> THEN
<expression_1>;
ELSE
<expression_2>:
END_IF;
END_IF;
The processing flow diagram is as follows:
Condition 1 False
True
Condition 2
False
True
Expression 1
Expression 1
149
Section 5-5
Statement Descriptions
Condition
False
True
Expression
Examples
Example 1: If variable A>0 is true, variable X will be substituted with numerical
value 10. If A>0 is false, variable X will be substituted with numerical value 0.
IF A>0 THEN
X:=10;
ELSE
X:=0;
END_IF;
Example 2: If variable A>0 and variable B>1 are both true, variable X will be
substituted with numerical value 10, and variable Y will be substituted with
numerical value 20. If variable A>0 and variable B>1 are both false, variable X
and variable Y will both be substituted with numerical value 0.
IF A>0 AND B>1 THEN
X:=10; Y:=20;
ELSE
X:=0; Y:=0;
END_IF;
Example 3: If the boolean (BOOL data type) variable A=1(ON), variable X will
be substituted with numerical value 10. If variable A=0(OFF), variable X will
be substituted with numerical value 0.
IF A THEN X:=10;
ELSE X:=0;
END_IF;
IF Statement (Multiple
Conditions)
Summary
This statement is used to execute an expression when a specified condition is
met. If the first condition is not met, but another condition is met, a corresponding expression is executed. If none of the conditions is met, a different
expression is executed.
Reserved Words
IF, THEN, ELSIF, (ELSE), END_IF
150
Section 5-5
Statement Descriptions
Note
Statement Syntax
Condition 1
True
Expression 1
False
Condition 2
True
Expression 2
False
Condition 3
False
True
Expression 3
Expression m
Usage
Use the IF statement to perform different operations depending which of multiple conditions (condition equation) is met.
Description
Condition 1 = If true, execute expression 1
Condition 1 = If false,
Condition 2 = If true, execute expression 2
Condition 2 = If false,
Condition 3 = If true, execute expression 3
etc.
Condition n = If true, execute expression n
If none of these conditions are met, condition m is executed.
Precautions
IF must be used together with END_IF.
Condition_@ contains the true or false result of the equation (e.g.,
IF(A>10)).
A boolean (BOOL data type) variable only can also be specified as the
condition rather than an equation. For boolean conditions, the result is
true when the variable value is 1 (ON) and false when it is 0 (OFF).
Statements that can be used in expression_@ are assignment statements, IF, CASE, FOR, WHILE, or REPEAT.
151
Section 5-5
Statement Descriptions
152
Section 5-5
Statement Descriptions
Processing Flow Chart
Same as
selected
value 1?
Yes
No
Same as
selected
value 2?
Yes
No
Same as
selected
value n?
Yes
No
Expression m
Expression n
Expression 2
Expression 1
Usage
Use the CASE statement to execute different operations depending on specified integer values.
Description
If the integer_equation matches integer_equation_value_n, expression_n is
executed.
if the integer_equation does not match any of integer_equation_value_n,
expression_m is executed.
Precautions
CASE must be used together with END_CASE.
The result of the integer_equation must be in integer format (INT, DINT,
LINT, UINT, UDINT, or ULINT).
Statements that can be used in expression_@ are assignment statements, IF, CASE, FOR, WHILE, or REPEAT.
Multiple statements can be executed in expression_@. Be sure to use a
semicolon (;) delimiter between multiple statements in an expression.
Variables in integer format (INT, DINT, LINT, UINT, UDINT, or ULINT), or
equations that return integer values can be specified in the
integer_equation.
When OR logic is used for multiple integers in the
integer_equation_value_n, separate the numerical value using a comma
delimiter. To specify a sequence of integers, use two periods (..) as delimiters between the first and last integers.
153
Section 5-5
Statement Descriptions
Examples
BY can be omitted.
Statement Syntax
FOR <iteration_variable>:= <initial_value> TO <final_value_equation> BY
<increment_value_equation>
DO
<expression>;
END_FOR;
154
Section 5-5
Statement Descriptions
Processing Flow Chart
Iteration variable = Initial
True
Iteration
variable
Final value?
Iteration
False
Expression
End
Usage
Use the FOR statement when the number of iterations has been determined
beforehand. FOR is particularly useful when switching the number of elements in an array variable according to the value of a specified iteration variable.
Description
When the iteration_variable is the initial_value, the expression is executed.
After execution, the value obtained from the increment_equation is added to
the iteration_variable, and if the iteration_variable < final_value_equation (see
note 1), the expression is executed. After execution, the value obtained from
the increment_equation is added to the iteration_variable, and if the
iteration_variable < final_value_equation value (see note 1), the expression is
executed. This process is repeated.
If the iteration_variable final_value_equation (see note 2), the processing
ends.
Note
155
Section 5-5
Statement Descriptions
FOR i:=0 TO 100 DO
array[i]:=0;
END_FOR;
IF i=101 THEN
a:=TRUE;
ELSE
a:=FALSE;
END_IF;
Do not use a FOR statement in which an iteration variable is changed
directly. Doing so may result in unexpected operations.
Example:
FOR i:=0 TO 100 BY 1 DO
array[i]:=0;
i:=i+5;
END_FOR;
Statements that can be used in the expression are assignment statements, IF, CASE, FOR, WHILE, or REPEAT.
Multiple statements can be executed in the expression. Be sure to use a
semicolon (;) delimiter between multiple statements in an expression.
BY increment_equation can be omitted. When omitted, BY is taken as 1.
Variables with integer data types (INT, DINT, LINT, UINT, UDINT, or
ULINT), or equations that return integer values can be specified in the
initial_value, final_value_equation, and increment_equation.
Example 1: The iteration is performed when the iteration variable n = 0 to
50 in increments of 5, and the array variable SP[n] is substituted with 100.
FOR n:=0
TO 50 BY 5 DO
SP[n]:=100;
END_FOR;
Example 2: The total value of elements DATA[1] to DATA[50] of array variable DATA[n] is calculated, and substituted for the variable SUM.
FOR n:=0
TO 50 BY 1 DO
SUM:=SUM+DATA[n];
END_FOR;
Example 3: The maximum and minimum values from elements DATA[1] to
DATA[50] of array variable DATA[n] are detected. The maximum value is
substituted for variable MAX and the minimum value is substituted for variable MIN. The value for DATA[n] is between 0 and 1000.
MAX:=0;
MIN:=1000;
FOR n:=1
TO 50 BY 1 DO
IF DATA[n]>MAX THEN
MAX:=DATA[n];
END IF;
IF DATA[n]<MIN THEN
MIN:=DATA[n];
END IF;
END_FOR;
WHILE Statement
Summary
This statement is used to execute a specified expression repeatedly for as
long as a specified condition is true.
156
Section 5-5
Statement Descriptions
Reserved Words
WHILE, DO, END_WHILE
Statement Syntax
WHILE <condition> DO
<expression>;
END_WHILE;
Processing Flow Chart
Iteration
Condition
False
True
Expression
End
Usage
Use the WHILE statement when the number of iterations has not been determined beforehand (depends on the condition being met) to repeat specified
processing for the duration that the condition is met. This statement can be
used to execute processing while the condition equation is true only (pretest
loop).
Description
Before the expression is executed, the condition is evaluated.
If the condition is true, the expression is executed. Afterwards, the condition is
evaluated again. This process is repeated. If the condition is false, the expression is not executed and the condition evaluation ends.
Precautions
WHILE must be used in combination with END_WHILE.
Before executing the expression, if the condition equation is false, the process will end without executing the expression.
Statements that can be used in the expression are assignment statements, IF, CASE, FOR, WHILE, or REPEAT.
Multiple statements can be executed in the expression. Be sure to use a
semicolon (;) delimiter between multiple statements in an expression.
The condition can also be specified as a boolean variable (BOOL data
type) only rather than an equation.
Examples
Example 1: The value exceeding 1000 in increments of 7 is calculated and
substituted for variable A.
A:=0;
WHILE A<=1000 DO
A:=A+7;
END_WHILE;
157
Section 5-5
Statement Descriptions
Example 2: While X<3000, the value of X is doubled, and the value is substituted for the array variable DATA[1]. The value of X is then multiplied by 2
again, and the value is substituted for the array variable DATA[2]. This process
is repeated.
n:=1
WHILE X<3000 DO
X:=X*2;
DATA[n]:=X;
n:=n+1;
END_WHIE;
REPEAT Statement
Summary
This statement is used to repeatedly execute an expression until a specified
condition is true.
Reserved Words
REPEAT, UNTIL, END_REPEAT
Statement Syntax
REPEAT
<expression>;
UNTIL <condition>
END_REPEAT
Processing Flow Chart
Expression
Condition
Iteration
False
True
End
Usage
Use the REPEAT statement to repeat processing for as long as a condition is
met after specified processing, when the number of iterations is undetermined
beforehand (depends on whether the condition is met). This statement can be
used to determine whether to repeat processing according to the results of
specified processing execution (post-test loop).
Description
The expression will execute the first time without a condition. Thereafter, the
condition equation will be evaluated. If the condition is false, the expression
will be executed again. If the condition is true, processing will end without executing the expression.
Precautions
REPEAT must be used together with END_REPEAT.
Even if the condition equation is true before the expression has been executed, the expression will be executed.
158
Section 5-5
Statement Descriptions
Statements that can be used in the expression are assignment statements, IF, CASE, FOR, WHILE, or REPEAT.
Multiple statements can be executed in the expression. Be sure to use a
semicolon (;) delimiter between multiple statements in an expression.
The condition can also be specified as a boolean variable (BOOL data
type) only rather than an equation.
Examples
Example 1: Numeric values from 1 through 10 are incremented and the total
is substituted for the variable TOTAL.
A:=1;
TOTAL:=0;
REPEAT
TOTAL:=TOTAL+A;
A:=A+1;
UNTIL A>10
END_REPEAT;
EXIT Statement
Summary
This statement is used within iteration statements (FOR, WHILE, REPEAT)
only to force an iteration statement to end. This statement can also be used
within an IF statement to force an iteration statement to end when a specified
condition is met.
Reserved Words
EXIT
Statement Syntax (Example: Using within IF Statement)
FOR (WHILE, REPEAT) expression
...
IF <condition> THEN EXIT;
END_IF;
...
END_FOR (WHILE, REPEAT);
Usage
Use the EXIT statement to force iteration processing to end before the end
condition is met.
Description (Example: Using within IF Statement)
When the condition equation is true, the iteration statement (FOR, WHILE,
REPEAT) is forced to end, and any statements after EXIT will not be executed.
Note
(1) The condition can also be specified as a boolean variable (BOOL data
type) only rather than an equation.
(2) Even if the condition equation is true before the expression has been executed, the expression will be executed.
Example
Processing is repeated from when variable n = 1 until 50 in increments of 1
and n is added to array variable DATA[n]. If DATA[n] exceeds 100, however,
processing will end.
159
Section 5-5
Statement Descriptions
FOR n:=1; TO 50 BY 1 DO
DATA[n]:=DATA[n]+n;
IF DATA[n]>100 THEN EXIT;
END_IF;
END_FOR;
RETURN Statement
Summary
The data type is any of the function blocks internal variable names (when ST
is used in the function blocks instance) or global variable names (when ST is
used in an ST task or SFC action program).
Entry Method 1
Use this method to enter both the argument specification (called function
block definitions variable name) and return value specification.
A(B:=C, .......... ,D=>E)
160
Section 5-5
Statement Descriptions
A: Instance name
B: Called function block definitions input variable name
Note
When B and D are omitted, as shown above, C is moved to the B position and
passed automatically in the order that values are registered in that variable
table. In contrast, the values from the D position are automatically received at
E in the order that values are registered in that variable table.
Usage
Use the function block call statement to call a function block definition (ST or
ladder language) from an ST-language program.
Description
1. The following instance is registered in the internal or global variables in the
variable table.
Internal variable element
Content
Example
Name
Any instance name
Calcu_execute
Data type
FUNCTION BLOCK
FUNCTION BLOCK
FB definition
Selects the called func- Calculation
tion block definition.
161
Section 5-5
Statement Descriptions
2. The values that will be passed between variables are specified within parentheses after the instance name registered in step 1 (Calcu_execute in
this example), and a semi-colon marks the end of the statement, as shown
in the following example.
Calcu_execute (A:=B,C=>D) ;
The value of B is passed to A, and at the same time the value of C is received at D.
A: Called function block definitions input variable name
B: One of the following values, depending on the ST program being used
Calling function blocks input variable or a constant (when ST is being
used in the function blocks instance)
Global variable or local variable name (when ST is being used in an
ST task or SFC action program)
C: Called function block definitions output variable name or constant
D: One of the following values, depending on the ST program being used
Calling function blocks output variable or constant (when ST is being
used in the function blocks instance)
Global variable or local variable name (when ST is being used in an
ST task or SFC action program)
Examples Showing Additional Details
The following two examples show how to actually use an ST program to call a
function block.
Example 1:
These examples show how to call a function block from each kind of source
program (ST task, SFC, and function block).
Conditions:
A function block is called.
The called function block is written in ladder language or ST language.
Call Details
a. Calling a function block from an ST task or SFC program
ST task
(ST)
Example) ...
Instance_FB(...,...);
SFC
(ST)
Stepn
aaa
(ST)
Example) ...
Instance_FB(...,...);
Action program
162
Example) ...
Section 5-5
Statement Descriptions
b. Calling a function block from another function block
Function block (ST)
Program
(ST)
Example) ...
Instance_FB(...,...);
Instance_ST
ST
Example) ...
Variable Settings
Setting the variables of the ST program and SFC program (call source)
The ST program and SFC program have the following variables, and the
following values are passed with the called function block.
Variable name in ST task/
SFC program
IN1
IN2
IN3
OUT1
OUT2
OUT3
A
Input variables
Output variables
163
Section 5-5
Statement Descriptions
Variable type
Internal variables
Internal variables
(instance)
Passed to EN.
Input variables
Output variables
Examples
Example of Entry Method 1
Instance_FB(EN:=A,FB_IN1:=IN1,FB_IN2:=IN2,FB_IN3:= IN3,
FB_OUT1=>OUT1,FB_OUT2=> OUT2,FB_OUT3=> OUT3,ENO=>B)
It is all right for the arguments and return values to be listed in irregular
order.
The input variables' arguments must be at the beginning of the list, or just
after the EN variable if the EN variable is listed.
Output variables may be omitted if the data is not used.
Specification method 2 cannot be used together with specification method
A in the same function block call statement.
Examples of other Entry Formats
EN not entered:
Instance_FB(FB_IN1:=IN1,FB_IN2:=IN2,FB_IN3:= IN3,
FB_OUT1=>OUT1,FB_OUT2=> OUT2,FB_OUT3=> OUT3,ENO=>B)
EN and ENO not entered:
Instance_FB(FB_IN1:=IN1,FB_IN2:=IN2,FB_IN3:= IN3,
FB_OUT1=>OUT1,FB_OUT2=> OUT2,FB_OUT3=> OUT3)
ENO not entered:
Instance_FB(EN:=A,FB_IN1:=IN1,FB_IN2:=IN2,FB_IN3:=IN3,
FB_OUT1=>OUT1,FB_OUT2=>OUT2,FB_OUT3=>OUT3)
FB_OUT2 data not required:
Instance_FB(EN:=A,FB_IN1:=IN1,FB_IN2:=IN2,FB_IN3:=IN3,
FB_OUT1=>OUT1,FB_OUT3=>OUT3,ENO=>B)
164
Section 5-5
Statement Descriptions
Instance_FB(FB_IN1:=IN1,FB_IN2:=IN2,FB_IN3:=IN3,
FB_OUT1=>OUT1,FB_OUT3=>OUT3)
Different order of entry:
Instance_FB(EN:=A,FB_IN1:=IN1,FB_OUT1=> OUT1,FB_IN2:=IN2,
FB_OUT2=>OUT2,FB_IN3:= IN3,FB_OUT3=> OUT3,ENO=>B)
Example of Entry Method 2
In this example, only parameter variables (including constants) of a new
instance are entered.
Instance_FB(IN1, IN2, IN3, OUT1, OUT2, OUT3)
Instance_FB(IN1, IN2, IN3, OUT1)
The arguments and return values must be listed in a fixed order.
Input variable 1, Input variable 2, ..., Output variable 1, Output variable 2,
...
The input variables arguments must be at the beginning of the list, or just
after the EN variable if the EN variable is listed.
An output variable can be omitted if the data is not actually being used
and the output variable is not in the middle of the list of output variables.
Example: Instance_FB(IN1, IN2, IN3, OUT1, OUT3)
In this case, the OUT3 at the end of the list would return the value from
FB_OUT2.
The EN and ENO data cannot be entered as an argument or return value.
Specification method 1 cannot be used together with specification method
B in the same function block call statement.
Example 2
In the following example, function block 1 calls function block 2, which calculate the average value by calling a function block from within a function block.
The data1, data2, and data3 values are
passed to input1, input2, and input3.
FB1 (ST)
Program
Instance_FB1
Average_FB( input1 := data1, input2 := data2,
input3 := data3, average => AVG );
FB1
FB2 (ST)
average := ( input1 + input2 + input3 ) / 3 ;
Function Block 1
Variable Table
Variable type
Input variable
Input variable
Input variable
Input variable
Input variable
Output variable
Output variable
Internal variable
Variable name
EN
data1
data2
data3
bCheck
ENO
AVG
Average_FB
Data type
BOOL
INT
INT
INT
BOOL
BOOL
INT
FUNCTION BLOCK
Called function block definition:
Function block 2
165
Section 5-6
Variable name
EN
input1
input2
input3
ENO
average
Data type
BOOL
INT
INT
INT
BOOL
INT
ST-language Algorithm
Calculates the average value of input1, input2, and input3 and stores the
result in average.
average:=(input1+input2+input3)/3;
5-6
5-6-1
Converting an Integer
to BCD and
Outputting It as a Text
String
FB
(BOOL)
(BOOL)
EN
ENO
(INT)
Input_Num
(STRING)
(STRING)
Output_StringOutput_String
Input Variable
INT Input_Num;
Input-Output Variable
STRING Output_String;
Internal Variable
WORD Num_BCD;
(*Check Input_BCD input parameter (BCD data)*)
IF(Input_BCDNum>=0 & Input_BCD<=16#Num<=9999) THEN
166
Section 5-7
Restrictions
ENO:=true;
ELSE
ENO:=false;
RETURN;
END_IF;
Num_BCD:=INT_TO_BCD_WORD(Input_Num);
(*For example, if Num is 100 (16#0064), it is converted to BCD 0100*)
Output_String:=WORD_TO_STRING(Num_BCD);
(*Convert BCD 0100 to text string*)
5-7
5-7-1
Restrictions
Restrictions
Nesting
There is no restriction on the number of nests that can be used in IF,
CASE, FOR, WHILE, or REPEAT statements.
Data Type Restrictions
Integers can only be allocated to variables with data types WORD,
DWORD, INT, DINT, UINT, UDINT, or ULINT. For example, if A is an INT
data type, A:=1; it possible. If the value is not an integer data type, a syntax error will occur. For example, if A is an INT data type, a syntax error
will occur for A:=2.5;.
If a real number (floating point decimal data) can only be allocated to variables with data types REAL and UREAL. For example, if A is a REAL data
type, A:=1.5; is possible. If the value is not an real data type, a syntax
error will occur. For example, if A is a REAL data type, a syntax error will
occur for A:=2;. Use A:=2.0;.
Bits (TRUE, FALSE) can only be allocated to variables with the BOOL
data type. For example, if A is a BOOL data type, A:=FALSE; is possible.
If a BOOL data type is not used, a syntax error will occur. For example, if
A is an INT data type, a syntax error will occur for A:=FALSE;.
Data types must all be consistent within the structured text. For example,
if A, B, and C are INT data types, A:=B+C; is possible. If, however, A and
B are INT data types, but C is a REAL data type or LINT data type, a syntax error will occur for A:=B+C;.
In the structured text, the following cannot be used:
P_CY, P_EQ, P_ER, P_N, P_GE, P_GT, P_LE, P_LT, P_NE, P_OF, and
P_UF
5-7-2
167
Section 5-7
Restrictions
FOR i:=0 TO 100 BY 1 DO
a:=a+1;
END_FOR;
Q: What occurs when the array subscript is exceeded?
A: For the array variable INT[10] with 10 elements, an error will not be
detected for the following type of statement. Operation will be unstable when
this statement is executed.
i:=15;
INT[i]:=10;
Q: Are the variables in the structured text editor automatically registered
in the variable tables?
A: No. Register the variables in the variable table before using them.
Q: Can ladder programming instructions be called directly?
A: No.
168
SECTION 6
Creating ST Programs
This section explains how to create ST programs.
6-1
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
170
6-1-1
Creating a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
170
6-1-2
170
6-1-3
171
6-1-4
172
6-1-5
174
6-1-6
174
6-1-7
Comparing ST Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
175
6-1-8
175
6-1-9
176
169
Section 6-1
Procedures
6-1
Procedures
This section explains how to create ST programs. For details on creating a
function block with ST language, refer to SECTION 3 Creating Function
Blocks in Part 1: Function Blocks of this manual.
6-1-1
Creating a Project
1,2,3...
6-1-2
1. Right-click the Programs Item in the project workspace to display the popup menu.
2. Select Insert Program - ST from the pop-up menu.
170
(1) Ladder and SFC programs can also be created. To create these programs, right-click the Programs Item in the project workspace to display
the pop-up menu, and select Insert Program - Ladder or Insert Program - SFC.
For details on ladder programming, refer to the CX-Programmer Operation Manual (W446).
For details on SFC programming, refer to the CX-Programmer Operation
Manual: SFC (W469).
Section 6-1
Procedures
(2) When a new project has been created, ST programs can be set as the
PLCs initial program type. Select Tools - Options and click the PLCs
Tab to set this option.
6-1-3
The following procedure, which allocates a program to a task, can be performed after the program has been created, but always allocate the programs
before transferring the user program to the PLC.
Use the following procedure to allocate a program to a task.
1,2,3...
1. Right-click the inserted ST program item in the project workspace, and select Properties from the pop-up menu.
171
Section 6-1
Procedures
2. Click the General Tab in the displayed Program Properties Dialog box, and
select the task from the Task Type List. To set a program name, input the
program name in the Name Text Box in this tab page.
3. Click the Close Button to close the Program Properties Dialog Box.
4. When the program is allocated to a task, the check mark over the ST programs icon will be deleted. The allocated task number will be shown in parentheses after the program name.
6-1-4
Inputting the ST
Language after
Registering Variables
There are two kinds of variables: global variables and local variables. This
section explains how to set local variables. For details on setting global variables, refer to the CX-Programmer Operation Manual (W446).
2. The symbol table will be displayed. Right-click to display the pop-up menu,
and select Insert Symbol from the pop-up menu.
(It is also possible to select Insert - Symbol.)
3. The New Symbol Dialog Box will be displayed. Set the following items, and
click the OK Button.
172
Section 6-1
Procedures
Name: Input the variable name.
Data type: Select the data type.
Address or Value: Input the address.
Input the name.
The default is BOOL.
Change the data type if required.
When variables are being registered without specifying addresses, the CXProgrammer can be set to allocate addresses automatically. For details on
Automatic Allocation, refer to the CX-Programmer Operation Manual (W446).
Symbol table
ST Editor Window
If the symbol table with the registered variables is displayed while inputting
the ST program, it is easy to reference the variable names for programming.
Note
(1) Tabs or spaces can be input to create indents. They will not affect the algorithm.
(2) The display size can be changed by holding down the Ctrl Key and turning the scrolling wheel on a wheel mouse.
(3) When an ST language program is input or pasted into the ST input area,
syntax keywords reserved words will be automatically displayed in blue,
173
Section 6-1
Procedures
Registering Variables
While Using
Structured Text
6-1-5
When using structured text, a dialog box will not be displayed to register the
variable whenever a variable name that has not been registered is input. Be
sure to always register variables used in standard text programming in the
variable table, either as you need them or after completing the program.
1. Select the ST program, right-click, and select Compile from the pop-up
menu. (Alternately, press the Ctrl + F7 Keys.)
2. The ST program will be compiled and the results of the program check will
be automatically displayed on the Compile Table Page of the Output Window.
6-1-6
174
Section 6-1
Procedures
6-1-7
Comparing ST Programs
It is possible to compare the edited ST program with an ST program block in
the actual PLC or another project file to check whether the two ST programs
are identical. For details on comparing programs, refer to the CX-Programmer
Operation Manual (W446).
6-1-8
Monitoring the ST
Programs Variables
The Set New Value Dialog Box will be displayed. Input the new value in the
Value field.
Force-setting and Force-resetting Bits
To force-set, force-reset, or clear the forced status, select the desired variable
in the ST variable monitor window (displayed in reverse video when selected),
right-click, and select Force - On, Force - Off, Force - Cancel, or Force Cancel All Forces from the pop-up menu.
Copying and Pasting in the Watch Window
1,2,3...
1. To copy a variable to the Watch Window, select the desired variable in the
ST variable monitor window (displayed in reverse video when selected),
right-click, and select Copy from the pop-up menu.
175
Section 6-1
Procedures
2. Right-click in the Watch Window and select Paste from the pop-up menu.
ST Program
Simulation Function
6-1-9
Starting Online
Editing
1,2,3...
1. Start monitoring.
2. Select the desired ST program in the project workspace, and display it in
program view.
3. Select Program - Online Edit - Begin. At this point, it will be possible to
edit the ST program.
4. Start editing the ST program.
176
Section 6-1
Procedures
Transferring the
Changes
1,2,3...
Cancelling the
Changes
Transfer Modes
Standard Mode
In Standard Mode, both the ST programs source code and object code are
transferred to the CPU Unit. Some time may be required for Standard Mode
transfers because of the quantity of data that must be sent. Other editing or
transfer operations cannot be performed until the transfer has been completed.
Quick Mode
In Quick Mode, only the ST programs object code is transferred to the CPU
Unit. The ST source code is not transferred, making Quick Mode faster than
Normal Mode. After transferring the object code in Quick Mode, either 1)
select Program - Transfer SFC/ST Source to PLC to transfer the source
code or 2) transfer the source code according to instructions displayed in a
dialog box when you go offline.
After transferring the object code, a yellow mark will be displayed at the bottom of the window until offline status is entered to indicate that the source
code has not yet been transferred. This yellow mark will disappear when the
source code is transferred.
Selecting a Transfer
Mode
It may be still be possible to transfer the source code with the following procedure, even if the above problem occurs.
177
Section 6-1
Procedures
Transferring Source Code
from a Backup Project
1,2,3...
3. Click the OK Button. the CX-Programmer will start the backup project from
the previous Quick Mode transfer.
4. Connect online with the PLC that was the destination of the Quick Mode
transfer. The following dialog box will be displayed.
1. Start the CX-Programmer, and open the project file with the ST source
code to be transferred.
2. Connect online with the PLC that was the destination of the Quick Mode
transfer. The flashing yellow message Src, Fail will be displayed in the CXProgrammers status bar
3. Select Program - Online Edit - Transfer SFC/ST Source to PLC. The ST
source code transfer dialog box will be displayed.
4. Click the OK Button.
The ST source code that was automatically backed up in the computer will
be compared with the object code in the actual PLC, and the ST source
code can be transferred if the code matches.
Note
178
Procedures
Section 6-1
For CJ2-series CPU Units, there is no restriction on the number of steps
that can be added to or deleted from a function block definition during one
online editing operation.
Online editing is not possible for ST programs that exceed 4 Ksteps
(except for CJ2-series CPU Units).
A maximum of 0.5 Ksteps can be added to or deleted from an ST program
during one online editing operation (except for CJ2-series CPU Units).
After performing online editing, do not turn OFF the power supply to the
PLC until the CPU Unit has finished backing up data to the built-in flash
memory (i.e., until the BKUP indicator goes OFF). If the power supply is
turned OFF before the data is backed up, the data will not be backed up
and the program will return to the status it had before online editing was
performed.
179
Procedures
180
Section 6-1
Appendix A
System-defined external variables supported
in function blocks
Classification
Conditions Flags
Clock Pulses
Name
Greater Than or Equals (GE) Flag
External variable in
Data type
CX-Programmer
P_GE
BOOL
CF00
P_NE
P_LE
P_ER
P_CY
P_GT
P_EQ
P_LT
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
CF001
CF002
CF003
CF004
CF005
CF006
CF007
P_N
BOOL
CF008
P_OF
P_UF
P_AER
P_Off
P_On
P_0_02s
P_0_1s
P_0_2s
P_1mim
P_1s
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
BOOL
CF009
CF010
CF011
CF114
CF113
CF103
CF100
CF101
CF104
CF102
P_First_Cycle
P_Step
P_First_Cycle_Task
P_Max_Cycle_Time
P_Cycle_Time_Value
P_Cycle_Time_Error
P_Low_Battery
P_IO_Verify_Error
P_Output_Off_Bit
P_CIO
P_HR
P_WR
P_DM
P_EM0 to P_EMC
BOOL
BOOL
BOOL
UDINT
UDINT
BOOL
BOOL
BOOL
BOOL
WORD
WORD
WORD
WORD
WORD
A200.11
A200.12
A200.15
A262
A264
A401.08
A402.04
A402.09
A500.15
A450
A452
A451
A460
A461 to
A473
Address
Note These words are external variables for the OMRON FB Library. Do not use these words for creating
function blocks.
181
182
Appendix A
Appendix B
Structured Text Errors
Error Messages
Error Message
%s' Input variables cannot be
assigned a value
%s' operator not supported by
%s data type
Cause of error
A value was substituted for an
input variable.
A numerical value or variable
for a data type that is not supported by the operator was
used.
A value was substituted for a
%s' variable had a read only
memory AT Address and can- variable allocated to a readonly memory address (readnot be assigned a value
only Auxiliary Area address or
Condition Flag).
Array index out of range
An array index larger than the
array size was specified.
Conversion cannot convert
A numeric equation in which
from %s to %s
the data type of the operation
result does not match the variable at the substitution destination and a variable that is
different from the data type
was substituted.
Division by Zero
The numeric expression contains division by 0.
End of comment not found
The comment does not have a
closing parenthesis and asterisk *) corresponding to the
opening parenthesis and
asterisk (* of the comment.
Invalid Literal Format '%s'
The numeric format is illegal.
Example
(*comment
183
Appendix B
Invalid expression
Cause of error
A numeric equation with a
non-integer type operation
result, or a non-integer variable or numeric value has
been specified in the integer
equation of a CASE statement.
The numeric equation is illegal. For example, the integer
equation or condition equation
is illegal or has not been specified in the syntax (IF, WHILE,
REPEAT, FOR, CASE).
Missing END_FOR
Missing END_IF
Missing END_REPEAT
184
Example
CASE A OF (*A is a REAL type variable*)
1: X:=1;
2: X:=2;
END_CASE;
Y:=SIN(X1, ENO=>1);
Y:=INT_TO_DINT X);
Y:=(X1+X2/2
CASE A OF
1 X:=1;
END_CASE;
Appendix B
Missing ]
Missing constant
Cause of error
END_WHILE is not provided at the end of the WHILE
statement.
The function argument is not
specified or is insufficient.
OF is not included in CASE
statement.
THEN is not included in IF
statement.
TO is not included in FOR
statement.
UNTIL is not included in
REPEAT statement.
The array index for the array
variable has not been specified.
The array index for the array
variable has not been specified.
A constant is not provided in
the integer equation of the
CASE statement.
Example
Y:=EXPT(X);
CASE A OF
2..: X:=1;
2,: X:=2;
END_CASE;
Result:=NOT 1;
Y:=-X; (*X is an UINT type variable, Y is an INT type variable*)
185
Appendix B
Warning Messages
Warning message
Keyword '%s' is redundant
186
Cause of warning
Example
The keyword has been used
in an invalid location. For
example, use of the EXIT
statement outside a loop syntax.
Data may be lost due to con- Y:=DINT_TO_INT(X); (*X is a DINT type variable, Y is an
version of a data type with a
INT type variable*)
large data size to a data type
with a small data size.
Appendix C
Function Descriptions
Standard Functions
Text String Functions
LEN: Detect String Length
Function
Finds the length of a specified text string.
Application
Return_value := LEN(string);
Arguments and Return Values
Variable name
String
Data type
STRING
Return_value
INT
Description
Specifies the text string for
which to find the length.
Returns the size of the specified text string.
Example
Variables
STRING Message
INT Result
Message
Result:=LEN(Message);
"8" is stored in Result variable.
Data type
STRING
Number_of_characters
INT, UINT
Return_value
STRING
Description
Specifies the text string from which to
extract characters.
Specifies the number of characters to
extract.
Returns the extracted characters.
Example
Variables
STRING Message
STRING Result
Message
Result:=LEFT(Message,3);
"ABC" is stored in the Result variable.
187
Appendix C
Function Descriptions
Arguments and Return Values
Variable name
Source_string
STRING
Data type
Number_of_characters
INT, UINT
Return_value
STRING
Description
Specifies the text string from
which to extract characters.
Specifies the number of characters to extract.
Returns the extracted characters.
Example
Variables
STRING Message
STRING Result
Message
Result:=RIGHT(Message,3);
"FGH" is stored in the Result variable.
Data type
STRING
Number_of_characters
INT, UINT
Position
INT, UINT
Return_value
STRING
Description
Specifies the text string from which to
extract characters.
Specifies the number of characters to
extract.
Specifies the position from which to start
extracting characters. The first character is
position 1 (e.g., position 1 is A in message 1 in the following illustration).
Returns the extracted characters.
Example
Variables
STRING Message
STRING Result
Message
Result:=MID(Message,3,2);
"BCD" is stored in the Result variable.
188
STRING
STRING
Data type
Description
Specifies a text string to be joined.
Specifies a text string to be joined.
STRING
Appendix C
Function Descriptions
Example
Variables
STRING
STRING
STRING
STRING
Message 1
C Message 2 D
Message1
Message2
Message3
Result
Message 3
Result:=CONCAT(Message1,Message2,Message3);
"ABCDEFGH" is stored in the Result variable.
Result
Data type
STRING
Description
Specifies the text string into which to insert characters.
Insert_string
STRING
Position
INT, UINT
Return_value
STRING
Specifies the position at which to insert characters. The first character is position 1 (e.g., position 1 is A in message 1 in the following
illustration).
Returns the text string with the characters
inserted.
Example
Variables
STRING Message1
STRING Message2
STRING Result
Message 1
Message 2
Data type
STRING
Number_of_characters
Position
INT, UINT
INT, UINT
Return_value
STRING
Description
Specifies the text string from which to delete
characters.
Specifies the number of characters to delete.
Specifies the position from which to delete
characters. The first character is position 1
(e.g., position 1 is A in message 1 in the following illustration).
Returns the text string with the specified
number of characters deleted.
189
Appendix C
Function Descriptions
Example
Message
Variables
STRING Message1
STRING Result
Result:=DEL(Message1,4,2);
"AFGH" is stored in the Result variable.
Result
STRING
Data type
Replace_string
Number_of_characters
STRING
INT, UINT
Position
INT, UINT
Return_value
STRING
Description
Specifies the text string in which to replace
characters.
Specifies the replace text string.
Specifies the number of characters to be
replaced.
Specifies the position from which to
replace characters. The first character is
position 1 (e.g., position 1 is A in message 1 in the following illustration).
Returns the text string with the characters
replaced.
Example
Message 1
Variables
STRING Message1
STRING Message2
STRING Result
Message 2
Result:=REPLACE(Message1,Message2,2,3);
"ABXYEFGH" is stored in the Result variable.
Result
190
Data type
STRING
STRING
INT
Description
Specifies the text string to search.
Specifies the text string to find.
Returns the position of the first occurrence of
the find text string. The first character is position
1 (e.g., position 1 is A in message 1 in the following illustration).
Appendix C
Function Descriptions
Example
Variables
STRING Message1
STRING Message2
INT Result
Message 1
Message 2
Result:=FIND(Message1,Message3);
"2" is stored in the Result variable.
Delimiter
STRING
Parameter
Description
Specifies the text string to write to a file.
Specifies the directory and file name, including the root directory(\). The file name must be 8 characters or less. The file
name extension is always TXT. For example, the following file
name creates a file named LINE_A.TXT in the root directory:
\LINE_A.
'': Empty character
',': Comma
$L or $l: Line feed (ASCII 0A)
$N or $n: Carriage return + line feed (ASCII 0D 0A)
$P or $p: New page (ASCII 0C)
$R or $r: Carriage return (ASCII 0D)
$T or $t: Tab (ASCII 09)
0: Append
1: Create new file
191
Appendix C
Function Descriptions
Example
Variables
BOOL
BOOL
STRING
INT
STRING
STRING
P_MemCardBusyFlag
P_MemCardAskFlag
FileName
LogData1 2 3
FiledStrl1 2 3
CsvLineStr
FileName := '\LOGFILE';
LogData1 := 12;
LogData2 := 345;
LogData3 := 6789;
(* Output data to text file if Memory Card write conditions are met. *)
IF ( P_MemCardAckFlag AND (NOT P_MemCardBusyFlag) ) THEN
(* Convert from number to text string *)
FieldStr1 := INT_TO_STRING( LogData1 );
FieldStr2 := INT_TO_STRING( LogData2 );
FieldStr3 := INT_TO_STRING( LogData3 );
(* Create 1-row CSV-format numeric value text string *)
CsvLineStr := FieldStr1 + ',' + FieldStr2 + ',' + FieldStr3;
(* Output one line of numeric data to file *)
WRITE_TEXT( CsvLineStr, FileName, '$n', 0 );
END_IF;
Related Auxiliary
Area Flag
File Memory Operation Flag
Memory Card
Detected Flag
LOGFILE.TXT
12,345,6789
Address
A343.13
Description
ON when any of the following conditions exists:
CMND instruction sending a FINS command to the local
CPU Unit.
File Memory Instruction being executed.
Program replacement using the control bit in the Auxiliary
Area.
Easy backup operation.
ON when a Memory Card has been detected.
A343.15
For further information and precautions on related Auxiliary Area flags, refer to the section on the FWRIT File
Memory Instruction in the CS/CJ-series Instruction Reference Manual.
Communications Functions
TXD_CPU: Send String via CPU Unit RS-232C Port
Function
Sends a text string from the RS-232C port on the CPU Unit.
Application
TXD_CPU (Send_string);
Conditions
The serial communications mode of the RS-232C port must be set to no-protocol communications.
Arguments and Return Values
Variable name
Send_string
192
Data type
STRING
Description
Specifies the text string to send.
Appendix C
Function Descriptions
Example
CPU Unit
RS-232C
port
Barcode Reader
Variables
BOOL
INT
STRING
BOOL
DoSendData
iProcess
Message
SendEnableCPUPort
Related Auxiliary
Area Flag
RS-232C Port Send
Ready Flag
Address
A392.05
Description
ON when sending is enabled in no-protocol mode.
For further information and precautions on related Auxiliary Area flags, refer to the section on TXD Serial Communications Instruction in the CS/CJ-series Instruction Reference Manual.
TXD_SCB: Send String via Serial Port on Serial Communications Board
Function
Sends a text string from a serial port on a Serial Communications Board (SCB).
Application
TXD_SCB (Send_string, Serial_port);
Conditions
The serial communications mode of the serial port must be set to no-protocol communications.
Arguments and Return Values
Variable name
Send_string
Serial_port
Data type
STRING
INT, UINT, WORD
Description
Specifies the text string to send.
Specifies the number of the serial port.
1: Serial port 1
2: Serial port 2
193
Appendix C
Function Descriptions
Example
Serial
Communications
Board
CPU Unit
(SCB)
Serial
port 1
Barcode Reader
Variables
BOOL
INT
STRING
BOOL
P_DoSendData
(* Variable to control send function *)
iProcess
(* Process number *)
Message
(* Send message *)
P_SendEnableSCBPort1 (* Send Ready Flag *) AT A356.05
Serial port 1 used.
Related Auxiliary
Area Flag
Port 1 Send Ready
Flag
Port 2 Send Ready
Flag
Address
Description
A356.05
A356.13
For further information and precautions on related Auxiliary Area flags, refer to the section on TXD Serial Communications Instruction in the CS/CJ-series Instruction Reference Manual.
TXD_SCU: Send String via Serial Port on Serial Communications Unit
Function
Sends a text string from a serial port on a Serial Communications Unit (SCU).
Application
TXD_SCU (Send_string, SCU_unit_number, Serial_port, Internal_logic_port);
Conditions
The serial communications mode of the serial port must be set to no-protocol communications.
194
Appendix C
Function Descriptions
Arguments and Return Values
Variable name
Send_string
SCU_unit_number
Data type
STRING
INT, UINT, WORD
Serial_port
Internal_logic_port
Description
Specifies the text string to send.
Specifies the number of the Serial Communications Unit.
1: Serial port 1
2: Serial port 2
0 to 7: Internal logic port number specified
16#F: Automatic internal logic port allocation
Example
Serial
Communications
Unit (SCU)
CPU Unit Unit No. : 0
GetScene
SceneNumber
Number
Get
Command:@READ
@READ
command:
Serial
port 2
Barcode reader
Variables
BOOL
INT
STRING
BOOL
P_DoSendData
iProcess
Message
P_TXDU_Exe
BOOL
P_ComInstEnable
(* Use the following: Unit number: 0, Serial port number: 2, Logical port number: 7 *)
(* Send data when P_DoSendData is ON and iProcess is 0 *)
IF (P_DoSendData = TRUE) AND (iProcess = 0) THEN
iProcess := 1;
P_DoSendData := FALSE;
END_IF;
(* Execute send processing according to process number *)
CASE iProcess OF
1: (* Create send text data *)
Message := '@READ';
iProcess := 2;
2: (* Execute send function if Communications Port Enable Flag and TXDU Execution Flag are ON *)
IF (P_ComInstEnable = TRUE) AND (P_TXDU_Exe = FALSE) THEN
TXD_SCU(Message, 0, 2, 7);
iProcess := 3;
END_IF;
3: (* Sending has been completed if Communications Port Enable Flag is ON *)
IF P_ComInstEnable = TRUE THEN
iProcess := 0;
END_IF;
END_CASE;
195
Appendix C
Function Descriptions
Related Auxiliary
Area Flag
Communications
Instruction Enable
Flags
Related CPU Bus
Unit Area bits
n = CIO 150 + 25 x
unit number
Port 1: n+9
Port 2: n+19
Address
A202.00 to A202.07
Bit
05
For further information and precautions on related Auxiliary Area flags, refer to the section on TXDU Serial
Communications Instruction in the CS/CJ-series Instruction Reference Manual.
RXD_CPU: Receive String via CPU Unit RS-232C Port
Function
Receives a text string from the RS-232C port on the CPU Unit.
Application
RXD_CPU (Storage_location, Number_of_characters)
Conditions
The serial communications mode of the RS-232C port must be set to no-protocol communications.
Arguments and Return Values
196
Variable name
Storage_location
Data type
STRING
Number_of_characters
Description
Specifies the storage location for the received
text string.
Specifies the number of characters to receive.
0 to 255
Appendix C
Function Descriptions
Example
CPU Unit
Message Value to read
RS-232C
port
Barcode reader
Variables
BOOL
STRING
BOOL
P_DoRecvData
Message
P_EndRecvCPUPort
Related Auxiliary
Area Flag
RS-232C Port
Reception Completed Flag
RS-232C Port
Reception Overflow
Flag
RS-232C Port
Reception Counter
Address
Description
A392.06
A392.07
A393
For further information and precautions on related Auxiliary Area flags, refer to the section on RXD Serial Communications Instruction in the CS/CJ-series Instruction Reference Manual.
RXD_SCB: Receive String via Serial Port on Serial Communications Board
Function
Receives a text string from a serial port on a Serial Communications Board (SCB).
Application
RXD_SCB (Storage_location, Number_of_characters, Serial_port)
Conditions
The serial communications mode of the serial port must be set to no-protocol communications.
Arguments and Return Values
Variable name
Storage_location
Data type
STRING
Number_of_characters
Serial_port
Description
Specifies the storage location for the received
text string.
Specifies the number of characters to receive.
0 to 255
Specifies the number of the serial port.
1: Serial port 1
2: Serial port 2
197
Appendix C
Function Descriptions
Example
Serial
Communications
Board
(SCB) CPU Unit
Serial
port 1
Barcode reader
Variables
BOOL
P_DoRecvData
STRING Message
BOOL
P_EndRecvSCBPort1
Related Auxiliary
Area Flag
Port 1 Reception
Completed Flag
Port 1 Reception
Overflow Flag
Port 1 Reception
Counter
Port 2 Reception
Completed Flag
Port 2 Reception
Overflow Flag
Port 2 Reception
Counter
Address
Description
A356.06
A356.07
A357
A356.14
A356.15
A358
For further information and precautions on related Auxiliary Area flags, refer to the section on RXD Serial Communications Instruction in the CS/CJ-series Instruction Reference Manual.
RXD_SCU: Receive String via Serial Port on Serial Communications Unit
Function
Receives a text string from a serial port on a Serial Communications Unit (SCU).
Application
RXD_SCU (Storage_location, Number_of_characters, SCU_unit_number, Serial_port,
Internal_logic_port);
Conditions
The serial communications mode of the serial port must be set to no-protocol communications.
198
Appendix C
Function Descriptions
Arguments and Return Values
Variable name
Storage_location
STRING
Data type
Number_of_characters
SCU_unit_number
Serial_port
Internal_logic_port
Description
Specifies the storage location for the received text
string.
Specifies the number of characters to receive.
0 to 255
Specifies the number of the Serial Communications Unit.
1: Serial port 1
2: Serial port 2
0 to 7: Internal logic port number specified
16#F: Automatic internal logic port allocation
Example
Serial
Communications
Unit (SCU)
CPU Unit Unit No.: 0
Message Value to read
Serial
port 2
Barcode reader
Variables
BOOL
INT
STRING
BOOL
BOOL
P_DoRecvData
iProcess
Message
P_RXDU_Recv
(* Use the following: Unit number: 0, Serial port number: 2, Logical port number: 7 *)
(* Receive data when P_DoRecvData is ON and iProcess is 0 *)
IF (P_DoRecvData = TRUE) AND (iProcess = 0) THEN
iProcess := 1;
P_DoRecvData := FALSE;
END_IF;
(* Execute receive processing according to process number *)
CASE iProcess OF
1:
(* Reception function executed if Communications Enabled Flag and Reception Completed
Flag are ON. *);
IF (P_ComInstEnable = TRUE) AND (P_RXDU_Recv = TRUE) THEN
RXD_SCU(Message, 16, 0, 2, 7);
iProcess := 2;
END_IF;
2:
(* Reception has been completed if Communications Port Enable Flag is ON *)
IF P_ComInstEnable = TRUE THEN
iProcess := 0;
END_IF;
END_CASE;
199
Appendix C
Function Descriptions
Address
A202.00 to
A202.07
Bit
ON when reception has been completed in no-protocol mode.
For further information and precautions on related Auxiliary Area flags, refer to the section on RXDU Serial
Communications Instruction in the CS/CJ-series Instruction Reference Manual.
Data type
REAL, LREAL
REAL, LREAL
Description
Specifies an angle in degrees.
Returns an angle in radians.
200
Data type
REAL, LREAL
REAL, LREAL
Description
Specifies an angle in radians.
Returns an angle in degrees.
Index
A
addresses
allocation areas, 42
checking internal allocations, 104
setting allocation areas, 102
algorithm
creating, 87
applications
precautions, xxiii
array settings, 20, 38, 59, 89
AT settings, 19, 38, 89
restrictions, 51
automatically generating function block definitions, 92
advantages, 12
application guidelines, 56
creating, 23
debugging, 113
defining, 85
elements, 31
errors, 55
monitoring, 113
operating specifications, 49
outline, 11
restrictions, 51
reusing, 24
setting parameters, 99
specifications, 6, 7, 30
structure, 13
functions, 4
function blocks, 6, 7
restrictions, 5
compiling, 107
D
data types, 19, 37
determining, 56
debugging function blocks, 113
differentiation
restrictions, 51
G
global symbol table, 18
I
IEC 61131-3, 4, 7
input variables, 32
input-output variables, 35
E
errors
function blocks, 55
external variables, 37
externals, 19
F
features, 4
files
function block definitions, 112
library, 8
project text files, 8
function block definitions, 13
checking for an instance, 106
compiling, 107
creating, 82
saving to files, 112
inputs, 19
instance areas, 21, 42
setting, 21, 102
instances
creating, 23, 97
multiple, 46
number of, 14
outline, 14
registering in global symbol table, 18
specifications, 42
internal variables, 35
internals, 19
L
ladder programming
function block definition, 84
restrictions in function blocks, 51
function blocks
201
Index
M
menus, 8
main, 8
popup, 10
monitoring function blocks, 113
O
online editing
function block definitions, 121
restrictions, 54
output variables, 33
outputs, 19
P
parameters
outline, 15
precautions, xxi
applications, xxiii
general, xxii
safety, xxii
Programming Consoles, 54
projects
creating, 82
S
safety precautions, xxii
specifications
CX-Programmer Ver. 5.0, 5
function block operation, 49
instances, 42
structured text
function block definition, 84
restrictions, 53
symbol name
automatically generating, 91
T
timer instructions
operation, 75
restrictions, 52
202
V
variable names, 19
variables
address allocations, 21
checking address allocations, 104
creating as needed, 88
definitions, 31
introduction, 18
properties, 19, 37
registering in advance, 85
restrictions, 51
setting allocation areas, 21
usage, 19, 32
Revision History
A manual revision code appears as a suffix to the catalog number on the front cover of the manual.
Revision code
The following table outlines the changes made to the manual during each revision. Page numbers refer to the
previous version.
Revision
Date
code
01
February 2005
02
November 2005
03
04
July 2006
January 2007
05
07
08
July 2007
June 2008
February 2009
Revised content
Original production
Added Ver. 6.1 upgrade information, such as information on the Simulation functions and
ST program variable monitoring.
Added Ver. 7.0 upgrade information.
Pages 17 and 18: Changed can to cannot in table (two locations) and changed note.
Page 29: Changed text in inputs cell for the status of value at next execution.
Page 213: Changed illustration.
Pages 214, 216 to 218, and 202: Changed illustration and changed code.
Pages 215 and 219: Changed text in bottom right cell.
Added upgrade information from Ver. 7.0 to Ver. 7.2.
Added upgrade information from Ver. 7.2 to Ver. 8.0.
Added upgrade information from Ver. 8.0 to Ver. 8.1.
203
Revision History
204
OMRON Corporation
Industrial Automation Company
Control Devices Division H.Q.
PLC Division
Shiokoji Horikawa, Shimogyo-ku,
Kyoto, 600-8530 Japan
Tel: (81) 75-344-7084/Fax: (81) 75-344-7149
Regional Headquarters
OMRON EUROPE B.V.
Wegalaan 67-69-2132 JD Hoofddorp
The Netherlands
Tel: (31)2356-81-300/Fax: (31)2356-81-388
Authorized Distributor: