Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CONTENTS
1 INTRODUCTION 3
2 CPLCHANDLER CLASS 4
2.1 Constructor and Configuration of the PLCHandler 4
2.2 Destructor (and connection termination) 5
2.3 Connection establishment 5
2.4 Disconnection 6
2.5 Browsing all variables in the PLC 6
2.6 Getting a variables' description 7
2.7 Cyclic Update of Variables 7
2.7.1 Creating a cyclic list 7
2.7.2 Deleting a cyclic list 7
2.7.3 Reading the values of a cyclic list 8
2.8 Synchronous reading of variables 8
2.9 Synchronous writing of variables 8
2.10 General data transfer 9
2.11 Reading the directory structure on the PLC 9
2.12 Protected method for sending and receiving any services to/from the PLC 9
1 Introduction
The PLCHandler is a C++-class which provides at a comfortable level services for the communication
between a client (e.g. visualization) and a 3S Automation-Alliance compliant PLC (controller).
The following features and services are available:
Establishing and terminating the communication with the PLC
Reading all variables on the PLC
Cyclic reading of variables' values from the PLC
Synchronous reading of variables' values from the PLC
Synchronous writing of variables' values to the PLC
Possibility of instancing for the purpose of a simultaneous communication with several PLCs
Automatic reconnecting with the PLC after an break of the connection
Automatic restart after a program download from CoDeSys to the PLC
Data transfer to and from PLC
Thus the PLCHandler can be used as a basic component for OPC Servers or visualizations.
The communication to the PLC can be done via the following communication channels (named
"interfaces" in the following):
1. Simulation: The symbolic information of the PLC is read directly from SDB file 1 . Provided this
way all variables can be written to and read from the PLC like it is possible in a connection.
2. ARTI: The ARTI-Interface already has been ported to various platforms (Windows NT,
Windows CE, VxWorks, Linux) and serves as a communication layer concerning the PLC.
The ARTI only supports communication via TCPIP and serial interface.
3. Gateway: The Gateway is restricted to Windows 95/98/NT/2000/XP, but provides various
communication media and protocols (TCPIP, RS232, Shared-Memory, CANOpen, ...).
The Handler is delivered as SDK 2 , i.e. all C++ header files, the static link library (PLCHandler.lib resp.
PLCHandlerComplete.lib) and a sample program (main.cpp) are part of the package.
The link library is provided in two different versions:
1. PLCHandler.lib: Contains only PLCHandler (without ARTI resp. gateway dlls)
2. PLCHandlerComplete.lib: Contains complete ARTI interface (no additional dlls needed)
A Visual Studio C++ V6.0 workspace for compiling the sample program also is contained
(PLCHandlerDemo.dsp).
For the Windows Platform the PLCHandler additional is available as a dll (PLCHandler.dll with ANSI-
interface) and as ActiveX-Control (PLCHandlerX.ocx).
In the following the PLCHandler class and its methods will be described in detail.
1
SDB = Symbolic Data Base; will be created by CoDeSys during project compilation if in Project /
Options / Symbol configuration the export of variables is activated
2
SDK: Source Development Kit
2 CPLCHandler Class
2.4 Disconnection
Method: long ::Disconnect(void)
At a call of this method the connection to the PLC will be terminated.
Return value: If no error occurs, the function returns RESULT_OK. Otherwise, it returns …
RESULT_FAILED: no corresponding interface which can be closed .
RESULT_FAILED: common error in the underlying interfaces. A specific error code can be
retrieved by GetStatus() resp. GetLastError().
RESULT_PLC_NOT_CONNECTED: lost connection to the PLC.
RESULT_EXCEPTION: an exception occurred in the underlying interface.
2.12 Protected method for sending and receiving any services to/from the
PLC
Method: long ::SyncSendService(unsigned char *pbySend, unsigned long ulSendSize,
unsigned char **ppbyRecv, unsigned long *pulRecvSize)
This method can be used to transfer any runtime system service to the PLC.
Return value: If no error occurs, the function returns RESULT_OK. Otherwise, it returns …
RESULT_FAILED: common error in the underlying interfaces. A specific error code can be
retrieved by GetStatus() resp. GetLastError().
RESULT_PLC_NOT_CONNECTED: lost connection to the PLC.
RESULT_EXCEPTION: an exception occurred in the underlying interface.
ATTENTION: The structure of the service must be known in detail! An erroneous service might cause
a crash of the PLC! Due to this reason the method is only accessible in derivative classes and has not
been published straightly.
3.1 Simulation
will be supplied in a future version of the document
3.2 ARTI
will be supplied in a future version of the document
3.3 Gateway
will be supplied in a future version of the document
timeout=10000 Time in ms, defines how long the answer on a data package
from the PLC might take, before an error will be dumped.
precheckidentity=0 Flag, defines whether the symbol file should be checked for
up-to-dateness by a separate runtime system service before
each reading/writing of variables.
Regard: On runtime systems >= 2.3 at each write-/read
service it will be checked automatically, whether the symbol
file still are up to date. For this reason on those runtime
systems this entry can be 0.
tries=3 Number of communication trials in case the receiving of data
fails.
waittime=20 Total time in seconds in PLCHandler::Connect() for the
connection establishment. As soon as the time is exceeded,
the routine returns with an error.
reconnecttime=20 Time slice in seconds according to which a reconnect is tried
by Reconnect-Thread().
buffersize=0 Size of the communication buffer; must match with the used
runtime system. 0 = Default value for the currently used
communication protocol.
Special: ELAU -> buffersize = 1500
...
Browsing of variables:
Method: long ::GetNumberOfSymbols();
Returns the number of available variables in the PLC.
Method: long ::GetSymbol(long lIndex, LPCTSTR pszSymbol, long lMaxLen);
GetNumberOfSymbols() can be used to get the number of available variables.
GetSymbol() can be used to get the name of the variable which is specified by the index.
Change History