Sei sulla pagina 1di 17

PLCHandler Programming Guide

PLCHandler Programming Guide

Document Version: 1.2


Last update: 05.12.2008

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 1 of 17
PLCHandler Programming Guide

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

3 CONFIGURATION OF THE PARTICULAR INTERFACES 10


3.1 Simulation 10
3.2 ARTI 10
3.3 Gateway 10
3.4 Simplified configuration with the CEasyPLCHandler Class 10

APPENDIX A: STRUCTURE OF THE INI-FILE FOR THE CONFIGURATION 11

APPENDIX B: ERROR CODES 13

APPENDIX C: STATUS REPORTS OF THE PLCHANDLER 14

APPENDIX D: ACTIVEX-CONTROL OF THE PLCHANDLER UNDER WINDOWS 15

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 2 of 17
PLCHandler Programming Guide

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

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 3 of 17
PLCHandler Programming Guide

2 CPLCHandler Class

2.1 Constructor and Configuration of the PLCHandler


A PLCHandler object of the CPLCHandler class always is assigned to a single PLC. Thus at creation
of the object it has to be configured, with which PLC resp. which communication interface the
PLCHandler should work. The configuration is specified in chapter 3.
There are various constructors for creating the PLCHandler object:
1. CPLCHandler(unsigned long ulId, char *pszIniFile,
SysLog *pLogFile = NULL):
Parameter ulId designates the index of the PLCHandler assumed that more instances are
used.
An ini-file for reading the configuration will be handed over to the constructor. The SDK
provides two sample files (OPCServerARTI.ini and OPCServerSimu.ini). The structure is
described in detail in the Appendix of this guide.
Optionally a log file can be specified for recording all errors and internal states. The SysLog
class is contained in the PLCHandler.
2. CPLCHandler(PlcConfig *pPlcConfig, PlcDeviceDesc *pDeviceDesc,
SysLog *pLogFile = NULL):
The parameters on the one hand define general configuration data in the PLCHandler
(pPlcConfig) and on the other hand the communication settings for the (pDeviceDesc). The
data are identic with the entries in the ini-file. Thus both constructors can be used according to
the actual requirements.
Optionally also here a log file can be specified for recording all errors and internal states. The
SysLog class is contained in the PLCHandler.
The PlcConfig structure contains the configuration data for the PLCHandler:
struct PlcConfig
{
PlcConfig(void);
~PlcConfig(void);
unsigned long ulId; unique ID for every PLC
char *pszName; name of the PLC
ItfType it; interface type of the PLC (IT_ARTI, IT_GATEWAY, ...)
char ulSize; size of the variable
char bActive; flag if the PLC is active or not
char bMotorola; flag if data has to be swapt for motorola byte order
char bLogin; flag if the application can do a login
char bLogToFile; flag if the application should log to a file
char bPreCheckIdentity; flag if the project identity will be checked
before every read / write of variables
unsigned long ulTimeout; communication timeout in ms
unsigned long ulNumTries; number of tries of receive's before throwing a
COMM_FATAL error
unsigned long ulWaitTime; total time in ms to wait for a reconnection to the PLC
unsigned long ulReconnectTime; time interval in ms to try for a reconnection
char *pszHwType; HW type of the PLC (PLCC_HW_STANDARD,
PLCC_HW_MAX4)
unsigned long ulHwVersion; HW version
unsigned long ulBufferSize; communication buffersize of the runtime system
running on the PLC; 0 = default size
char *pszProjectName; name of the CoDeSys project running on the
runtime system; only of interest in simulation
char *pszDllDirectory; directory where to find the (Sym-)ARTI Dll's
GatewayConnection *gwc; pointer to the gateway connection if using the
gateway interface
 3S - Smart Software Solutions GmbH
PLCHandler Programmming Guide.doc Page 4 of 17
PLCHandler Programming Guide

unsigned long ulLogFilter; Filter for log actions


};
The PlcDeviceDesc structure contains data to connect to a device:
struct PlcDeviceDesc
{
PlcDeviceDesc(void);
~PlcDeviceDesc(void);
char* pszName; name of the device / protocol
char* pszInstance;instance name of the device
char* pszProject; name of the project running on that device (only of
interest for gateway)
unsigned long ulNumParams; number of the device parameters
PlcParameterDesc* ppd; pointer to an array of parameter descriptions
};
To get the definition of the PlcParameterDesc please have a look at the PLCHandler header
PlcConfig.h.

3. CPLCHandler(SysLog *pLogFile = NULL):


This constructor is used to create a PLCHandler object with default configuration (Interface:
ARTI).
But in each case before connection establishment the communication device must be
configured (with SetConfig() or directly by opening the configuration with GetConfig() and
setting the appropriate values).

2.2 Destructor (and connection termination)


As soon as the PLCHandler object has been deleted, the connection to the PLC gets terminated (if
there was one), all resources are deallocated and all internal threads are terminated.

2.3 Connection establishment


Method: long ::Connect(unsigned long ulTimeout = PLCHANDLER_USE_DEFAULT,
unsigned long hStateChangedEvent = 0, int bLoadSymbols = 1)
After the configuration has been done, via this method a connection to the PLC can be established.
The method will return RESULT_OK (=0) as soon as the connection has been built up successfully. In
case of an error the current state of the communication resp. The last occurred error can be get by the
GetStatus() resp. GetLastError().
If a connection could not be established, the method returns an error and internally a thread will be
started, trying to reconnect to the PLC in the defined reconnect interval.
ulTimeout: This value specifies how long the connection establishment maximally can take,
before the function returns. At 0 the value set actually in the configuration will be used (see:
WaitTime). At ulTimeout = –1 the method will not return until a connection to the PLC will be set up
successfully. This can take any time.
hStateChangedEvent: Here optionally the handle of an event can be passed which can be used to
inform the client at each status change.
bLoadSymbols: This parameter can be used to specify whether at a connection establishment the
symbols of the PLC should be loaded or not.
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_NO_CONFIGURATION: no configuration for this PLCHandler instance (Id unknown).

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 5 of 17
PLCHandler Programming Guide

RESULT_PLCHANDLER_INACTIVE: PLCHandler instance isn’t set active (see IniFile).


RESULT_RECONNECTTHREAD_STILL_ACTIVE: reconnect thread is still active.
RESULT_ITF_NOT_SUPPORTED: the interface isn’t supported.
RESULT_ITF_FAILED: the interface can’t start successfully (missing interface dependent
Dll’s).
RESULT_PLC_NOT_CONNECTED: cannot open connection to the PLC.
RESULT_PLC_NOT_CONNECTED_SYMBOLS_LOADED: cannot open connection to the PLC but
could load the symbol file offline.

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 .

2.5 Browsing all variables in the PLC


Method: long ::GetAllItems(PlcSymbolDesc **ppSymbolList, unsigned long *pulNumOfSymbols)
This method can be used to read the list of all variables which are specified in the PLC.
In ppSymbolList a list of all symbols will be returned. For each symbol the list provides name, data
type, address within PLC, variables size in bytes etc.
In pulNumOfSymbols the number of variables will be returned.
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_INVALID_PARAMETER: invalid function parameters (for e.g. NULL).
The PlcSymbolDesc structure contains the symbolic description of a variable:
struct PlcSymbolDesc
{
char* pszName; symbol name of the variable
unsigned long ulTypeId; reference into the symbol type table
char* pszType; type name of the variable
unsigned short usRefId; variable's type (input, output, global, …)
unsigned long ulOffset; offset in the memory image
unsigned long ulSize; size of the variable
char szAccess[2]; access type of the variable (no, read, write access, both)
unsigned char bySwapSize; basic swap size of the variable
};
Speciality: The size of a bit symbol is per definition 0 in the CoDeSys runtime system. So you have
to check the symbol's size for 0 and do a special bit coding (for e.g. memset() or memcpy()
with parameter size=1 instead with the original symbol's size)

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 6 of 17
PLCHandler Programming Guide

2.6 Getting a variables' description


Method: long ::GetItem(char *pszSymbol, PlcSymbolDesc *pSymbol)
pszSymbol specifies the variable, for which the description should be retrieved.
In pSymbol the description (data type, size in bytes, address etc.) of the variable will be returned.
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_INVALID_PARAMETER: invalid function parameters (for e.g. NULL).

2.7 Cyclic Update of Variables

2.7.1 Creating a cyclic list


Method: HCYCLIST ::CycDefineVarList(char **ppszSymbols, unsigned long ulNumOfSymbols,
unsigned long ulUpdateRate, unsigned long hUpdateReadyEvent = 0,
unsigned long hDataChangeEvent = 0, unsigned long hUpdateEvent = 0)
This method can be used to create a list of variables, whose values should be updated cyclically by
the PLCHandler and can be read at any time. The method returns a handle for the list. This handle
must be passed with all further method calls.
ppszSymbols: Here a list of variable names will be passed.
ulNumOfSymbols: This parameter specifies the number of variables in the list.
ulUpdateRate: Specifies the update rate for the cyclic update of the variable values.
hDataChangeEvent: Here optionally a handle on a event can be specified, referring to which an
information should be sent at any value change.
hUpdateEvent: Here the handle of an event can be passed, which then will be used to control the
cyclic update.
Return value: If no error occurs, the function returns a handle for the cyclic list. Otherwise, it returns …
NULL: function failed. A specific error code can be retrieved by GetStatus() resp.
GetLastError().

2.7.2 Deleting a cyclic list


Method: long ::CycDeleteVarList(HCYCLIST hCycVarList, int bKeepalive = 1)
This method is used to delete a list of variables which had been set up for cyclic update (see above).
hCycVarList: Specifies the handle which has been passed by CycDefineVarList().
BKeepalive: Here you define, whether the PLCHandler should start a so-called "Keepalive" if the
current list is the last cyclic list which gets deleted. In this case typically a thread will be started in the
PLCHandler, sending a Keepalive service to the PLC every 2 seconds, in order that the PLC will not
log out if no further services are sent.
Return value: If no error occurs, the function returns a handle for the cyclic list. Otherwise, it returns …
RESULT_PLC_NO_CYCLIC_LIST_DEFINED: no list to delete.

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 7 of 17
PLCHandler Programming Guide

2.7.3 Reading the values of a cyclic list


Methods: long ::CycEnterVarAccess(HCYCLIST hCycVarList)
long ::CycReadVars(HCYCLIST hCycVarList, PlcVarValue ***pppValues,
unsigned long *pulNumOfValues)
void ::CycLeaveVarAccess(HCYCLIST hCycVarList)
The methods CycEnterVarAccess() and CycLeaveVarAccess() must enclose each read operation in a
cyclic list to synchronize access to the variables of the list.
The method CycReadVars() can be used to access the values of a cyclic list. Those get updated
according to the time pattern defined by UpdateRate.
Return value : If no error occurs, the function CycEnterVarAccess() return 1. Otherwise, it returns …
0: the cyclic list is invalid.
Return value: If no error occurs, the function CycReadVars() returns RESULT_OK. Otherwise, it returns
RESULT_FAILED: common error in the underlaying interfaces. A specific error code can be
retrieved by GetStatus() resp. GetLastError().
RESULT_PLC_NOT_CONNECTED: lost connection to the PLC.
RESULT_INVALID_PARAMETER: invalid function parameters (for e.g. NULL).
RESULT_PLC_NO_CYCLIC_LIST_DEFINED: invalid list or no list variables to read.

2.8 Synchronous reading of variables


Methods: HVARLIST ::SyncReadVarsFromPlc(char **ppszSymbols,
unsigned long ulNumOfSymbols, PlcVarValue ***pppValues,
unsigned long *pulNumOfValues)
long ::SyncReadVarsFromPlcReleaseValues(HVARLIST hSyncRead)
The method SyncReadVarsFromPlc() can be used to read the values of a list of variables from the
PLC.
ppszSymbols: specifies the list of variables
ulNumOfSymbols: number of variables in the list
pppValues: returns the list of variables values after the call
pulNumOfValues: Number of read values
SyncReadVarsFromPlcReleaseValues() then can be used to deallocate the list of read variables
Return value: If no error occurs, the function returns a handle for the list. Otherwise, it returns …
NULL: function failed. A specific error code can be retrieved by GetStatus() resp.
GetLastError().

2.9 Synchronous writing of variables


Method: long ::SyncWriteVarsToPlc(char **ppszSymbols, unsigned long ulNumOfSymbols,
unsigned char **ppbyValues)
This method can be used to transfer a list of variable values to the PLC.
ppszSymbols: specifies the list of variables
ulNumOfSymbols: number of variables in the list
ppbyValues: specifies the variables values which should be written to the PLC. Must match the list of
the specified variables !
Return value: If no error occurs, the function returns RESULT_OK. Otherwise, it returns …

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 8 of 17
PLCHandler Programming Guide

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.10 General data transfer


Methods: long ::UploadFile(char *pszPlc, char *pszHost = NULL)
long ::DownloadFile(char *pszHost, char *pszPlc = NULL)
The method UploadFile() can be used to transfer files from the PLC to the client. pszPlc specifies the
name of the file on the PLC, pszHost specifies the name of the file on the client.
The method DownloadFile() can be used to transfer files from the client to the PLC. pszHost specifies
the name of the file on the client, pszPlc specifies the name of the file on the PLC.
The methods RenameFile() and DeleteFile() can be used to rename resp. delete files on 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.

2.11 Reading the directory structure on the PLC


Method: long ::ReadDirectory(CDirInfo **ppdi, char *pszBaseDir = NULL)
This method can be used to read the directory structure on the PLC. You can specify a basic folder in
pszBaseDir.
In object ppdi the complete directory structure is stored (including files and sub-directories).
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.

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.

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 9 of 17
PLCHandler Programming Guide

3 Configuration of the particular interfaces


The PLCHandler allows to communicate with a PLC via two different interfaces (ARTI or Gateway)
and it makes possible a simulation of the PLC variables if no PLC is connected.
See In the following how the PLCHandler must be configured in order to be able to communicate via
the particular interfaces.

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

3.4 Simplified configuration with the CEasyPLCHandler Class


The PLCHandler contains a derived class CEasyPLCHandler. This class encapsulates the most
important and popular communication channels and applies the appropriate correct settings.
The following methods are available in addition to the PLCHandler methods:
Method: long ::ConnectTcpipViaGateway(char *pszGatewayIP, char *pszPlcIP,
char *pszProtocol = PLCC_DN_TCPIP_L2ROUTE,
int bMotorola = 0, int bLoadSymbols = 1,
unsigned long ulTimeout = PLCHANDLER_USE_DEFAULT)
This method can be used to set up a connection to a PLC via TCPIP and the Gateway on a Windows
system. For this purpose only the IP address of the gateway as well as the IP address of the PLC
must be passed on. Default setting: Tcpip L2 Route Protocol.
Method: long ::ConnectTcpipViaArti(char *pszPlcIP,
char *pszProtocol = PLCC_DN_TCPIP_L2ROUTE,
int bMotorola = 0, int bLoadSymbols = 1,
unsigned long ulTimeout = PLCHANDLER_USE_DEFAULT);
This method can be used to set up a connection to a PLC via TCPIP and ARTI. For this purpose only
the IP address of the PLC must be passed on. Default setting: Tcpip L2 Route Protocol.
Method: long ::ConnectRs232ViaArti(short sPort, unsigned long ulBaudrate,
int bMotorola = 0, int bLoadSymbols = 1,
unsigned long ulTimeout = PLCHANDLER_USE_DEFAULT);
This method can be used to set up a connection to a PLC via ARTI and the serial interface. sPort = 1
corresponds to COM1, etc.
Method: long ::ConnectToSimulation(char *pszSdbFile, int bLoadSymbols = 1,
unsigned long ulTimeout = PLCHANDLER_USE_DEFAULT);
This method can be used to set up a connection to a simulation and to a SDB file. Only the name of
the SDB file must be given. For this purpose also a complete path can be specified.
Return value: These methods return same error values like the ::Connect() method.

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 10 of 17
PLCHandler Programming Guide

Appendix A: Structure of the Ini-File for the Configuration


[Server] PLCHandler-Section
PLCs=2 Number of configured PLCHandlers (for several
instances/connections)
PLC0=PLCWinNT Name of the first PLC; here e.g. PLCWinNT
PLC1=RTE Name of the second PLC; here e.g. RTE

[PLC:PLCWinNT] This section is assigned to a particular PLCHandler


instance. The assignment is done by specifying the
index in the constructor of the PLCHandler object. This
index corresponds to the index in the above defined list
of instances (PLC<n>=…).
interfacetype=ARTI Interface type: ARTI, SIMULATION, GATEWAY (gateway only
under WinNT/2000/XP)

logevents=1 Activating/Deactivating the output of events in a log file


(OPCServer.log). The file is in the same directory as the
OPC-Server.
active=1 Flag, defines whether the PLC is active (Establishing
connection) or not
motorola=0 Flag, defines whether the data must be swapped (Motorola
Byte order is used on the PLC) or not
nologin=0 Flag, defines whether the PLCHandler should not log in on
the PLC; some runtime systems only allow a log-in of one
application !
Special: ELAU, ABB -> nologin = 1

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

max4version=0 Please use only together with a ELAU-Max4 controller and in


this case set to the corresponding hardware version (1100,
1200); with all other controllers this entry is not applicable!

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 11 of 17
PLCHandler Programming Guide

project= ProjektName.pro Only relevant in SIMULATION: in this case the PLCHandler


needs no PLC, but simulates the PLC via the symbol file
’ProjektName.sdb’.
This entry also can be used in the ARTI Interface, if the SDB
file cannot be stored on the underlying PLC.
device=Tcp/Ip (Level 2 Communication protocol; the most important settings are:
Route) Tcp/Ip (Level 4): TCP/IP Level 4 Protocol
Tcp/Ip (Level 2): TCP/IP Level 2 Protocol
Tcp/Ip (Level 2 Route): TCP/IP Level 2 Route
Serial (RS232): Serial connection
For information on other protocols please see the
corresponding specification (see Gateway).
Special: ELAU -> device = Tcp/IP (Level 4)

instance=PLCWinNT_TCPIP Here you can assign a name to the package of configuration


settings
parameters=4 Number of parameters for this protocol
(here: TCP/IP Level 2 Route)
parameter0=Address Name of the first parameter: TCP/IP address of the PLC
value0=localhost Value of first parameter: here: connection to localhost
parameter1=Port Name of second parameter: Port Number
value1=1200 Value of second parameter: Default value 1200
Special: ELAU -> value1 = 5000

parameter2= TargetId For TCP/IP (Level 2 Route): ID of the runtime system,


to which the data should be routed
value2=0 For TCP/IP (Level 2 Route): Default value 0 (no
routing)
parameter3= Motorola Name of fourth parameter: Motorola byte order for the
byteorder communication data
value3=No Value of fourth parameter: No -> no swapping necessary

[PLC:RTE] This is the second instance to be configured


interfacetype=GATEWAY Interface type: ARTI, SIMULATION, GATEWAY (gateway only
under WinNT/2000/XP)

...

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 12 of 17
PLCHandler Programming Guide

Appendix B: Error codes

Define Value Description


RESULT_FAILED -1 Action erroneous.
More exact error values can
be requested by
::GetLastError() resp. by
::GetState().
RESULT_OK 0 Action successful
RESULT_PLC_NOT_CONNECTED 1 PLC not connected
RESULT_PLC_LOGIN_FAILED 2 Login to PLC has failed
RESULT_PLC_NO_CYCLIC_LIST_DEFINED 3 No cyclic list has been found
RESULT_PLCHANDLER_INACTIVE 4 PLCHandler is inactive
RESULT_LOADING_SYMBOLS_FAILED 5 Loading of the symbols has
failed
RESULT_ITF_NOT_SUPPORTED 6 The defined communication
interface is not valid or not
supported
RESULT_COMM_FATAL 7 Communication error occurred
during action
RESULT_NO_CONFIGURATION 8 Wrong or erroneous
configuration of the
PLCHandler
RESULT_INVALID_PARAMETER 9 Invalid parameter
RESULT_ITF_FAILED 10 Communication interface not
resp. incorrectly installed (e.g.
Gateway Dlls not available)
RESULT_NOT_SUPPORTED 11 Method not yet supported
resp. implemented
RESULT_EXCEPTION 12 Exception occurred during
action
RESULT_TIMEOUT 13 Timeout wurde überschritten
RESULT_STILL_CONNECTED 14 PLC already connected (at a
further ::Connect() call)
RESULT_RECONNECTTHREAD_STILL_ACTIVE 15 Reconnect Thread already
active
RESULT_PLC_NOT_CONNECTED_SYMBOLS_LOADE 16 Symbols available offline
D

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 13 of 17
PLCHandler Programming Guide

Appendix C: Status reports of the PLCHandler

Define Value Description


STATE_TERMINATE -1 PLCHandler currently is
terminating (Destructor)
STATE_PLC_NOT_CONNECTED 0 PLC is not connected (init state)
STATE_PLC_CONNECTED 1 PLC is connected
STATE_NO_SYMBOLS 2 PLC is connected but symbols
are not yet loaded
STATE_SYMBOLS_LOADED 3 PLC is connected and symbols
are loaded
STATE_RUNNING 4 PLC is connected, symbols are
loaded and all of them are
verified. Now you can work
correctly with the PLCHandler
object
STATE_DISCONNECT 5 Connection is just getting
terminated
STATE_NO_CONFIGURATION 6 No valid configuration
STATE_PLC_NOT_CONNECTED_SYMBOLS_LOADE 7 Symbols available offline
D

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 14 of 17
PLCHandler Programming Guide

Appendix D: ActiveX-Control of the PLCHandler under Windows


The PLCHandler also will be provided as ActiveX Control.
Before first use the ActiveX-Control must be registered with the following command:
regsvr32 plchandlerx.ocx
Then the PLCHandlerX class can be used in a Visual-Basic, Delphi or C++ project.

The following methods deviate from the methods in the PLCHandler:


Connection establishment:
Method: long ::ConnectByString(long lId, LPCTSTR pszConfigString, long lConfigLen,
long StateChangedEvent, LPCTSTR pszLogFile);
Parameter ulId specifies the index of the PLCHandler, if several instances are used.
Parameter pszConfigString points to a string containing the content of the ini-file of the
configuration. For information on the structure of this ini-file please see Fehler!
Verweisquelle konnte nicht gefunden werden. lConfigLen specifies the length of the
configuration string.
StateChangedEvent: Here optionally the handle of an event can be processed, via which the
client can be informed at each state change.
pszLogFile is the name of a log file, where the PLCHandler optionally can record all important
actions.
Method: long ::ConnectViaGateway(LPCTSTR pszGatewayIP, LPCTSTR pszPlcIP,
LPCTSTR pszProtocol, LPCTSTR pszLogFile);
This method can be used to establish a connection via TCPIP and the Gateway to a PLC
under Windows. For this purpose only the IP-address of the Gateway as well as the IP-
address of the PLC must be passed. Default setting is the Tcpip L2 Route Protocol („Tcp/Ip
(Level 2 Route)“).
Method: long ::ConnectViaArti(LPCTSTR pszPlcIP, LPCTSTR pszProtocol,
LPCTSTR pszLogFile);
This method can be used to establish a connection via TCPIP and ARTI to a PLC. For this
purpose only the IP-address of the PLC must be passed. Default setting is Tcpip L2 Route
Protocol.
Method: long ::ConnectViaSimulation(LPCTSTR pszSdbFile, LPCTSTR pszLogFile);
Via this method the connection to the simulation mode and to a SDB-file is established. Just
the name of the SDB-file must be specified. Thereby also a complete path can be defined.

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.

Synchronous Reading of variables:


Method: long ::SyncReadVarFromPlc(LPCTSTR pszSymbol, long lAddressData, long lSize);
lAddressData specifies the address, where the value of the variables is stored.
pszSymbol specifies the name of one variable.

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 15 of 17
PLCHandler Programming Guide

Method: long :: SyncReadVarsFromPlc(LPCTSTR pszSymbols, long lAddressDataList, long


lAddressSizeList, long lNumOfVars);
lAddressData specifies the address, where the value of the variables is stored.
pszSymbol specifies the names of several variables. LNumOfVars defines the number of
variables.

Synchronous Writing of variable values:


Method: long SyncWriteVarToPlc(LPCTSTR pszSymbol, long lAddressData, long lSize);
lAddressData specifies the address where the value of the variable to be written is stored.
pszSymbol specifies the name of one variable.
Method: long SyncWriteVarsToPlc(LPCTSTR pszSymbols, long lAddressDataList, long
lAddressSizeList, long lNumOfVars);
lAddressData specifies the address, where the value of the variables to be written is stored.
pszSymbol specifies the names of several variables. LNumOfVars specifies the number of
variables.

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 16 of 17
PLCHandler Programming Guide

Change History

V1.0 27.02.04 Release Version


V1.1 15.10.04 VersionTcp/Ip (Level 4), Elau specialities added; some formatting and translation
corrections
V1.2 08.02.05 PLCHandler methods updated and described (ActiveX-Control,App.D), Return and
status values described (new App.B,C), ActiveX-Control (App.D)

 3S - Smart Software Solutions GmbH


PLCHandler Programmming Guide.doc Page 17 of 17

Potrebbero piacerti anche