SYSMAC
WS02-CXPC1-E-V50
CS1-H, CJ1-H, CJ1M CPU Units
Cat.No. W438-E1-01
CX-Programmer
Ver. 5.0
WS02-CXPC1-E-V50
CS1-H, CJ1-H, CJ1M CPU Units
Operation Manual
Function Blocks
Produced July 2004
iv
Notice:
r
f
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.
!DANGERIndicates an imminently hazardous situation which, if not avoided, will result in death or
serious injury.
!WARNINGIndicates a potentially hazardous situation which, if not avoided, could result in death or
serious injury.
!CautionIndicates a potentially hazardous situation which, if not avoided, may result in minor or
moderate injury, or property damage.
OMRON Product References
All OMRON products are capitalized in this manual. The word “Unit” is also capitalized when it refers to
an OMRON product, regardless of whether or not it appears in the proper name of the product.
The abbreviation “Ch,” which appears in some displays and on some OMRON products, often means
“word” and is abbreviated “Wd” in documentation in this sense.
The abbreviation “PLC” means Programmable Controller. “PC” is used, however, in some Programming Device displays to mean Programmable Controller.
Visual Aids
The following headings appear in the left column of the manual to help you locate different types of
information.
OMRON, 2004
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, o
by any means, mechanical, electronic, photocopying, recording, or otherwise, without the prior written permission o
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.
Note Indicates information of particular interest for efficient and convenient opera-
tion of the product.
1,2,3...1. Indicates lists of one sort or another, such as procedures, checklists, etc.
This manual describes the function blocks and related functionality of the CX-Programmer Ver. 5.0
used together with CS1-H, CJ1-H, and CJ1M CPU Units with unit version 3.0 or later, and includes the
sections described on the next page. The CX-Programmer Ver. 5.0 is software that enables the personal computer to be used as a function block programming device, and can be used only for SYSMAC CS-series and CJ-series CPU Units that support function blocks.
The CX-Programmer Ver. 5.0 function block functions have been enhanced. This manual describes
only CX-Programmer Ver. 5.0 operations that are related to functions blocks. For operations not related
to function blocks, refer to the CX-Programmer Operation Manual (enclosed, Cat. No. W437). This
manual also provides only information related to function blocks for the CS1-H, CJ1-H, and CJ1M CPU
Units. For other information, refer to the CS/CJ-series manuals.
Please read this manual and related manuals carefully and be sure you understand the information
provided before attempting to install or operate the CX-Programmer Ver. 5.0 or the CS1-H, CJ1-H, or
CJ1M CPU Units. Be sure to read the precautions provided in the following section.
Manuals Related to the CX-Programmer Ver. 5.0
NameCat. No.Contents
SYSMAC WS02-CXPC1-E-V50
CX-Programmer Ver. 5.0 Operation Manual
Function Blocks
W438Describes the functionality unique to the CX-Programmer Ver.
5.0 and CS/CJ-series CPU Units with unit version 3.0 or later
based on function blocks. Functionality that is the same as
that of the CX-Programmer is described in W437 (enclosed).
W437Provides information on how to use the CX-Programmer for
all functionality except for function blocks.
Manuals Related to the CS1-H, CJ1-H, CJ1M CPU Units
NameCat. No.Contents
SYSMAC CS Series
CS1G/H-CPU@@-EV1, CS1G/H-CPU@@H
Programmable Controllers
Operation Manual
SYSMAC CJ Series
CJ1G-CPU@@, CJ1G/H-CPU@@H, CJ1GCPU@@P, C J 1 M - C P U @@
Programmable Controllers
Operation Manual
W339Provides an outline of and describes the design, installation,
maintenance, and other basic operations for the CS-series
PLCs.
The following information is included:
An overview and features
The system configuration
Installation and wiring
I/O memory allocation
Troubleshooting
Use this manual together with the W394.
W393Provides an outline of and describes the design, installation,
maintenance, and other basic operations for the CJ-series
PLCs.
The following information is included:
An overview and features
The system configuration
Installation and wiring
I/O memory allocation
Troubleshooting
Use this manual together with the W394.
ix
NameCat. No.Contents
SYSMAC CS/CJ Series
CS1G/H-CPU@@-EV1, CS1G/H-CPU@@H,
CJ1G-CPU@@, CJ1G/H-CPU@@H, CJ1GCPU@@P, C J 1 M - C P U @@
Programmable Controllers
Programming Manual
SYSMAC CS/CJ Series
CS1G/H-CPU@@-EV1, CS1G/H-CPU@@H,
CJ1G-CPU@@, CJ1G/H-CPU@@H, CJ1GCPU@@P, C J 1 M - C P U @@
Programmable Controllers
Instructions Reference Manual
SYSMAC CS/CJ Series
CS1G/H-CPU@@-EV1, CS1G/H-CPU@@H,
CS1W-SCB21-V1/41-V1, CS1W-SCU21/41,
CJ1G-CPU@@, CJ1G/H-CPU@@H, CJ1GCPU@@P, C J 1 M - C P U @@, CJ1W-SCU21-V1/
41-V1
Communications Commands
Reference Manual
W394Describes programming and other methods to use the func-
tions of the CS/CJ-series PLCs.
The following information is included:
Programming
Ta sk s
File memory
Other functions
Use this manual together with the W339 or W393.
W340Describes the ladder diagram programming instructions sup-
ported by CS/CJ-series PLCs.
When programming, use this manual together with the Oper-
ation Manual (CS1: W339 or CJ1: W393) and Programming
Manual (W394).
W342Describes the communications commands that can be
addressed to CS/CJ-series CPU Units.
The following information is included:
C-series (Host Link) commands
FINS commands
Note: This manual describes commands that can be sent to
the CPU Unit without regard for the communications path,
which can be through a serial communications port on the
CPU Unit, a communications port on a Serial Communications Unit/Board, or a port on any other Communications
Unit.
Overview of Contents
Precautions provides general precautions for using the CX-Programmer Ver. 5.0.
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.
The Appendices provide information on data types, structure text specifications, and external vari-
ables.
!WARNING Failure to read and understand the information provided in this manual may result in per-
sonal 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.
x
PRECAUTIONS
This section provides general precautions for using the CX-Programmer Ver. 5.0 and the Programmable Logic Controller.
The information contained in this section is important for the safe and reliable application of the CX-Programmer
Ver. 5.0 and Programmable Controller. You must read this section and understand the information contained before
attempting to set up or operate the CX-Programmer Ver. 5.0 and Programmable Controller.
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.
2General 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 speci-
fied 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.
3Safety Precautions
!WARNING Confirm safety sufficiently before transferring I/O memory area status from the
CX-Programmer Ver. 5.0 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.
xii
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
Application Precautions4
• When the size to be processed by the instruction operand is fixed:
The number of array elements must be the same as the number of elements to be processed by the instruction. Otherwise, the CX-Programmer
will output an error when compiling.
• When the size to be processed by the instruction operand is not fixed:
The number of array elements must be greater than or the same as the
size specified in the other operands.
• If the other operand specifying a size is a constant, the CX-Programmer Ver. 5.0 will output an error when compiling.
• If the other operand specifying a size is a variable, the CX-Programmer
Ver. 5.0 will not output an error when compiling, even if the size of the
array variable is not the same as that specified by the other operand
(variable). A warning message, however, will be displayed. In particular, if the number of array elements is less than the size specified by
the other operand (e.g., the size of the instruction operand is 16, and
the number of elements registered in the actual variable table is 10),
the instruction will execute read/write processing for the area that exceeds the number of elements. For example, read/write processing will
be executed for the 6 words following those for the number of elements
registered in the actual variable table. If these words are used for other
instructions (including internal variable allocations), unexpected operation will occur, which may result in serious accidents.
Check that the system will not be adversely affected if the size of the
variable specified in the operand is less than the size in the operand
definition before starting PLC operations.
!Caution Confirm safety at the destination node before transferring a program to
another node or changing contents of the I/O memory area. Doing either of
these without confirming safety may result in injury.
!Caution Execute online editing only after confirming that no adverse effects will be
caused by extending the cycle time. Otherwise, the input signals may not be
readable.
!Caution Confirm safety sufficiently before monitoring power flow and present value
status in the Ladder Section Window or when monitoring present values in the
Watch Window. If force-set/reset or set/reset operations are inadvertently performed by pressing short-cut keys, the devices connected to Output Units
may malfunction, regardless of the operating mode of the CPU Unit.
4Application 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.
• Disable sharing hard disks, printers, or other devices with other computers on any network.
xiii
Application Precautions4
• 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 CS1-H, CJ1-H, and CJ1M 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 Mem-
ory 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 the 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 in the input variable.) Therefore, an input variable cannot be used
as the operand of the instruction in the function block when the operand
specifies the first or last of multiple words. Use an internal variable with an
AT setting. Alternatively, specify the first or last element in an internal
array variable.
xiv
Application Precautions4
• Values are passed in a batch from the input parameters to the input variables before algorithm execution (not at the same time as the instructions
in the algorithm are executed). Therefore, to pass the value from a
parameter to an input variable when an instruction in the function block
algorithm is executed, use an internal variable or external variable instead
of an input variable. The same applies to the timing for writing values to
the parameters from output variables.
• Always use internal variables with AT settings in the following cases.
• The addresses allocated to Basic I/O Units, Special I/O Units, and
CPU Bus Units cannot be registered to global symbols, and these variables cannot be specified as external variables (e.g., the data set for
global variables may not be stable).
• Use internal variables when Auxiliary Area bits other than those preregistered to external variables are registered to global symbols and
these variables are not specified as external variables.
• Use internal variables when specifying PLC addresses for another
node on the network: For example, the first destination word at the remote node for SEND(090) and the first source word at the remote
node for RECV(098).
• Use internal variables when the first or last of multiple words is specified by an instruction operand and the operand cannot be specified as
an internal array variable (e.g., the number of array elements cannot
be specified).
xv
Application Precautions4
xvi
SECTION 1
Introduction
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.
The CX-Programmer Ver. 5.0 is a Programming Device that can use standard
IEC 61131-3 function blocks. The CX-Programmer Ver. 5.0 function block
function is supported for CS/CJ-series CPU Units with unit version 3.0 or later
and has the following features.
• User-defined processes can be converted to block format by using function blocks.
• Function block algorithms can be written in the ladder programming language or in the structured text (ST) language. (See note.)
• When ladder programming is used, ladder programs created with nonCX-Programmer Ver. 4.0 or earlier can be reused by copying and pasting.
• When ST language is used, it is easy to program mathematical processes that would be difficult to enter with ladder programming.
Note The ST language is an advanced language for industrial control
(primarily Programmable Logic Controllers) that is described in IEC
61131-3. The ST language supported by CX-Programmer conforms to the IEC 61131-3 standard.
• Function blocks can be created easily because variables do not have to
be declared in text. They are registered in variable tables.
A variable can be registered automatically when it is entered in a ladder or
ST program. Registered variables can also be entered in ladder programs
after they have been registered in the variable table.
• A single function block can be converted to a library function as a single
file, making it easy to reuse function blocks for standard processing.
• A program check can be performed on a single function block to easily
confirm the function block’s reliability as a library function.
• Programs containing 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 containing function blocks, however, cannot be downloaded in task
units (uploading is possible).
• One-dimensional array variables are supported, so data handling is easier for many applications.
NoteThe 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).
2
Introducing the Function BlocksSection 1-1
1-1-2Function Block Specifications
For specifications that are not listed in the following table, refer to the CX-Programmer Ver. 5.0 Operation Manual (W437).
ItemSpecifications
Model numberWS02-CXPC1-E-V50
Setup diskCD-ROM
Compatible CPU UnitsCS/CJ-series CS1-H, CJ1-H, and CJ1M CPU Units with unit version 3.0 or
Compatible
computers
ComputerIBM PC/AT or compatible
CPU133 MHz Pentium or faster with Windows 98, SE, or NT 4.0 (with service pack
OSMicrosoft Windows 95, 98, SE, Me, 2000, XP, or NT 4.0 (with service pack 6
Memory64 Mbytes min. with Windows 98, SE, or NT 4.0 (with service pack 6 or
Hard disk space100 Mbytes min. available disk space
Monitor
CD-ROM driveOne CD-ROM drive min.
COM portOne RS-232C port min.
later are compatible.
Device TypeCPU Type
• CS1G-HCS1G-CPU42H/43H/44H/45H
• CS1H-HCS1H-CPU63H/64H/65H/66H/67H
• CJ1G-HCJ1G-CPU42H/43H/44H/45H
• CJ1H-HCJ1H-CPU65H/66H/67H
• CJ1MCJ1M-CPU11/12/13/21/22/23
Note If a user program containing function blocks created on the CX-Pro-
grammer 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.
CS/CJ Series Function Restrictions
• Instructions Not Supported in Function Block Definitions
Block Program Instructions (BPRG and BEND), Subroutine Instructions
(SBS, GSBS, RET, MCRO, and SBN), Jump Instructions (JMP, CJP, and
CJPN), Step Ladder Instructions (STEP and SNXT), Immediate Refresh
Instructions (!), I/O REFRESH (IORF), ONE-MS TIMER (TMHH)
For details, refer to 2-3 Restrictions on Function Blocks.
6 or higher)
or higher)
higher)
Refer to Computer System Requirements below for details.
SVGA (800
Note Use “small font” for the font size.
× 600 pixels) min.
3
Introducing the Function BlocksSection 1-1
ItemSpecifications
Functions not
supported by
CX-Programmer Ver. 4.0
or earlier.
Defining
and creating function blocks
Creating
instances
Storing
function
blocks as
files
Number of
function block
definitions
Function
block names
VariablesVariable names30,000 characters max.
LanguageFunction blocks can be created in ladder programming language or structured
Number of
instances
Instance
names
Project filesThe project file (.cxp/cxt) Includes function block definitions and instances.
Program files The file memory program file (*.obj) includes function block definitions and
Function
block library
files
CS1-H/CJ1-H CPU Units:
• Suffix -CPU44H/45H/64H/65H/66H/67H: 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
64 characters max.
Variable typesInputs, Outputs, Internals, and Externals
Number of I/O variables in
function block definitions
Allocation of addresses
• Suffix -CPU44H/45H/64H/65H/66H/67H: 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
30,000 characters max.
instances.
Each function block definition can be stored as a single file (.cxf) for reuse in
other projects.
64 max. (not including EN and ENO)
Automatic allocation (The allocation range can
be set by the user.)
Supported
NoteThe 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, and comments.
For details, refer to Appendix B Structured Text (ST Language) Specifications.
1-1-3Files Created with CX-Programmer Ver. 5.0
Project Files (*.cxp) and
File Memory Program
Files (*.obj)
Projects created using CX-Programmer that contain function block definitions
and projects with instances are saved in the same standard project files
(*.cxp) and file memory program files (*.obj).
The following diagram shows the contents of a project. The function block definitions are created at the same directory level as the program within the relevant PLC directory.
A function block definition created in a project with CX-Programmer Ver. 5.0
can be saved as a file (1 definition = 1 file), enabling definitions to be loaded
into other programs and reused.
Project Text Files
Containing Function
Data equivalent to that in project files created with CX-Programmer Ver. 5.0
(*.cxp) can be saved as CXT text files (*.cxt).
Blocks (*.cxt)
1-1-4CX-Programmer Ver. 5.0 Function Block Menus
The following tables list CX-Programmer Ver. 5.0 menus related to function
blocks. For details on all menus, refer to the CX-Programmer Ver. 5.0 Opera-tion Manual (W437).
Each function block can be
stored in a separate
definition file (.cxf).
Main Menu
Main menuSubmenuShortcutFunction
FileFunc-
tion
Block
EditUpdate Function Block---When a function block definition’s I/O variables have been changed
InsertFunction Block InvocationFCreates an instance in the program (section) at the present cursor
Function Block Parameter PWhen the cursor is located to the left of an input variable or the right
PLCFunc-
tion
Block
Memory
Load Function
Block from File
Save Function
Block to File
Function Block
Memory Allocation
Function Block
Memory Statistics
Function Block
Instance Address
Optimize Function
Memory
---Reads the saved function block library files (*.cxf).
---Saves the created function block definitions to a file ([function block library file]*.cxf).
after the instance was created, an error will be indicated by displaying the instance’s left bus bar in red. This command updates the
instance with the new information and clears the error.
location.
of an output variable, sets the variable’s input or output parameter.
---Sets the range of addresses (function block instance areas) internally allocated to the selected instance’s variables.
---Checks the status of the addresses internally allocated to the
selected instance’s variables.
---Checks the addresses internally allocated to each variable in the
selected instance.
---Optimizes the allocation of addresses internally allocated to variables.
5
Introducing the Function BlocksSection 1-1
Main Popup Menus
Popup Menu for Function Block Definitions
Popup menuFunction
Insert Function BlockLadderCreates a function block definition with a ladder programming language algo-
Structured TextCreates a function block definition with an ST language algorithm.
From fileReads a function block definition from a function block library file (*.cxf).
Popup Menu for Inserted Function Blocks
Popup menuFunction
OpenDisplays the contents of the selected function block definition on the right side of the window.
Save Function Block File Saves the selected function block definition in a file.
CompileCompiles the selected function block definition.
Popup Menu for Function Block Variable Tables
Popup menuFunction
EditEdits the variable.
Insert VariableAdds a variable to the last line.
Insert Variable AboveInserts the variable above the current cursor position.
BelowInserts the variable below the current cursor position.
CutCuts the variable.
CopyCopies the variable.
PastePastes the variable.
FindSearches for the variable. Variable names, variable comments, or all (text strings) can
be searched.
ReplaceReplaces the variable.
DeleteDeletes the variable.
RenameChanges only the name of the variable.
rithm.
Popup Menu for Instances
Popup menuFunction
EditChanges the instance name.
Update InvocationWhen a function block definition’s I/O variables have been changed after the instance
Go To Function Block Definition Displays the selected instance’s function block definition on the right side of the window.
was created, an error will be indicated by displaying the instance’s left bus bar in red.
This command updates the instance with the new information and clears the error.
Shortcut Keys
F Key: Pasting Function
Block Definitions in
Program
P Key: Inputting
Parameters
Move the cursor to the position at which to create the copied function block
instance in the Ladder Section Window, and click 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 at the right of the output
variable and click the P Key. This operation is the same as selecting Insert -Function Block Parameter.
6
Function BlocksSection 1-2
1-2Function Blocks
1-2-1Outline
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.
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
Standard
program section
written with
variables
Define in advance.
Insert in
program.
Save function
block as a file.
Convert to
library function.
Function
block A
Reuse.
1-2-2Advantages of Function Blocks
Function blocks allow complex programming units to be reused easily. Once
standard programming is created in a function block and saved in a file, it can
be reused just by placing the function block in a program and setting the
parameters for the function block’s I/O. The ability to reuse existing function
blocks will save significant time when creating/debugging programs, reduce
coding errors, and make the program easier to understand.
Program 1
Copy of function block A
InputOutput
Variable Variable
Set
Copy of function block A
InputOutput
Variable Variable
To another PLC program
Set
Variable
Output
Structured
Programming
Easy-to-read “Black Box”
Design
Use One Function Block
for Multiple Processes
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).
7
Function BlocksSection 1-2
Reduce Coding ErrorsCoding mistakes can be reduced because blocks that have already been
debugged can be reused.
Data ProtectionThe variables in the function block cannot be accessed directly from the out-
side, so the data can be protected. (Data cannot be changed unintentionally.)
Improved Reusability with
Variable Programming
The function block’s I/O is entered as variables, so it isn’t necessary to change
data addresses in a block when reusing it.
Creating LibrariesProcesses that are independent and reusable (such as processes for individ-
ual steps, machinery, equipment, or control systems) can be saved as function block definitions and converted to library functions.
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.
Compatible with
Mathematical expressions can be entered in structured text (ST) language.
Multiple Languages
1-2-3Function Block Structure
Function Block
Definitions
Function blocks consist of function block definitions that are created in
advance and function block instances that are inserted in the program.
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
Variable definitions
Example: CLOCK PULSE
1. Algorithm
tim_b
tim_a
2. Variable Definitions
Usage
Internal
Internal
Input
Input
TIMX tim_a OFF_TIME
TIMX tim_b ON_TIME
Name
tim_aTIMER
tim_bTIMER
ON_TIMEINT
OFF_TIMEINT
ENO
Type
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.
8
Function BlocksSection 1-2
2. Variable Definitions
The variable table lists each variable’s usage (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.
InstancesTo use an actual function block definition in a program, create a copy of the
function block diagram and insert it in the program. Each function block definition that is inserted in the program is called an “instance” or “function block
instance.” Each instance is assigned an identifier called an “instance name.”
By generating instances, a single function block definition can be used to process different I/O data with the same function.
Not yet in program
and memory not yet
allocated
(abstract).
Function Block Definition FB1
1. Algorithm
Standard
program unit
with variable
names a, b, c,
etc.
2. Parameters
Table defining usage
and properties of
variables a, b, c, etc.
Insert in
program.
Insert in
program.
Block instance in program with memory
allocated. (object)
Program
Instance FB1_1 of function block definition FB1
Input
data
Instance FB1_2 of function block definition FB1
Input
data
Instance
ab
ab
c
Output data
Output data
c
Output data
Output data
Automatic
allocation
Automatic
allocation
Memory
used
Memory
for FB1_1
Memory
for FB1_2
Different I/O data
can be processed
with the same
function.
NoteInstances 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.
9
Function BlocksSection 1-2
instance_A
Function Block Definition
TIMER_FB
Variable Definitions
Internal variable: WORK_NUM
TIMER_FB
Use same internal variables.
instance_A
TIMER_FB
instance_B
TIMER_FB
Use different internal variables.
Number of InstancesMultiple instances can be created from a single function block definition. Up to
either 256 or 2,048 instances can be created for a single CPU Unit depending
on the CPU Unit model. The allowed number of instances is not related to the
number of function block definitions and the number of tasks in which the
instances are inserted.
ParametersEach time an instance is created, set the real I/O memory addresses or con-
stants for I/O 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
Set the constants or
input source addresses
from which to pass data.
ab
c
Output 2.00
Set the constant or
output destination
address to which to pass
data.
10
Here, it is not the input source address itself, but the contents at the input
address in the form and size specified by the variable data type that is passed
to the function block. In a similar fashion, it is not the output destination
address itself, but the contents for the output address in the form and size
specified by the variable data type that is passed from the function block.
Function BlocksSection 1-2
Even if an input source address (i.e., an input parameter) or an output destination address (i.e., an output parameter) is a word address, the data that is
passed will be the data in the form and size specified by the variable data type
starting from the specified word address.
Program
Instance of Function Block Definition A
Input D100
Input D200
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.
mk
n
Output D300
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
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.
■ Reference Information
A variety of processes can be created easily from a single function block by
using parameter-like elements (such as fixed values) as input variables and
changing the values passed to the input variables for each instance.
Example: Creating 3 Instances from 1 Function Block Definition
11
Function BlocksSection 1-2
Cyclic task 0
Instance
CASCADE_01
Algorithm
Internal and I/O
Function Block Definition
Example: CONTROL
Algorithm
Variables
Example:
There are 3 FB
instances and each
has its own I/O and
internal variables.
variables
Instance
CASCADE_02
Algorithm
Internal and I/O
variables
Instance
CASCADE_03
Algorithm
Internal and I/O
variables
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 task 0
P_On
&100
&130
P_On
&150
Function block definition
Example: CONTROL
Algorithm
Variables
The same instance can be
used at multiple locations.
Instance
CASCADE
Algorithm
Internal and I/O
variables
P_On
&20
&10
P_On
&15
&10
Cyclic task 1
P_On
&7
&8
CASCADE
CONTROL
EN ENO
PARA_1
PARA_2
CASCADE
CONTROL
EN ENO
&50
PARA_1
PARA_2
CASCADE_01
CONTROL
EN ENO
ON_TIME
OFF_TIME
CASCADE_02
CONTROL
EN ENO
ON_TIME
OFF_TIME
CASCADE_03
CONTROL
EN ENO
ON_TIME
OFF_TIME
1.0
1.1
1.2
1.0
1.1
Cyclic task 1
P_On
&100
&200
CASCADE
EN ENO
PARA_1
PARA_2
CONTROL
1.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.
Registration of InstancesEach instance name is registered in the global symbol table as a file name.
Program
Instance (sample) of function block definition A
ab
c
The instance is registered in the
global symbol table with the instance
name as the symbol name.
Name
Data type
sample FB [FunctionBlock1]N/A[Auto]
Instance name
Address/
value
The function block definition
name is registered after FB in
square parentheses [ ].
12
VariablesSection 1-3
1-3Variables
1-3-1Introduction
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 isn’t necessary for the user to know the real I/O memory addresses
used in the function block, just as it isn’t 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:
Insert in
program.
Program
Input 0.00
Input 3.00
Instance of function block definition A
ab
c
Output 2.00
Function block definition A
Standard program section with
variable names a, b, c, etc.
a
c
b
MOV
Specify inputs and outputs
at the same time.
Table indicating usage and
prpperties of variables a, b, c, etc.
Usage: Inputs
Prpperties:
Name Type AT Initial Value Retained
a BOOL
c
BOOL
Usage: Outputs
Prpperties:
Name Type AT Initial Value
BOOL
b
Retained
NoteConstants are not registered as variables. Enter constants directly in instruc-
tion operands.
• Ladder programming language: Enter hexadecimal numerical values
after the # and decimal values after the &.
• Structured text (ST language): Enter hexadecimal numerical values after 16# and enter decimal numerical values as is.
Exception: Enter directly or indirectly specified addresses for Index Registers
IR0 to IR15 and Data Registers DR0 to DR15 directly into the instruction
operand.
1-3-2Variable Usage and Properties
Status of 0.00 (1 or 0) is
passed to a.
0.00a
11
Status of 3.00 (1 or 0) is
passed to c.
3.00
00
c
The system automatically allocates the
addresses used by variables a, b, and c. For
example, when W100 to W120 is set as the
system’s non-retained memory area, bit
addresses such as a = W10000, b = W10001,
and c = W10002 will be allocated.
Status of b (1 or 0) is
passed to 2.00.
b
2.00
11
Variable UsageThe following variable types (usages) are supported.
Internals:Internal variables are used only within an instance. They cannot
be used pass data directly to or from I/O parameters.
Inputs:Input variables can input data from input parameters outside of
the instance. The default input variable is an EN (Enable) variable, which passes input condition data.
13
VariablesSection 1-3
Outputs:Output variables can output data to output parameters outside of
the instance. The default output variable is an ENO (Enable Out)
variable, which passes the instance’s execution status.
Externals: External variables are either system-defined variables registered
in advance with the CX-Programmer, such as the Condition Flags
and some Auxiliary Area bits, or user-defined global symbols for
use within instances.
For details on variable usage, refer to the section on Variable Type (Usage)
under Variable Definitions in 2-1-2 Function Block Elements.
The following table shows the number of variables that can be used and the
kind of variable that is created by default for each of the variable usages.
1-3-3Variable Properties
Variables have the following properties.
Variable NameThe variable name is used to identify the variable in the function block. It
doesn’t matter if the same name is used in other function blocks.
NoteThe 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 Var i a bl e D e f i-nitions in 2-1-2 Function Block Elements.
Data TypeSelect one of the following data types for the variable:
For details on variable data types, refer to Variable Definitions in 2-1-2 Func-tion Block Elements.
AT Settings (Allocation to
an Actual Addresses)
Array SettingsA variable can be treated as a single array of data with the same properties.
It is possible to set a variable to a particular I/O memory address rather than
having it allocated automatically by the system. To specify a particular
address, the user can input the desired I/O memory address in this property.
This property can be set for internal variables only. Even if a specific address
is set, the variable name must still be used in the algorithm.
Refer to Variable Definitions in 2-1-2 Function Block Elements for details on
AT settings and 2-4-3 AT Settings for Internal Variables for details on using AT
settings.
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 only. Only one-dimensional
arrays are supported by the CX-Programmer Ver. 5.0.
• 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
Elements
.
2-1-2 Function Block
Initial ValueThis 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.
14
VariablesSection 1-3
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.
RetainSelect the Retain Option if you want a variable’s data to be retained when the
PLC is turned ON again and when the PLC starts operating.
• Setting Procedure
Select the Retain Option.
1-3-4Variable Properties and Variable Usage
The following table shows which properties must be set, can be set, and cannot be set, based on the variable usage.
PropertyVariable usage
InternalsInputsOutputs
NameMust be set.Must be set.Must be set.
Data TypeMust be set.Must be set.Must be set.
AT (specified address)Can be set.Cannot be set.Cannot be set.
Initial ValueCan be set.Can be set.
(See note.)
RetainedCan be set.Can be set.
(See note.)
Can be set.
Can be set.
NoteInputs can be set as initial values, but the value of the actual input parameter
will be given priority.
1-3-5Internal Allocation of Variable Addresses
When an instance is created from a function block definition, the CX-Programmer internally allocates addresses to the variables. Addresses are allocated
to all of the variables registered in the function block definition except for variables that have been assigned actual addresses with the AT Settings prop-
erty.
Program
Instance of function block definition A
Input 0.00
Note: Variable c is an internal
a
variable, so it is not displayed.
Usage: Inputs
Properties:
Name Type AT Initial Value
a BOOL
Usage: Outputs
Properties:
Name Type AT
b
BOOL
t
TIMER
Usage: Internals
Properties:
Name TypeInitial Value
c
BOOL
AT
2000.00
Initial Value
b
Output 2.00
t
Output 5.00
Retained
Retained
YES
Retained
Non-retained area
Starting address
Retained area
Starting address
Timer area
Starting address
Counter area
Automatic allocation of
addresses by system
Manual allocation of address to
variable in FB by AT Settings option.
FB instance areas
Starting
address
Example
2000.00
150
CIO, H, W,
D, or E Area
150
H, D, or E
Area
T Area
C Area
Size (words)
Size (words)
Size (Completion
Flags)
Size (Completion
Flags)
Setting Internal Allocation
Areas for Variables
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.
15
Loading...
+ 153 hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.