TC Quick Start 28
TC Quick Start 28
Beckhoff TwinCAT
The Windows Control and Automation Technology
Contents
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
System requirements
486 processor or higher
To operate TwinCAT, you need a PC with a 486 type processor or higher. The computer must also have a ma-
thematical coprocessor. The coprocessor will be integrated in a 486DX, DX2 or DX4 processor. In the case of
486SX or SX2 processors, the computer can be upgraded with an overdrive processor, which then contains a
coprocessor.
At least 16 MB RAM
The computer must contain at least 16 MB of RAM. Memory requirement increases if applications are large or if
additional software is run on the computer in parallel with TwinCAT
Demokit:
The required Hardware for the sample program is contained in the Beckhoff Demokit Lightbus.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
2. Installation
Starting the installation program
Start the SETUP.EXE program on the CD. To do this, open the Explorer, change to the CD ROM and double
click the SETUP.EXE program.
The following dialog box opens. Click 'Next ' to continue.
Exit programs
The installation program recommends, to exit all Windows programs, before running this Setup program.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
License Agreement
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
8
TwinCAT PLC
In TwinCAT PLC includes the IEC61131-3 Software Development kit.
TwinCAT NC PTP
Further to PLC this module contains the NC/CNC functionality to control the PTP-Axis .
TwinCAT NC I
Further to PLC this module contains the NC functionality interpolates drives in 3D.
Installation type
Select TwinCAT as 30-Day-Test-Version, Register an installation or a request for further Information. If you
have no Registration Number 'Install the 30 day Version' and register during the 30 day period.
Registration key
If you decide to register TwinCAT, you must now enter the Key. You must obtain this register key directly from
Beckhoff Industrie Elektronik. The Telephone number is in the dialog box. In order to compute the registration
number, the System ID must be given. The System ID is shown in the dialog box.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
Component selection
By Default, not all the components in TwinCAT are installed.
Component Description
TwinCAT IO Allows the direct access to IO via a DLL. Can be installed with TwinCAT PLC or Twin-
CAT NC PTP.
TwinCAT Scope Program for the graphical visualisation of the TwinCAT process variables.
View
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
10
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
11
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
12
End of installation
New Program icons
After the installation the Windows NT/2000 Startup menu will contain a new folder containing five program sym-
bols and two further program folders.
StartUp
TwinCAT automatically starts all programs in the Startup folder if activated via the Auto-Boot Function. This is to
ensure that user programs that use process values from TwinCAT are started after TwinCAT.
TwinCAT System-Manager
With the help of this program, assign physical I/O adresses (Fieldbus) to the logical process variables (PLC
program). This assignment is called mapping. The realtime properties are defined here.
This is the software development kit for IEC61131-3. The PLCPrograms are written and tested here.
Apart from the visible programs, there are also hidden tasks and drivers that run in the background. The Twin-
CAT System Control administrates these programs.
With the help of the TwinCAT Scope View process values can be displayed graphical in real time. The dynamic
Axis values can be thoroughly examined.
The color indicates the general operating state of the system. It can have one of the states 'started' (green),
'starting' (yellow)' and 'stopped' (red). If you click the icon, a pop up menu opens in which you can define further
system settings. Within the scope of these instructions, you can accept the default setting. The TwinCAT server
can be stopped and started in this menu.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
13
The TwinCAT Information System is a constantly growing reference source for TwinCAT products. It contains
technical information, manuals, example code, the TwinCAT Knowledge Base and much more. The hierarchical
arrangement of the documents makes it easy to find the required information.
Full version:
If you installed TwinCAT of the Beckhoff product CD, now the entire TwinCAT information system is installed on
your computer.
Base Version
If you loaded yourselves the installation from TwinCAT from the Internet, only a basic version of the TwinCAT
information system on your computer is installed. In order to receive a complete version (size 13 MB), you have
several possibilities:
You will find it
· on our FTP-Server
· ftp://ftp.beckhoff.com/Software/TwinCAT/InfoSystem/1033/TcInfoSys.exe
· http://www.beckhoff.com
You can infer the statements for the installation also from the start page, which you can open with the start me-
nu, as represented above.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
14
IEC 61131-3
TwinCAT PLC allows the PLC programmer to obtain easy access to the powerful language resources of IEC
61131-3. The following features were implemented during the course of TwinCAT PLC development:
Function blocks
TwinCAT PLC supports different programming languages: instruction list (IL), structured text (ST), sequential
function chart (SFC), function block diagram (FBD) and ladder diagram (LD).
Reusability
Reuseability of existing PLC program blocks
Standardized interfaces
A link to other programs and computers, even through a network, is possible thanks to standardized open inter-
faces (DDE, OCX, DLL, etc). By way of OLE, for example, you can realize a data transfer to MS Excel without
the need for programming effort and you can process the data further in that application
Heterogeneous environment
Thanks to the use of system-independent and widespread network protocols, it is possible to integrate Twin-
CAT into a heterogeneous network environment. For example, an Oracle database running under UNIX can
exchange data with TwinCAT via TCP/IP and can process this data further in a PDA or PPS system or can
specify parameters within TwinCAT PLC in order to influence the production process.
SCADA systems
Some manufacturers of SCADA systems (Fix32, InTouch, Citect, Genesis, Wizcon, etc) offer direct driver sup-
port for linking to TwinCAT
Remote access
Central programming of distributed control systems through a network (including ISDN) is possible thanks to the
fact that the programming and run time environments are separate.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
15
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
16
SFC programs essentially consist of steps, transitions and their links. Each step is assigned a set of com-
mands. These commands are executed when the step is active. A transition must be fulfilled to ensure that the
next step is executed. The steps and the transitions can be formulated in any chosen language.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
17
Realtime Configuration
Realtime configurations and creation of user defined tasks.
PLC Configuration
Under this entry, all PLC projects that are running on the local system are listed (currently up to four projects).
Cam Configuration
Electronical Cam Server and its configuration.
I/O Configuration
Corresponding field bus interface cards are necessary to link the control to the process level. Which cards are
used must be defined under this entry.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
18
Data backup
TwinCAT Scope View permits data to be saved in a number of data formats, such as in an Excel table.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
19
6. Sample Program
Sample Maschine.pro
Creation of applications using TwinCAT will be explained with reference to a sample program. This program
represents a machine tool for any chosen workpieces. After you have installed TwinCAT, you will find it in the
'\TwinCAT\Samples\First Steps' directory. It has the name 'Maschine.pro'.
Sketch:
Description
1) The conveyor belt is moved by 25 steps.
2.) The drill is moved down for 2 sec.
3.) The drill is moved up for 2 sec.
4.) Begin at step 1 again.
Start TwinCAT:
Before you are able to execute the program, you must activate the TwinCAT real time server.
To do this, click on the TwinCAT real time server icon and activate the "Start" command from the 'System' me-
nu. The color of the icon changes through yellow to green, which means that Twin-CAT's real time kernel is
active.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
20
Open Projekt:
A PLC project is stored in a file on the hard disk or on a diskette that bears the name of the project. To open a
project, select the 'File' menu item and then the 'Open' command.
Select directory:
Switch to the directory specified above by clicking the symbol shown on the left in the dialog box. Double click
the 'Samples' entry. Then proceed in exactly the same way with the 'First steps' entry.
Select project:
Select the 'Maschine.pro' project by clicking the entry in the dialog box with the mouse and by then executing
the 'Open' command.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
21
The dialog window divides into three individual windows, it contains the object list, the variable declaration and
the program representation.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
22
Object list:
Variable declaration:
A PLC program stores its data in variables. Variables are comparable to flag words or data words. Before a
variable can be used, it must be declared, i.e. its affiliation to a specific data type (e.g. BYTE or REAL) must be
made known. Declaration also involves defining specific at-tributes such as battery buffering, initial values or
affiliation to physical addresses. If a variable is not needed in the input or output image, i.e. only within the PLC
program, the PLC programmer need not worry about the stor-age location of the data. This is taken care of by
TwinCAT. This avoids unintentional overlapping of flag words/data words as was possible in previous systems
(side effects). As in the case of variables, function blocks also have to be declared (instance). In the example,
one instance each (drive, down and up) of the three functions 'DriveType', 'DownType' and 'UpType' are crea-
ted. After instancing, the instances can be used and can be activated.
Program representation:
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
23
The actual PLC program is entered and represented in this area of TwinCAT PLC control.
After installation of TwinCAT, only one run time system is released and so only the first run time system (Run
Time 1) is displayed in this dialog. Select OK to confirm the selection.
Logging in:
You have now loaded the PLC program in TwinCAT PLC control and you are able to execute it. Make sure the
TwinCAT real time server is active. This is recognizable by the fact that the TwinCAT real time server icon is
displayed in green on the bottom right of the screen. Be-fore you start a PLC program, you must link TwinCAT
PLC control to the run time system, i.e. you must 'log in' with the control system. Execute the 'Log in' command
in the 'Online' menu. As there is still no PLC program in the run time system, you get the message: No program
on the controller! Rebuild All? Acknowledge the question with ' OK'.
You start the PLC program in the TwinCAT real time server by selecting the 'Start' command from the 'Online'
menu. The word "RUN" displayed in the status line darkens. You should also see that individual steps within the
sequential function chart are temporarily displayed in blue.
A step shown in blue is currently being executed, i.e. it is the active step.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
24
Besides the variables, the 'timerUp', 'timerDown' and 'devTimer' function blocks are also displayed there. A
lozenge is visible before the function names. When you double click the lozenge, a tree-like display opens in
which all variables of the function are displayed.
You have now loaded a PLC program into TwinCAT PLC control (IEC 61131-3 programming environment) and
you have executed it on the TwinCAT PLC server (run time system). Now end the PLC program. To do this,
select the 'Stop' command in the 'Online' menu.
Logging out:
In the next sections, we will add to the PLC program. To do this, you must log out of the TwinCAT PLC server.
To do this, execute the 'Log out' command in the 'Online' menu.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
25
Viewing transitions:
The 'TRUE' transition is constantly fulfilled because the 'TRUE' key word is a system-wide constant and is per-
manently fulfilled. The 'En-gine' step is executed unconditionally after the 'INIT' step. TimerUp.Q means that the
variable Q in the Up function must be TRUE (or also 1) for this transition to be fulfilled. 'End' is a transition that
contains further program text. When you double click the transition, a further window opens in which the cor-
responding program text is displayed.
In the 'End' transition, a comparison is made as to whether the 25 steps of the motor have already been rea-
ched. If this is the case, the program changes in the next cycle from the 'engine' step to the 'drill' step.
If a step or a transition contains further program text, this is indicated by a small black triangle.
When you select 'OK', the 'switch' variable is added to the variable list of MAIN. If this dialog box not opens,
your auto declare is deactivated. (You can activate it by selecting autodeclaration under 'Options' 'Editor' in the
menu 'Project'. ) Open 'Auto declare' in the menu 'Edit'.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
26
devSpeed := T#10ms;
ELSE
devSpeed := T#25ms;
END_IF
The window must then have the following contents:
If the 'switch' variable is set, the 'devSpeed' variable is set to 25 ms, or otherwise to 10 ms. The result of this is
that the pulse and pause duration of the clock pulse generator in the following program lines either amount to
25 ms or 10 ms.
Save the program by selecting the 'Save ' command in the 'File' menu.
You will find more information about TwinCAT PLC Control in the documentation on TwinCAT PLC Control in
the TwinCAT Information System.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
27
Insert channel:
In order to display the individual signals it is necessary to create the associated channels.
To do this, click with the right mouse button on 'Scope View 1', choose 'Add channel', and confirm with 'OK'.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
28
The following tabs then appear, with which the variables whose values are to be recorded are described.
Assign channel:
Assign the signal .ENGINE to Channel 1 by clicking on 'Change' again, and confirm this action with 'OK'.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
29
Settings
The tab then shows the following settings:
Renaming a channel:
A slow double click on 'Channel1' allows it to be renamed to ENGINE.
When you have created and renamed the four channels, save the Scope View via the 'File' menu, selecting
'Save as' and giving Maschine.scp as the name.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
30
In order to be able to distinguish the various curves from one another, each channel can be given a different
colour, form or axis. This is done with the aid of the Style or Display tabs.
Start recording:
Maschine.pro
The sample program then looks like this:
You will find more information about TwinCAT Scope View in the documentation on TwinCAT Scope View in
the TwinCAT Information System.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
31
Note:
It´s neccessary to have the required hardware. The Demokit for the Lightbus contains the PC interface card for
the II/O-Lightbus (FC2001), the bus Coupler BK 2000, Bus Terminals, 2 fibre optic and some documentation.
Without hardware go to the next chapter Visual Basic Link .
Variable declaration:
The storage locations (addresses) of variables are managed internally by the system. The programmer does
not need to bother about memory management. The PLC programs operate with symbolic variable names, thus
preventing the occurrence of side effects (overlaps) when using variables. To access the input/output level, it is
necessary for the programmer to be able to assign a fixed address to individual variables. This is achieved by
means of the key word 'AT', which must always be specified when declaring a variable. The key word 'AT' is
followed by several parameters which provide information about the data location (input/output or flag area) and
the width of the data (BIT, BYTE, WORD or DWORD). The variable declaration for the above example has the
following structure:
VAR_GLOBAL
engine AT %QX0.0: BOOL;
deviceUp AT %QX0.1: BOOL;
deviceDown AT %QX0.2: BOOL;
timerUp: TON;
timerDown: TON;
steps: BYTE;
count: UINT := 0;
devSpeed: TIME := t#10ms;
devTimer: TP;
switch: BOOL;
END_VAR
Where:
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
32
Note:
This example is exactly appropriate for the contents of the Beckhoff Lightbus demokit (TC9910-B200-0100).
The hardware is however exchangeable. In this case, the configuration of the I/O devices has to be changed
Connect the bus coupler to the PC interface card and power the bus coupler with 24 V DC.
Hardware Documentation
Further information about the hardware connection contains the hardware documentation of the demokit.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
33
The system configuration is shown as a tree structure on the left side of the System Manager. It consists of the
following four main points:
Configuration Meaning
Realtime Set the Real Time Parameters
PLC All PLC Projects that are required to be configured
Cam Add the cam server
I/O In order to link the controller to the process level, the system needs interfaces. This entry
offers a list of all interfaces.
PLC Configuration:
The individual PLC projects must be made known to the System Manager so that TwinCAT can access the
variables of the PLC programs. To do this, press the right mouse button while the mouse pointer is over 'PLC
configuration'
A context menu opens, in which you must select the 'Append IEC project…' entry.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
34
A further point has been added under 'PLC configuration' which bears the name of the PLC project.
The + and the - symbols indicate whether the entry contains a further subpoints. By clicking these symbols, you
open or close the entries below them. The following structure appears if you open the tree as far as possible:
I/O Configuration:
Once the PLC project has been added to the PLC configuration, and thus all variables that are in the process
image are known, it is necessary to specify the I/O configuration. Select the 'I/O devices' entry with the right
mouse button. A context menu opens, in which you must select the 'Add device' entry.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
35
On the right hand side, a dialog box now opens in which you can specify the configuration of the interface card.
One important setting under the 'FC2001' slider, for example, is the I/O address of the lightbus card. You can
use the specified entries if you have not made any changes to the default settings of the card.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
36
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
37
End of configuration:
The configuration then has the following breakdown:
It goes without saying that you can rename the standard designations (device 1, box 1, terminal 1 etc.) To do
this, slowly double click the corresponding name and enter the new designation.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
38
To do this, mark the terminal you wish to configure. In the case of terminal 1 (four digital outputs), a dialog box
containing the 'General' and 'Variables' sliders opens on the right. Select the 'Variables' tab.
Obove you see a list of the two output channels, but they are still all free. To configure channel 1, select the
corresponding button ('channel 1…'). The following dialog box opens:
All output variables are now listed in this dialog box. Select the first variable (engine) and confirm your entry by
clicking 'OK'. Proceed analogously with the second output variable.
The first bus terminal is attached:
Assigning variables:
Terminal 2 PLC variables Meaning
Channel1(=output 1) engine Stepper motor control
Channel2 (=output 2) device.Up Drill up control
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
39
You should save the configuration at this point to make sure you can access it later on. To do this, run the 'Sa-
ve as…' command from the 'File' menu.
Mapping Variables:
You have now configured the complete system for the above example pro-gram. You must now create the allo-
cation. To do this, go to the 'Create allocation' command in the 'Actions' menu. Under the 'Allocations' tree
entry, you now see 'Standard device 1(FC2001)'. Click this entry. The following window opens:
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
40
In the dialog box, you can define whether the data flow from A to B or from B to A is to be displayed. In this
case, Image A corresponds to the process image of the PLC variables, i.e. the input/output variables. Image B
corresponds to the process image of the I/O devices, in this case of the bus coupler BK2000. Each variable or
bus terminal is color highlighted in the process image. If you stop on one of these areas with the mouse, a small
display box appears in which the precise designation is shown.
As the last step, you must save the configuration to Windows NT registry because the information stored there
is evaluated when you start Twin-CAT. Run the 'Save in registry…' command from the 'Actions' menu. If an
older configuration is already stored there, a safety prompt will appear, which you must confirm.
Restarting TwinCAT:
You must restart the system so that TwinCAT will accept the change.
The individual PLC variables are now output on the bus terminal KL 2032. The Bus Terminals indicate their
signal state by means of light emitting diodes.
You will find more information about TwinCAT System Manager in the documentation on TwinCAT System
Manager in the TwinCAT Information System.
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
41
Access methods:
AdsOCX contains various methods for reading the values out of other ADS devices. The decision as to which
method to use depends on the environment in which the program is to be run. You will find further notes and
detailed references to the individual functions in the special AdsOCX instructions. Only a brief overview of the
individual access methods will be given here:
Access Meaning
connect As soon as communication between a PLC variable and a Visual Basic variable is needed, a
connection between these two variables is established by activation of a method. During the
further course of the program, TwinCAT adapts the Visual Basic variable to the PLC variable.
This type of data exchange can also be used so as to activate an event function (event-
controlled data transfer) in the event of a change in a PLC variable in the Visual Basic pro-
gram.
synchronous After activation of a read/write method, execution of the Visual Basic program is interrupted
until the requested data has arrived. The Program can then continue working with the new
data.
asynchronous When using asynchronous access, execution of the Visual Basic program is not interrupted
and instead, execution of the next command is continued automatically. Once the requested
data arrives in AdsOCX, an event function is triggered in the Visual Basic program in which
the value is passed on as the parameter
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
42
Sample program
Starting TwinCAT and the PLC program:
TwinCAT and the PLC program must be active before you can start the Visual Basic program.
In the left area, you see the two outputs, which are also output to the bus terminals. The variable that counts
the workpieces is shown on the bottom left. You can modify the cycle speed of the motor in the 'speed' box. The
'position' display corresponds to the number of cycles that are output to the output 1.
Programtext:
Option Explicit
DimdeviceUp As Boolean
Dim deviceDown As Boolean
Dim steps As Integer
Dim counter As Long
Dim hDeviceUp As Long
Dim hDeviceDown As Long
Dim hSteps As Long
Dim hSwitch As Long
Dim hCounter As Long
'-----------------------------------------------------
'Is activated first when the program is started
'-----------------------------------------------------
Private Sub Form_Load()
'Sprachabhängige Wörter aus Resource-Datei laden
'load language dependent words from the resource-file
lblMachine.Caption =
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
43
LoadResString(0 + GetLanguageId)
lplDeviceUp.Caption = LoadResString(1 +GetLanguageId)
lplDeviceDown.Caption = LoadResString(2 + GetLanguageId)
lblCountLabel.Caption = LoadResString(3 + GetLanguageId)
lplSteps.Caption =LoadResString(4 + GetLanguageId)
fraSpeed.Caption = LoadResString(5 +GetLanguageId)
optSpeedFast.Caption = LoadResString(6 + GetLanguageId)
optSpeedSlow.Caption = LoadResString(7 + GetLanguageId)
'Connect PLC variables with VB variables
Call AdsOcx1.AdsReadIntegerVarConnect(".steps", 2&, 4, 55, steps)
Call AdsOcx1.AdsReadBoolVarConnect(".deviceUp", 2&, 4, 55, deviceUp)
Call AdsOcx1.AdsReadBoolVarConnect(".deviceDown", 2&, 4, 55, deviceDown)
Call AdsOcx1.AdsReadLongVarConnect(".count", 4&, 4, 55, counter)
'Determine handle of the variables
Call AdsOcx1.AdsCreateVarHandle(".steps", hSteps)
Call AdsOcx1.AdsCreateVarHandle(".deviceUp", hDeviceUp)
Call AdsOcx1.AdsCreateVarHandle(".deviceDown", hDeviceDown)
Call AdsOcx1.AdsCreateVarHandle(".count", hCounter)
Call AdsOcx1.AdsCreateVarHandle(".switch", hSwitch)
End Sub
'------------------------------------------
'is activated when ending the program
'------------------------------------------
Private Sub Form_Unload(Cancel As Integer)
'Visual Basic-Variablen von SPS-Variablen trennen
'Separate Visual Basic variables from PLC variables
Call AdsOcx1.AdsReadIntegerDisconnect(steps)
Call AdsOcx1.AdsReadBoolDisconnect(deviceUp)
Call AdsOcx1.AdsReadBoolDisconnect(deviceDown)
Call AdsOcx1.AdsReadLongDisconnect(counter)
'Release handle of the variables
Call AdsOcx1.AdsDeleteVarHandle(hSteps)
Call AdsOcx1.AdsDeleteVarHandle(hDeviceUp)
Call AdsOcx1.AdsDeleteVarHandle(hDeviceDown)
Call AdsOcx1.AdsDeleteVarHandle(hCounter)
Call AdsOcx1.AdsDeleteVarHandle(hSwitch)
End Sub
'------------------------------------------------------
'is activated when the 'fast' field is marked
'------------------------------------------------------
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
44
Operating principle:
In Form1_Load() the language dependent text are loaded as resources.The Text will displayed according to the
preselected language in Windows NT. The Method ‚AdsReadVarConnect' connects the appropiate VB variables
to the PLC System. The parameter of the methods are:
Parameter Meaning
adsVarName Name of the PLC variable
cbLenght Length of the data in bytes
TWINCAT
Eiserstraße 5 / D-33415 Verl / Telefon 05246/963-0 / Telefax 05246/963-149
45
Parameter Meaning
hVar Handle of the PLC variable
cbLenght Length of the data in bytes
pData Visual Basic variable, which contains the data
When a form is closed, all variables that are no longer needed should be separately from the PLC variables.
This is done in the Form1_Unload() function.
TWINCAT