Professional Documents
Culture Documents
Training fr Umsteiger
Training fr Umsteiger
Overview of contents
Motivation why
TwinCAT 3
eXtended Automation
(XA) overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)
Connectivity
TwinCAT 2 Migration
Functions
TwinCAT 3 | Overview
23.05.2012
23.05.2012
Engineering (XAE)
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
TcCOM
Safety
C++
Module
TcCOM
TcCOM
TcCOM
eXtended
Automation
Runtime (XAR)
PLC
TcCOM
TwinCAT 3
eXtended
Automation (XA)
eXtended
Automation
Engineering (XAE)
TwinCAT 3
Integrated
Visual Studio
2010 Shell
Visual Studio
2010
TwinCAT 3 | Overview
23.05.2012
eXtended Automation
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
Architecture (XAA)
PC System
Windows 32/64 bit
TwinCAT 3 Engineering Environment based on Visual Studio
System Manager
- Configuration
Programming
- IEC 61131-3
- objectoriented extensions
- C/C++
eXtended
Automation Engineering (XAE)
TcCOM
TcCOM
CPLC
Module
C++
PLC
Module
TcCOM
Simulink
PLC
Module
NC
PLC
TcCOM
TcCOM
CNC
PLC
Safety
PLC
TcCOM
TcCOM
PLC
PLC
TcCOM
Real-time Kernel
PLC
PLC
eXtended
Automation Runtime (XAR)
Fieldbus
TwinCAT 3 | Overview
23.05.2012
Engineering (XAE)
TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
eXtended Automation
Engineering (XAE)
TwinCAT 3 | Overview
23.05.2012
10
eXtended Automation
Engineering (XAE)
eXtended Automation Engineering (XAE)
TwinCAT 3
One programming environment
One project folder
One debugging environment for IEC and C/C++ - code
Integration of the familiar TwinCAT System Manager
Programming in IEC 61131-3 3rd Edition (NEU:
NEU object-orientated extension)
Real-time programming in C/C++
Integration and sequence of the C/C++ - program in the IEC environment or
execution as independent real-time code
Link to Matlab/Simulink
TwinCAT 2 PLC projects can be converted into a TwinCAT 3 PLC project
The old TwinCAT System Manager file (*.tsm file) can be converted
Embedded in Microsoft Visual Studio 2010
TwinCAT 3 | Overview
23.05.2012
11
eXtended Automation
Engineering (XAE) - variants
TwinCAT 3 Standard
Based on the Microsoft
Visual Studio Shell
Integrated System
Manager
Integrated IEC-61131-3
3rd edition programming
(OOP)
Integrated Safety PLC
TwinCAT 3 Integrated
Integration in an existing
Microsoft Visual Studio 2010
Integrated System Manager
Integrated IEC-61131-3 3rd
edition programming (OOP)
Integrated Safety PLC
C/C++ programming
Matlab/Simulink
C# and .NET programming for
non-real-time applications
Optional: implementation of thirdparty software tools
TwinCAT 3 | Overview
23.05.2012
12
Engineering (XAE)
TwinCAT 3 Standard
System Manager
Configuration
I/O
PLC
MC
NC
CNC
Safety
others
Configuration,
parameterisation and
diagnosis
Debugging of the PLC
code
Programming
IEC 61131
Objectoriented
extensions
IEC Compiler
TwinCAT 3 Runtime
TwinCAT 3 | Overview
23.05.2012
13
Engineering (XAE)
TwinCAT 3 Integrated
Matlab/
Simulink
Third-party
programming
tool
Programming
Non
real-time
Real-time
C#.NET
IEC 61131
Objectoriented
extensions
IEC Compiler
Real-time
Workshop
C/C++
C/C++
Microsoft C Compiler
TwinCAT 3 Runtime
TwinCAT 3 | Overview
23.05.2012
14
Engineering (XAE)
TwinCAT 3 Integrated integrated working area
Workbench integration - integrated working area
TwinCAT 3 framework = Microsoft Visual Studio 2010
Use of the commonest development environment
Supported by Microsoft
Ultimate
Professional
23.05.2012
15
Engineering (XAE)
Parallel programming of IEC 61131 and C++
C++ Code
IEC Code
TwinCAT 3 | Overview
23.05.2012
16
Engineering (XAE)
TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
17
Engineering (XAE)
Integrated System Manager | Directory tree
System configuration
PLC configuration
Safety PLC configuration
C++ module configuration
I/O configuration
TwinCAT 3 | Overview
23.05.2012
18
Engineering (XAE)
Integrated System Manager | Mapping
Mapping of the process image
Open for all common fieldbuses
Support for all PC hardware interfaces
Simple diagnosis of the fieldbus data
Correlation between logical and physical fieldbus
A change of the bus system does not entail a
change of the PLC code!
TwinCAT process images
Virtual
process
images
Physical
process
images
Inputs
Inputs
Outputs
Fieldbus 1
Outputs
Inputs
Outputs
Inputs
Fieldbus 2
TwinCAT 3 | Overview
Outputs
Fieldbus 3
23.05.2012
19
Engineering (XAE)
TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
20
Engineering (XAE)
TwinCAT 3 PLC
Multiple numbers of PLC projects:
Number of possible tasks: 65,000 (compare here to TwinCAT 2: 4x4)
Number of possible PLC projects limited only by the memory capacity of the automation
device (instead of 4 runtime systems in TwinCAT 2)
Programming
Standard IEC 61131-3 languages (IL, ST, FBD, LD, SFC) +CFC
Use of the object-orientated extensions of IEC 61131-3, 3rd edition
Call and data exchange of code developed in C/C++ and Matlab/Simulink
Large number of import and export interfaces
No direct addressing (necessary)
Commissioning/maintenance
Source code upload/download
Online Change
Complete debugging (breakpoints, monitoring, sequence control etc.) of IEC and C/C++
code
TwinCAT 3 | Overview
23.05.2012
21
Engineering (XAE)
TwinCAT 3 PLC | Development environment
Common tree structure for hardware and software
Common output of diagnosis and error messages (PLC, C++, system etc.)
TwinCAT 3 | Overview
23.05.2012
22
Engineering (XAE)
TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
23
Engineering (XAE)
TwinCAT 3 Motion Control
Scalable solutions (from stepper motor to servo)
Higher flexibility in use and exchange of technology
Shortened development time faster delivery
Fast commissioning, diagnosis and maintenance
Abstraction level - identical access:
PLC/SCADA/HMI always access the same objects, irrespective of the type of
axis or fieldbus employed.
Conversion of mechanical to electronic systems:
Electronic cam plate
Electronic gearing
Electronic coupling
Electronic cam shaft
Flying saw
TwinCAT 3 | Overview
23.05.2012
24
+
PLC
SP
Pos Ctrl
-
Velo Preset
Limit
+
+
Scale & Limit
Pos Meas.
Drives
Layer
Fieldbus
Layer
Soft Motion
Layer
Soft SPS
Layer
Engineering (XAE)
TwinCAT 3 Motion Control | Abstraction level
TwinCAT 3 | Overview
23.05.2012
25
Engineering (XAE)
TwinCAT 3 Motion Control | From PTP to Robot Control
Covered functionality
NC PTP
NC I
CNC
Robotics
Point-to-Pointmovement
Interpolated motion
with 3 axes and
5 additional axes
Complete CNC
functionality
Interpolated motion
for robotic control
interpolated
movement for
up to 32 axes
per channel
various
transformations
gearing
camming
superposition
flying saw
programming
according to DIN 66025
technological features
straightforward
utilisation through
function blocks from
the PLC
TwinCAT 3 | Overview
23.05.2012
26
Engineering (XAE)
TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
27
Engineering (XAE)
C/C++ programming languages
Reusability of already existing C/C++ code
Common use of C/C++ and PLC code
Real-time applications available for all platforms (CE, 7)
Opening up of a completely new world for automation technology
Renowned and well-known programming language
Standardised (C: ISO/IEC 9899 TC3, C++: IEC 14882)
The creation of Automation Device Drivers (ADD) enables you to implement your
own drivers (e.g. for your own fieldbus system or the like)
Beckhoff SDK supports (similar to PLC libraries)
ADS
No t
et a
yMotion
vaila
File I/O ble!
TwinCAT 3 | Overview
23.05.2012
28
Engineering (XAE)
C/C++ programming languages | Integration
TwinCAT 3 | Overview
23.05.2012
29
Engineering (XAE)
TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
30
Engineering (XAE)
Matlab/Simulink
Well-known from science and measurement technology
Large variability of toolboxes (e.g. fuzzy etc.)
Generation, simulation and optimisation of controller structures
Debug interface between Simulink and TwinCAT
Code generation
Design: Simulink
Automatic generation of C code by the Simulink real-time workshop
Compilation with the Visual Studio C compiler
Parameterisation in the TwinCAT System Manager
Download and execution in the TwinCAT 3 runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
31
Engineering (XAE)
Matlab/Simulink | Integration
TwinCAT 3 | Overview
23.05.2012
32
Engineering (XAE)
TwinCAT 3 Standard
TwinCAT 3 Integrated
System Manager
PLC
Motion Control
C/C++ programming
Matlab/Simulink
Integration
C#/ .NET programming
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
33
Engineering (XAE)
C#/.NET programming
HMI/
Windows processes
PLC module
C++ module
Real-time Code
TwinCAT 3 | Overview
23.05.2012
34
Engineering (XAE)
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
35
eXtended Automation
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
36
eXtended Automation
Runtime (XAR) | Modular runtime systems
Debugging
PLC
C++
Module
Task
TcCOM
Task
TcCOM
TcCOM
Call
PLC
Simulink
Module
PLC
CNC
Task
Task
PLC
NC
Call
PLC
PLC
C++
Module
TcCOM
Task
TcCOM
Task
Call
PLC
C
Module
TcCOM
PLC
TcCOM
Task
TcCOM
TcCOM
TC Configuration
TcCOM
TwinCAT Real-time
Kernel
PLC
Simulink
Module
PLC
Safety
TwinCAT 3 Runtime
Fieldbus
TwinCAT 3 | Overview
23.05.2012
37
eXtended Automation
Runtime (XAR) | TwinCAT modules
Must
Description (methods, functions, names
etc.)
StateMachine (Init, PreOp, Op)
TcCom Interface
TwinCAT Module
Module Description
State Machine
ITComObject Interface
Can
Interfaces
Parameter
Interfaces
Pointers
Interfaces
Parameter
Data Areas
Contexts
Data Areas
Categories
ADS Port
TwinCAT 3 | Overview
Data Area
Pointers
23.05.2012
38
eXtended Automation
TwinCAT 3 Multi-core support
TwinCAT 3 | Overview
23.05.2012
39
Runtime (XAR)
TwinCAT 3 Multi-core support
Support for multi-core systems
Assignment of the individual projects to
different cores
PLC, NC, HMI etc. each assigned
to their own core
Scalable basic time for each core
Scalable CPU limit adjustable for each
core
Multi-core CPU
Core 0
Core 1
Core 2
Core 3
Core ...
Windows
Apps
PLC Control
User HMI
PLC Runtime 0
PLC Runtime 1
NC Runtime 1
Windows
Drivers
ADS
ADS
ADS
Task 0 Task 1
ADS
ADS
L2 Shared Cache
System Memory
TwinCAT 3 | Overview
23.05.2012
40
Runtime (XAR)
TwinCAT 3 Multi-core support | Assignment
Activation of the cores
TwinCAT 3 | Overview
23.05.2012
41
Overview of contents
Motivation why
TwinCAT 3
eXtended Automation
(XA) - overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)
Connectivity
TwinCAT 2 Migration
Functions
TwinCAT 3 | Overview
23.05.2012
42
eXtended Automation
Connectivity
TwinCAT 3 | Overview
23.05.2012
43
eXtended Automation
Connectivity | ADS to Communication
(PLC) PC 1
(PLC) PC 2
TwinCAT
TwinCAT
TwinCAT
TwinCAT
Automation
Protocols
Industry
Protocols
IT
Protocols
Web
Server Ils
TwinCAT
Automation
Device
Specification
(ADS)
OPC UA,
Modbus
TCP, Modbus
RTU
3964R/RK512
IEC 61850,
IEC 61400-25,
IEC 60870-510x,
BACnet, FIAS,
Creston
WLAN,
Bluetooth,
TCP, UDP,
RAS,
FTP, VPN,
SNMP, SNTP,
SMS, SMTP
XML, AJAX,
ASP,
DPWS/WSD
Automation
Device
Specification
(ADS)
Acyclic
TCP, UDP, Serial,
Fieldbus
TwinCAT ADS
Router
Cyclic
EtherCAT Automation
Protocol (EAP),
Network variables
TwinCAT 3 | Overview
23.05.2012
44
Overview of contents
Motivation why
TwinCAT 3
eXtended Automation
(XA) - overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)
Connectivity
TwinCAT 2 Migration
Functions
TwinCAT 3 | Overview
23.05.2012
45
eXtended Automation
TwinCAT 2 Migration | Opening old projects
The opening of projects created with TwinCAT 2 results in:
1.) Conversion of old projects to the TwinCAT 3 format
Process can not be undone!
TwinCAT 3 projects can not be saved in the TwinCAT 2 project format!
Conversion of existing TwinCAT 2 projects to the TwinCAT 3 format means:
Extension of the project by new features
Increased reusability of the existing code in new project parts
Use of the same tools for all projects
Conversion of PLC Control and System Manager files
TwinCAT 3 | Overview
23.05.2012
47
Overview of contents
Motivation why
TwinCAT 3
eXtended Automation
(XA) - overview
Architecture (XAA)
Engineering (XAE)
Runtime (XAR)
Connectivity
TwinCAT 2 Migration
Functions
TwinCAT 3 | Overview
23.05.2012
48
eXtended Automation
TwinCAT Functions
The previously familiar TwinCAT supplements also exist in TwinCAT 3
The designation changes to TwinCAT Functions: TFxxxx
TwinCAT 3 | Overview
23.05.2012
49
Overview
Training fr Umsteiger
Thank you very much for your
attention!
01.10.2012
Engineering (XAE)
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
TcCOM
Safety
C++
modules
TcCOM
TcCOM
TcCOM
eXtended
Automation
Runtime (XAR)
PLC
TcCOM
TwinCAT 3
eXtended
Automation (XA)
eXtended
Automation
Engineering (XAE)
TwinCAT 3
Integrated
Visual Studio
2010 Shell
Visual Studio
2010
23.05.2012
TwinCAT 3
Integrated
Visual Studio
2010 Shell
Visual Studio
2010
eXtended
Automation
Runtime (XAR)
TwinCAT 3 | Overview
23.05.2012
eXtended
Automation
Runtime (XAR)
TcCOM
Safety
C++
modules
TcCOM
TcCOM
TcCOM
PLC
TcCOM
EtherCAT
TwinCAT 3 | Overview
23.05.2012
TwinCAT 3
Standard / Integrated
TwinCAT Transport Layer - ADS
TwinCAT 3 Runtime
Real-time Kernel
Simulink
PLC
modules
C++
PLC
modules
PLC
PLC
IO
CNC
PLC
TwinCAT 3 | Overview
23.05.2012
TwinCAT 3
Standard / Integrated
Real-time Kernel
CNC
PLC
Simulink
PLC
modules
C++
PLC
modules
PLC
PLC
IO
TwinCAT 3 Runtime
Config Mode:
to enable communication (programming)
XAE status
PC
taskbar
TwinCAT 3 | Overview
23.05.2012
PC taskbar
Real-time load in %
TwinCAT 3 | Overview
23.05.2012
Establishment of a connection
Practical part
Establishment of a
connection
TwinCAT 3 | Overview
23.05.2012
Establishment of a connection
Requirement: TC3 is successfully installed on the programming computer and the
target computer
Hardware with PC (XAE)
Target system CX with BK1120 Bus Station
01.10.2012
10
Hardware
Example hardware
PC with TwinCAT3 XAE,
CX with EtherCAT
adaptor
TwinCAT3 XAE / XAR
on the same computer
(local)
BK1120 Bus Coupler
2* KL1XX2 2-CHANNEL
DIG IN
2* KL2XX4 4-CHANNEL
DIG OUT
1* KL2531 Stepper
Terminal
01.10.2012
11
01.10.2012
12
01.10.2012
13
01.10.2012
14
Establishment of a connection
To search, first select Local Target System
01.10.2012
15
Establishment of a connection
searches
for TC
controllers
IPC/ CX
Connection
to both
devices
(enter PC
target
system)
01.10.2012
16
Establishment of a connection
Logon information: user name and password for computer.
Training CX 1020
CX training:
Administrator
1
01.10.2012
17
Establishment of a connection
Connection
valid
01.10.2012
18
Establishment of a connection
01.10.2012
19
PC taskbar
01.10.2012
20
01.10.2012
21
Hardware test
Scanning
Freerun Mode
TwinCAT 3 | Overview
22
23.05.2012
Scan Hardware
Check Config
Mode, activate
Config Mode if
necessary
Scan
01.10.2012
23
Scan Hardware
Scan Hardware
01.10.2012
24
Freerun
In Freerun Mode,
I/O can be tested
without PLC program
01.10.2012
25
PLC Program
Practical part
TwinCAT 3 | Overview
26
23.05.2012
01.10.2012
27
01.10.2012
28
01.10.2012
29
01.10.2012
30
Linking
Link
01.10.2012
31
Linking
Link
01.10.2012
32
Linking
Further links
01.10.2012
33
Activate
Activating the
configuration
Wait for Run Mode
01.10.2012
34
Activate
If TwinCAT XAR is not
registered, a 7-day
licence can be created
01.10.2012
35
Login
Logon to PLC project
Login
Start
PLC
PLC
Online
PLC RUN
01.10.2012
36
Online
Monitoring
Global variables online
Write
Value
s
01.10.2012
38
01.10.2012
39
01.10.2012
40
01.10.2012
41
01.10.2012
42
01.10.2012
43
01.10.2012
44
01.10.2012
45
01.10.2012
46
Autostart
Practical part
TwinCAT 3 | Overview
47
23.05.2012
Autostart
Boot project
Enable autostart
Creating a boot project
01.10.2012
48
Autostart
TwinCAT autostart
01.10.2012
49
Autostart
User name and
password for the
control computer
01.10.2012
50
Training fr Umsteiger
Identifier
Indentifier serves to assign individual names to variables, data types,
functions, etc.
The identifier starts with a letter or underscore
followed by numbers, letters and underscore
No distinction is made between upper and lower case
The following are not permitted
special characters (!, , , $, etc.)
spaces
consecutive underscores
umlauts
01.10.2012
Keywords
Keywords are identifiers specified by IEC61131-3. They are thus fixed
components of the syntax and therefore may not be used for other
purposes.
Examples
Standard operators AND, OR, NOT
Standard types BOOL, INT, REAL...
Types TYPE, STRUCT
Block types FUNCTION, FUNCTION_BLOCK, PROGRAM
01.10.2012
01.10.2012
Lower
Upper
BOOL
FALSE
TRUE
Size
Prefix
x
b
BYTE
8 BIT
by
Bitstring
WORD
16 BIT
Bitstring
DWORD
32 BIT
dw
Bitstring
01.10.2012
Detail slides
Overflows
Example: EL3102
Example: KL2531
TwinCAT Training: Programmer
01.10.2012
Lower
Upper
Size
Prefix
TIME_OF_DAY
TOD#0:0:0
TOD#23:59:
59
32 Bit
tod
DATE
D#1970:01:01
D#2106 ???
32 Bit
date
DATE_AND_TIME
DT#1970:01:01:00:00:00
DT#2106
???
32 Bit
dt
TIME
T#0s
T#49d17h2m 32BIT
47s295ms
tim
Detail slides
DT example - reading the system time
DT example - working with standard operators
01.10.2012
Lower
Upper
Size
Prefix
REAL
4 Byte
LREAL
8 Byte
lr
01.10.2012
Description
Example
Size
Prefix
STRING
String in ASCII
code. Standard
length 80
characters.
Maximum length
255. Strings are
zero-terminated
1234ABCDE
80 +1
ABCDE$R$L
ABCDE$0D$0A
Assignment
Result SIZEOF
Result LEN
sVar : STRING;
sVar:=ABC;
81
sVar1 :STRING(1);
sVar := X;
sVar: STRING(255);
sVar:=ABC;
256
01.10.2012
ASCII Code
$0D
CR
$R
$r
CR
$L
$l
Line Feed
$N
$n
New Line
$T
$t
Tab
Detail slides
Example: FIND
Example: string functions LEN, REPLACE
String conversion with Union
01.10.2012
10
Description
Example
Description
Pre
fix
WSTRING
String in Unicode
format
Level 0,Block
0x0400-0x4FFF
Cyrillic
ws
Training, seminar
Level 0
Block 0x00000x007F
Basic Latin
01.10.2012
11
Examples
BOOL
TRUE
2#1
16#1
FALSE
2#0
16#0
WORD,
DWORD
2#1010111111111110
16#AFFE
45054
INT
2#1000000000000001
16#8001
-32768
TIME
t#1h
t#60m
t#3600000ms
t#0.5d
t#12h
t#43200000ms
day
hours
min
sec
ms
ms
REAL
t#30m18s90ms
t#0.505025h
0.3333
3.333e-1
t#1818090ms
01.10.2012
12
Identifier
Data type
Initial value
bStellerUntenLinks:BOOL:=TRUE;
01.10.2012
13
AT
%I
Data type;
%Q*
01.10.2012
14
AT
%I
%Q
%M
Byte
Bit
Type
Byte
Detail slides
Detail - Replace %MB by UNION
TwinCAT Training: Programmer
01.10.2012
15
IX10.6
IX10.5
IX10.4
IX10.3
IX10.2
IX10.1
IX10.0
IB10
IB1
IB0
IW0
IX22.6
IX22.5
IB23
IX22.4
IX22.3
IB22
IX22.2
IX22.1
IB21
IW22
IB20
IW20
ID20
IX22.0
01.10.2012
16
END_VAR
VAR_OUTPUT ..
END_VAR
01.10.2012
17
Implementation
TwinCAT Training: Programmer
01.10.2012
18
Project machine
PROGRAM A
PROGRAM B
VAR
VAR
locVar AT%MB2:WORD;
END_VAR
END_VAR
LD %MB2
01.10.2012
19
Example
name:
Gvl1
LD Var1
LD Gvl1.Var1
01.10.2012
20
01.10.2012
21
Global
Also locally
possible
END_VAR
TwinCAT Training: Programmer
01.10.2012
22
Parent type
Name
Data type
New value
Derivation
Name
Data type
Initial value
Area
Inherit
ance
Initial value
Area
01.10.2012
23
Syntax:
TYPE
<Bezeichner>:<Zuweisungsausdruck>;
END_TYPE
Type
Declaration
01.10.2012
24
01.10.2012
25
01.10.2012
26
01.10.2012
27
01.10.2012
28
01.10.2012
29
Use
Online
01.10.2012
30
Use
Declaration
Online
01.10.2012
31
01.10.2012
32
01.10.2012
33
1-dimensional
2-dimensional
3-dimensional
01.10.2012
34
i:= 9
Feld_1[i+2] := 120;
Feld_1[9];
Feld_2[1,2];
120
01.10.2012
35
CheckBounds := L;
Limited
value
CheckBounds := U;
ELSE
OK case
CheckBounds := I;
END_IF
01.10.2012
36
01.10.2012
37
01.10.2012
38
Checkbounds is compiled-in
in XAR
10
Do not write,
it is called
automatically
(not visible in
the code)
10
9
Can be checked with call build:
TwinCAT Training: Programmer
01.10.2012
39
01.10.2012
40
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
LREAL;
BOOL; (*Pumpe ?*)
01.10.2012
41
TRUE,
Position:=
Positions[55].XPos ,
Velocity:=
Positions[55].FeedrateX
Acceleration:=
Positions[55].AccelerationX,
Deceleration:=
Positions[55].DeccelerationX,
Jerk:=
Positions[55].JerkX,
Direction:=
.........,
Axis:=
.............,
);
TwinCAT Training: Programmer
01.10.2012
42
Block types
In IEC61131-3 there are three types of block covered by the generic
term POU (PROGRAM ORGANISATION UNIT):
Program
Function Block
Function
01.10.2012
43
01.10.2012
44
01.10.2012
45
1,2,3........ VAR_INPUT
Outputs:
precisely 1!, but structure variable possible. The name of
the output is at the same time the name of the function.
Transfer by reference
1,2,3........ VAR_IN_OUT ,
Monitoring: In the online mode of the PLC control only ??? are visible
for the local variables, since this data area is used by all functions in the
cycle and monitoring (debug) takes place only at the cycle limits.
Remedy: program development with breakpoints
Use: algorithms where the result is available after a run. Scaling,
comparison, etc.
01.10.2012
46
Symbol
Binding strength
(expression)
Strongest binding
Function name (parameter list)
EXPT
NOT
*
Same binding strength,
processing from left to right
/
(10/2*5 = 25 )
MOD
+
Same binding strength
<,>,<=,>=
=
<>
AND
XOR
Weakest binding
OR
TwinCAT Training: Programmer
01.10.2012
47
Example
Assignment:=
PosWert := 10;
RETURN
RETURN;
IF
CASE
FOR
WHILE
REPEAT
EXIT
Empty instruction
01.10.2012
48
ST: IF instruction
Is needed to branch in a program, depending on conditions. With the
IF instructions its not possible to jump back in the PLC cycle.
GOTO is also not available
Keywords:
IF
THEN
ELSIF
ELSE
END_IF
01.10.2012
49
ST: IF instruction
IF Condition THEN
Instruction block;
END_IF
No
Condition
Yes
Instruction block
01.10.2012
50
ST: IF instruction
IF a>b THEN
Instruction block A;
ELSE
Instruction block B;
END_IF
Condition
No
Yes
Instruction block A
Instruction block B
01.10.2012
51
ST: IF instruction
IF Condition1 THEN
Instruction block A;
ELSE
IF Condition2 THEN
Instruction block B;
Condition 1
ELSE
No
Yes
IF Condition3 THEN
Condition 2
Instruction block C;
ELSE
Yes
Instruction block D;
END_IF
END_IF
END_IF
Instruction
Instruction
block A
block B
No
Condition 3
No
Yes
Instruction
block C
Instruction
block D
01.10.2012
52
ST: IF instruction
IF Condition1 THEN
Instruction block A;
ELSIF Condition2 THEN
Instruction block B;
ELSIF Condition3 THEN
Instruction block C;
ELSE
Instruction block D;
END_IF
Condition 1
No
Yes
Condition 2
No
Yes
Condition 3
No
Yes
Instruction
block A
Instruction
block B
Instruction
block C
Instruction
block D
01.10.2012
53
ST: IF instruction
What can the BOOLEAN EXPRESSION be?
Conditions:
BOOLEAN variable
Comparison
Function calls
Querying of FB instances
NO FB call!
IF bVar THEN
.
IF a>b THEN
.
IF LEFT(STR:= strVar, SIZE:=7) =
'TwinCAT' THEN
.
IF Ton1.Q THEN
.
IF Ton1(IN:=bVar, PT:=T#1s ) THEN
01.10.2012
54
ST CASE Instruction
CASE Selection criterion OF
1:
Selection criterion = 2
or 4 or 6
Instruction 1
2, 4, 6: Instruction 2
7..10: Instruction 3
Selection
criterion = 1
Selection criterion = 7
or 8 or 9 or 10?
No
Yes
..
No
ELSE
Yes
Default
instructions
No
Yes
END_CASE;
Two identical values
may not be available
for selection in the list.
Instruction 1
Instruction 2
Instruction 3
Default
instructions
01.10.2012
55
CASE State OF
0:
Q0:=TRUE;
IF Transition THEN state := 1; END_IF
1:
Q1:=TRUE;
IF Transition THEN state := 2; END_IF
2:
Step-further condition
(Transition)
Q2:=TRUE;
IF Transition THEN state := 3; END_IF
3:
Q3:=TRUE;
IF Transition THEN state := 0; END_IF
END_CASE
01.10.2012
56
Instructions;(*State=0*)
IF THEN
Instructions
if state = 0
1:
Instructions;(*State=1*)
Instructions
if state = 1
2:
Instructions;(*State=2*)
Instructions
if state = 2
3:
Instructions;(*State=3*)
Instructions
if state = 3
END_CASE
01.10.2012
57
Enum-Typ:
TYPE Schritte :
(INIT:=0, START, AUTOMATIK, ENDE);
END_TYPE
CASE State OF
INIT:
Instructions;(*State=0*)
START:
Instructions;(*State=1*)
AUTOMATIK:
Instructions;(*State=2*)
ENDE:
Instructions;(*State=3*)
END_CASE
01.10.2012
58
CASE State OF
INIT:
Q0:=TRUE;
IF Transition THEN state := START; END_IF
START:
Step-further condition
(Transition)
Q1:=TRUE;
IF Transition THEN state := AUTOMATIK; END_IF
Q3:=TRUE;
IF Transition THEN state := INIT; END_IF
END_CASE
TwinCAT Training: Programmer
01.10.2012
59
VAR CONSTANT
Step1 : INT:=
0;
Step1:
Instructions;(*State=0*)
Step2 : INT:=
1;
Step2:
Instructions;(*State=1*)
Step3 : INT:=
2;
Step3..Step4:
Step4 : INT:=
3;
END_CASE
END_VAR
VAR
State:INT;
END_VAR
01.10.2012
60
1
e.g.: 1ms
2
2ms
3
3ms
Begin of a new
time slice
4
4ms
1
5ms
01.10.2012
61
Expression
Processing
n cycle fix
FOR
SINT/INT/DINT
Instructions
Yes
follow condition
WHILE
BOOL
Instructions
No
follow condition
REPEAT
BOOL
Condition
follows
instructions
No
01.10.2012
62
Start i:=StartValue
Yes
i
>EndValue
No
Instruction block
i: = i + step size
Feld[i]:=i*2;(*Anweisung*)
END_FOR
Cycle n
TwinCAT Training: Programmer
01.10.2012
63
Cycle n
Yes
Boolean
expression
No
Instruction block
i: = i + step size
Cycle n
TwinCAT Training: Programmer
01.10.2012
64
Instruction block
i:= i + step size
i:=0;
REPEAT
Feld[i]:=i*2;(*Anweisung*)
i:=i+1;
UNTIL i>100
No
Boolean
expression
Yes
END_REPEAT
Cycle n
TwinCAT Training: Programmer
01.10.2012
65
ST: FB calls in ST
VAR
TON1:TON;
END_VAR
TON1 (IN:= NOT TON1.Q , PT:=T#1s );
Q0:= TON1.Q;
01.10.2012
66
01.10.2012
67
ST: FC calls in ST
Result:=Scale (x:=Eingang, xug:=0.0, xog:=32767.0, yug:=0.0,yog:=100.0);
(* Gleichwertig:*)
Result:=Scale (Eingang, 0.0, 32767.0, 0.0, 100.0);
(* Gleichwertig:*)
Result:=Scale (
xog:=
x:=
Eingang,
xug:=
0.0,
32767.0,
yug:=
0.0,
yog:=
100.0
);
In case of functions, all inputs must be occupied
TwinCAT Training: Programmer
01.10.2012
68
ST: FC calls in ST
Result := Scale (x:=Eingang, xug:=0.0, xog:=32767.0, yug:=0.0,yog:=100.0);
Result
CALL
Input parameters
(* Gleichwertig:*)
Result:=Scale
(
x:=
Eingang,
xug:=
0.0,
xog:=
32767.0,
yug:=
0.0,
yog:=
100.0
);
01.10.2012
69
Special methods:
FB_Init, FB_Exit, FB_Reinit
TwinCAT 3 | Training | Object-orientated
programming in IEC
70
03.05.2012
01.10.2012
71
Special methods:
FB_Init, FB_Exit, FB_Reinit
TwinCAT Training: Programmer
01.10.2012
72
01.10.2012
73
01.10.2012
74
01.10.2012
75
03.05.2012
01.10.2012
76
Example task
Example: a clock generator FB is to be created
that should be able to do the following:
generate a flashing cycle
generate a PWM signal (e.g. heating)
Parameter
fixed flashing time for flashing cycle
clock output for flashing signal
MaxCycles defines number of PLC cycles 100% duty cycle for PWM
generator
DCPercent; duty cycle in %
Enable: BOOL, enable for PWM signal
Vendor, name of the manufacturer as a string
01.10.2012
77
Standard procedure
All parameters are transferred with VAR_INPUT VAR_OUTPUT
The sub-functions are programmed in the FB and run through with the complete FB
to flashing
cycle
to PWM
generator
to flashing
cycle
to PWM
generator
01.10.2012
78
Standard procedure
This block is to be extended later
clock ratio of the flashing cycle is to be modified
the PWM generator is given a target profile generator (e.g. temperature profile)
Co
py
ex and
ten
d
01.10.2012
79
Alternative
With the new options
Methods
Features
Inheritance
Overwrite
01.10.2012
80
Example
A clock generator FB is to be created
Methods:
m_ClockGenerator generates the flashing cycle
M_Pwm generates a PWM signal (e.g. heating)
Features
p_CycleTime specifies flashing time for flashing cycle
p_MaxCycles defines number of PLC cycles 100% duty cycle
for PWM generator
p_Vendor
queries a string
01.10.2012
81
Example
FB_ClockGenerator
m_ClockGenerator()
m_Pwm()
p_Vendor
p_CycleTime
01.10.2012
82
01.10.2012
83
Example
FB_ClockGenerator
m_ClockGenerator()
m_PwmProfile()
p_Vendor
p_CycleTime
FB_ClockGeneratorEX
m_ClockGenerator() overwrite
m_PwmProfile() (new)
p_Vendor (overwrite)
01.10.2012
84
Extension
Block
see training examples
01.10.2012
85
The function blocks and functions are made available by integrating the
Standard.LIB. This is automatically integrated into the PLC project when
the project is created.
Standard blocks
Function Blocks
Timer
Functions
String Functions
Counter
Memory
Trigger
01.10.2012
86
FBD /CFC
ST
Comments
BOOL
AND
WORD
AND
DWORD
AND
01.10.2012
87
ST
Comments
Arithmetic Operators
Overloading possible,
beware of overflow with
integers.
- * /
Determines integral
remainder of a division
(in this case 4)
01.10.2012
88
Comments
FBD /CFC
ST
StrVarMode := SEL(Mode1, , Mode1Selected );
Example:
If Mode1 = TRUE, StrVarmode
contains Mode1Selected,
otherwise an empty string
01.10.2012
89
FBD /CFC
Selection with
integer variable,
inputs can be
overloaded
ST:
Online:
01.10.2012
90
Appendix: Conversions
Operator
ST
Comments
Time values are resolved
in ms rt1:REAL
iT1:INT
bVar1:BOOL
Rounding up takes place:
0.4 output goes FALSE
>=0.5 output goes TRUE
01.10.2012
91
Appendix: Conversions
FBD /CFC
ST
Comments
Result 20000.0
Implicit conversion also
possible
Conversion to INT with
rounding up/down
Conversion to INT without
rounding up/down
Beware of overflows
(Result is negative)
01.10.2012
92
CLK
R_TRIG
Q
CLK
F_TRIG
Q
ST
CLK
BOOL
Trigger input
BOOL
01.10.2012
93
SET1
SR
RESET1
Q1
SET1
RS
ST
RESET1
Q1
SET1
BOOL
Set
RESET1 BOOL
Reset
Q1
Output
BOOL
01.10.2012
94
IN
Q
ET
ST
IN
PT
TIME
BOOL Output
ET
TIME
01.10.2012
95
IN
PT
ST
IN
PT
TIME
BOOL Output
ET
TIME
ET
01.10.2012
96
IN
Q
ST
IN
PT
TIME
BOOL Output
ET
TIME
ET
01.10.2012
97
CU
BOOL
RESET BOOL
Counter reset
PV
UINT
Preset Value
BOOL
CV
WORD
01.10.2012
98
CD
BOOL
LOAD
BOOL
PV
UINT
Preset Value
BOOL
CV
UINT
01.10.2012
99
LOAD
CD
CU
RESET
CV
ST
CV=PV
QD
QU
CU
BOOL
CV
UINT
CD
BOOL
RESET
BOOL
Reset
LOAD
BOOL
PV
UINT
Preset Value
QU
BOOL
QD
BOOL
01.10.2012
100
ResultOnline
ST
STR1
STRING
First string
STR2
STRING
01.10.2012
101
ResultOnline
ST
STR1
STRING
STR2
STRING
String to be found
01.10.2012
102
Detail : Overflows
Beware of overflows with numerical operations
0000h
INT 0
FFFFh
INT -1
8000h
7FFFh
INT -32768
INT 32767
PLC memory
INT value
TwinCAT Training: Programmer
01.10.2012
103
Value
Decimal
32767
16383
0
-16383
-32768
Hexadecimal
0x7FFF
0x3FFF
0x0000
0xC001
0x8000
Status word from (EL3102-0000-0016) with older models only SW.0 - SW.7 1 byte
Bit
SW.15
SW.14
Name
TxPDO
Toggle
Bit
Name
SW.13
SW.12
SW.11
SW.10
SW.9
SW.8
SW.7
SW.6
SW.5
SW.4
SW.3
SW.2
SW.1
SW.0
ERROR
Limit 2
Overrange
Underrange
Limit 1
With older
models
01.10.2012
104
Velocity
Bit
15
14
Cont. VZ
13
12
11
10
Velocity value
Controlbyte (Ctrl)
Bit
Name
CB.7
CB.6
RegAccess Reset
CB.5
CB.4
CB.3
CB.2
CB.1
CB.0
AutoStop
AutoStart
Reduced
Current
Start
PLC-Stop
Enable
CW.13
CW.12
Reduced
Current
(drive)
CW.4
enLatch
FallEdge
CW.11
CW.10
CW.9
CW.8
Reduced
Current
SetPos
disMixed
Decay
GetEncoder
Position
CW.3
enLatch
RiseEdge
CW.2
enLatch
Input2
CW.1
enLatch
Input1
CW.0
Bit
Name
CW.15
CW.14
CW.7
CW.6
CW.5
GetPosition ToggleLatch GetLatch
Error
Data
Data
enLatchC
Position
Bit
15
14
13
12
11
10
Statusbyte (Status)
Bit
Name
SB.7
SB.6
RegAccess Error
SB.5
SB.4
SB.3
Warning
Idle
LoadAngle
SB.2
SB.1
SB.0
Ready
SW.7
SW.6
SW.5
SW.4
SW.3
SW.2
SW.1
SW.0
Encoder
Disabled
LatchData
Toggled
LatchData
InByte2,3
LatchValid
Target
Reached
SetPos
Ready
Input E2
Input E1
Bit
Name
SW.15
SW.10
OpenLoad
Br A
SW.9
Under
Voltage
SW.8
Over
Temperature
SW.14
NoControl
Config Error
Power
SW.13
SW.12
SW.11
OverCurrent OverCurrent OpenLoad
Br B
Br A
Br B
Summary
Description
Typ
INT
BYTE
WORD
UINT
BYTE
WORD
01.10.2012
106
01.10.2012
107
01.10.2012
108
Pos 1
Pos
10
Pos
11
10
01.10.2012
109
Pos 1
Pos 5
sVal
sResult
.1
-5
-5
12345
12345
01.10.2012
110
A
B
C
D
E
$R
$N
TwinCAT Training: Programmer
01.10.2012
111
Possible
Better, since user
does not have to
manage addresses
01.10.2012
112
System
Query the set PLC cycle time
Creation of a variable of the type PlcTaskSystemInfo;
Task no.
01.10.2012
113
Connectivity
01.10.2012
ADS (General)
Definition
NEU
ADS General
Definition: ADS = Automation Device Specification
modular ADS devices
e.g. PLC (each runtime system), NC, etc.
message exchange by ADS via the message router
01.10.2012
Router
unambiguously
identifiable by:
AdsAmsServerNetID
01.10.2012
01.10.2012
851
852
853
801
811
821
831
NC
500
(501)
IP Address
172.16.17.108
IO server
TwinCAT device
IO Mapper
Beckhoff Training: TwinCAT ADS
01.10.2012
01.10.2012
01.10.2012
Client-server relationship
1.) Confirmed services
2.) Unconfirmed services
ADS Client
ADS Server
Request
(Anforderung)
Indication
(Aufforderung)
Confirmation
(Besttigung)
Response
(Antwort)
01.10.2012
PLC I
Uses ADS FB
Request
Indication
(FB call)
Confirmation
Response
01.10.2012
10
%M
Memory range
%I
Input range
%Q
Output range
By name
PLC variable
Global
Example: .Tempsetpoint
Example: MAIN.TON1.ET
01.10.2012
11
Asynchronous:
Notification:
01.10.2012
12
01.10.2012
13
IDXGRP
IDXOFFS
%MB
0x4020
MB address
Example
IDXGRP 0x4020
IDXOFFS 100
%MX
%IB
0x4021
0xF020
MB address * 8 +
bit address
IDXGRP 0x4021
IB address
IDXGRP 0xF020
IDXOFFS 81
IDXOFFS 0
%IX
%QB
0xF021
0xF030
IB address * 8 +
bit address
IDXGRP 0xF021
QB address
IDXGRP 0xF030
IDXOFFS 41
ISXOFF 100
%QX
0XF031
QB address * 8 +
bit address
IDXGRP 0xF011
IDXOFFS 167
01.10.2012
14
Action
IDXGRP
IDXOFFS
Example
Create
Handle
0xF003
Read / Write
by
handle
0xF005
Handle
Delete
Handle
0xF006
WRITE: VarName
Read: Handle
01.10.2012
15
PLC examples
01.10.2012
16
Access by address
Example: PLC 1 sends to PLC2 2; access by address
PLC 1
01.10.2012
17
Access by address
Variable access
PLC 1
PORT PLC2
NETID local
01.10.2012
18
Access by address
Notes
01.10.2012
19
PLC 1
01.10.2012
20
NetiD local
PORT PLC2
Create Handle
01.10.2012
21
01.10.2012
22
01.10.2012
23
01.10.2012
24
INDEXGROUP
0x4020
INDEXGROUP
0x4021
INDEXGROUP 0x4021
INDEXOFFSET 10*8 +1 = 81
INDEXGROUP 0x4020
INDEXOFFSET 12
01.10.2012
25
PLC
C# Application
VAR_GLOBAL
END_VAR
01.10.2012
26
01.10.2012
27
Result
01.10.2012
28
%MB ACCES
lblMW12.Text = TcClient.ReadAny
(0x4020,
12,
typeof(short)).ToString();
Result
01.10.2012
29
TcClient.Dispose();
Enables the resources
01.10.2012
30
01.10.2012
31
Basic procedure:
Insert TcClient
Insert Namespace
Instance object variable for TcClient
Create handle variables
Request handle on PLC variable(s)
Write & read by handle
Delete handle(s)
Release resources (dispose)
01.10.2012
32
PLC
C# Application
VAR_GLOBAL
BIT0 :BOOL;
BIT1 :BOOL;
BIT2 :BOOL;
BIT3 :BOOL;
iVar0 :INT;
diVar0 :DINT;
END_VAR
01.10.2012
33
hBit0 = TcClient.CreateVariableHandle(".BIT0");
Request handle
Name of the PLC variable. Do
not forget the dot with global
variables
(. BIT0)
01.10.2012
34
Type of variable
Handle on the variable
TcClient.WriteAny(hiVar0, (short)tbariVar0.Value);
Value to the PLC
PLC INT is in C# Short
Handle
Beckhoff Training: TwinCAT ADS
01.10.2012
35
TcClient.Dispose();
Release resources
Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
Beckhoff Training: TwinCAT ADS
01.10.2012
36
01.10.2012
37
General procedure:
Register notification on each variable (handle)
Create event handler
Evaluate received data in the Notification Event
Delete notifications
Release resources
01.10.2012
38
PLC
VAR_GLOBAL
AxisName:STRING(19);
Ready:
Error:
actVelocity:
actPosition: LREAL;
setVelocity:
setPosition: LREAL;
Lagdistance: LREAL;
END_VAR
C# Application
BOOL;
BOOL;
LREAL;
LREAL;
01.10.2012
39
Instance TcClient
TcClient.AdsNotificationEx += new
AdsNotificationExEventHandler(TcClient_AdsNotificationEx);
Event
Name of the event function
01.10.2012
40
01.10.2012
41
Update method
Filter time
User object or zero
Data type of the read
variable
01.10.2012
42
01.10.2012
43
01.10.2012
44
PLC
VAR_GLOBAL
VisuPositions: ARRAY [0..19]
OF LREAL;
C# Application
double[] PlcArray;
END_VAR
01.10.2012
45
46
01.10.2012
47
01.10.2012
48
C# Application
double[] PlcArray;
END_VAR
01.10.2012
49
01.10.2012
50
01.10.2012
51
52
01.10.2012
53
01.10.2012
54
C# Application
ListView
01.10.2012
55
01.10.2012
56
01.10.2012
57
Function to
read/write
Indexgroup +
Axid
Indexoffset
Acces Read
only
58
BinRead.ReadInt32()
Example for 32-bit INT
01.10.2012
59
Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
01.10.2012
60
01.10.2012
61
01.10.2012
62
C# Application
private struct Axisstruct
{
AxisName:STRING(19);
Ready: BOOL;
Error: BOOL;
actVelocity: LREAL;
actPosition: LREAL;
setVelocity: LREAL;
setPosition: LREAL;
Lagdistance:LREAL;
END_STRUCT
END_TYPE
}
VAR_GLOBAL
Axistate1 :strAxisstate ;
END_VAR
01.10.2012
63
01.10.2012
64
AdsBinaryReader to
evaluate Stream
e.DataStream.Position = 0;
AdsBinaryReader AdsBinReader = new AdsBinaryReader(e.DataStream);
Axistruct1.AxisName = AdsBinReader.ReadPlcString(20);
Axistruct1.Ready = AdsBinReader.ReadBoolean();
Read Data from stream.
Position increments
automaticly
01.10.2012
65
TcClient.DeleteDeviceNotification(hnAxisstruct1);
Delete Notification only one handle per struct
TcClient.Dispose();
Release resources
Details: Open the templates (PLC/C#) distributed in the course and follow
the instructions
01.10.2012
66
01.10.2012
67