3 Use of the CoDeSys OPC server

3.1 General notes

After the OPC server is installed, it should be provided by the OPC client (e.g. visualization) for selection.

The gateway and the OPC server are automatically started by the operating system as soon as one of the clients (visualization software) establishes a connection. The OPC server is automatically exited as soon as all clients have cleared the connection. The gateway remains open, but it is inactive.

The steps 3.2.1 to 3.2.3 described below must be carried out to make data objects of a project in the CoDeSys programming system available for the OPC server and to establish a connection via OPC.

3.2 Settings in the programming software CoDeSys

In order to enable the OPC server to access data objects of a project, first a symbol file has to be created. For this, start the programming software CoDeSys and open the project.

 Caution: Using multi-PLC configurations it is required to give all PLC projects an independent name. This is necessary since the symbol files are created under this name. The OPC server compares the project ID of the PLC with that one of the symbol file at the beginning. If these do not agree, no communication is carried out then.

3.2.1 Step 1: Creating the data objects

The gateway does not use a project file, but a symbol file of the same name with the file name extension "sym" or "sdb" (binary). This file contains symbol entries (item list) for the project variables. To automatically create this symbol file with each compilation process, the option 'Dump symbol entries' must be selected. The corresponding settings can be made by calling the menu item <Project><Options>. The automatic creation of the symbol file is set by selecting the category <Symbol configuration> and then checking the checkbox 'Dump symbol entries'. The dialog stays open for entering further settings.

3.2.2 Step 2: Configuration of the symbol files

In the project structure tree shown in the dialog 'Set object attributes', the POUs or individual variables (items) can be selected for which symbol options shall be set. For this, click the button <Configure symbol file> in the presently open dialog or select <Project> <Options> from the menu and then <Symbol configuration> <Configure symbol file>.

Configuring all POUs

If all project variables shall be defined with the same properties, all POUs must be selected. The desired attributes are activated by clicking the checkboxes. When an attribute is active, the checkbox is filled with a black checkmark. Inactive attributes must be unchecked (white). Gray checkmarks are not allowed.

Configuring individual program blocks or variables

If only variables of individual POUs or individual variables shall be activated, first all attributes of the entire project must be deactivated. To do so, select all POUs and deactivate all attribute checkboxes. Now, all checkboxes must be white.

 Caution: The deletion of object attributes is not applied until it is confirmed with the <OK> button. Each deletion must be confirmed with the <OK> button prior to defining further settings. Otherwise, the object attributes are not deleted.

The dialog 'Set object attributes' must be opened again. Now, the individual project POUs or variables can be selected and set with the desired attributes.

The following attributes can be set:

Export variables of object

The variables of the selected object are written to the symbol file.

Export data entries

Entries for accessing the total variables are created for structures and arrays of the object. Assumption: 'Export variables of object' is activated.

Export structure components

For structures of the object, one entry is created for each component of the variable. Assumption: 'Export variables of object' is activated.

Export array entries:

For the arrays of the object one entry is created for each component of the variable. Assumption: 'Export variables of object' is activated.

Write access:

The OPC server can modify the variables of the object.

3.2.3 Step 3: Setting of the communication parameters in the project

The channel of the used gateway is set in the dialog <Online> <Communication Parameters>. (Further information on the gateway configuration can be found in the documentation "System technology of the CPUs" / "Programming and test"). This setting must match the OPC server configuration (see section 3.3 "Configuration of the OPC server using OPCconfig.exe").

 Note: For Single-PLC configuration:
The OPC server automatically starts with the connection settings last used (these settings are kept in the registry). These settings can be verified or changed in the file OPCconfig.exe prior to starting the OPC server. This means that the setting of the gateway is automatically updated in the configuration. Each time a project is sent to the PLC, the corresponding gateway settings are applied.

The gateway connection can be set to local or TCP/IP. A local connection is used, if the OPC server and the used gateway reside on the same computer. A TCP/IP connection is used, if the gateway of another computer is accessed by the OPC server via a network.

  Note: A TCP/IP connection to the gateway can also be used, if the OPC server and the gateway reside on the same computer. However, with this setting, higher transmission times must be expected compared to the setting 'local'.

 

 Caution: For parallel operation of the OPC server and CoDeSys or SyCon.net, the settings of the communication channels must match completely. Multiple access to a PLC is only possible via the same gateway channel. Here, not only the corresponding driver and address are important, but also all further settings such as the timeout value.

3.2.4 Step 4, optional: Store project

The communication parameters are saved with the project and, after a login, also in the gateway.

3.2.5 Step 5: Creating of the symbol file and transmission to the gateway

When compiling the project, the symbol file is created and stored to the project directory. When downloading the project (<Online> <Login> -> 'Download'), the symbol file (*.sym or *.sdb) with the present settings is additionally loaded to the gateway (directory 'Gateway Files'). The communication with the OPC server uses the settings of the symbol file located in the path \WinNT\Gateway Files\, for example.

 Note: The number of symbols should not exceed approx. 15 000 (corresponds to a symbol file size (*.sym) of approx. 1.5 MB). Please refer to chapter 4 "Behaviour of the OPC server".

 

 Note: When preparing a project in the office without having the corresponding hardware available, the symbol file must be copied to the system path \Gateway Files after finishing the CoDeSys project. This means that the file <project name>.sdb must, for example, be copied to the directory C:\WINNT\Gateway Files.

The representation of variables in the symbol file is the same as in the watch window.

Example:

PLC_PRG.A
PLC_PRG.structure.X[4]
.GlobVar1

 Caution: Direct addresses cannot be accessed.

3.3 Configuration of the OPC server with OPCconfig.exe

With the configuration it is determined which controller shall read the symbol entries. For this, the gateway channel must be determined, the project name must be entered and the individual parameters (e.g. transmission rate, timeout values, etc.) must be defined. The OPC standard does not include an interface for the transmission of this information. For that reason, the project identifier is written to the registry on each download of a project (refer to section 3.3.5 "Registry entries (example)"). The OPC server reads this identifier and searches the symbol file with the same name.

 Caution: Primarily it is important that in the OPC server configuration the project name corresponds to the used communication driver (i.e. if communication channel = TCP/IP_Address 192.68.0.251 and project name = OPC_test_program, the Ethernet subscriber with the IP address 192.68.0.251 must contain the project OPC_test_program).

For setting these parameters, please refer to section 3.2.3, step 3: "Setting the communication parameters in the project" and the CoDeSys documentation respectively.

First, it has to be determined which mode is used: Single-PLC or Multi-PLC. The mode of operation depends on the following factors:

Mode of operation

Factors

Single-PLC

- is used, if the symbol entries are read by only one controller.

 

 Note: In Single-PLC mode, the configuration of the gateway channel is adapted automatically. This means that each time a project is sent to the PLC, the corresponding gateway settings are applied to the OPC configuration.

 

 Caution: Single-PLC mode should only be used if the configuration shall be adapted automatically.

- Generally, we recommend to use the setting Multi-PLC.

Multi-PLC

- If the symbol entries are read from at least 2 controllers, then multi-PLC must always be used.

- is used if the symbol entries are read by only one controller and the configuration shall not be adapted automatically. This means that the settings in the OPC configuration are adapted manually. For instance, this is important if you have set up an Ethernet network with several controllers and the symbol file shall only be read by one controller (head controller). If the programming of the other controllers would be performed via the same gateway, the OPC configuration would be changed with each program download.

 

The following notes should be observed for the use:

 Note: A download of the desired project to the corresponding target controller should be performed immediately before using the OPC server.
If the target controller is not available, the current symbol file should be copied into the gateway files directory.

 

 Note: When adding or deleting variables in the project, the item list can be updated without the need to exit the OPC client and the OPC server by downloading once again (with the option 'Dump symbol entries' activated). For instance, the client then receives a corresponding message (status "Bad") when it tries to access a deleted variable.

 

 Note: Please note that a possibly existing boot project does no longer match a project which was changed and downloaded again. Hence, it is recommended to store the program in the PLC Flash memory each time after downloading it.

For configuring the OPC server and modifying the registry entries of the server, the configurator OPCconfig.exe is started (refer to OPC documentation, section 3.3.5 "Registry entries (example)").

The following sections describe the commands of the <File> and <Edit> menu as well as the specific dialogs for the Single-PLC or Multi-PLC configuration.

3.3.1 Menu <File>

 

Open

This command opens the configuration saved last using <File> <Save>.

Save

After the configuration of the server, the PLC(s) and the connection(s) is finished, it has to be saved using this command in order to become valid.

New

This command opens (creates) a new configuration. The dialogs contain default settings or empty input fields.

Single-PLC

Using this option, the mode Single-PLC or Multi-PLC is selected. If the menu entry 'Single-PLC' is displayed, Multi-PLC mode is currently active. If '√ Single-PLC' is displayed, Single-PLC mode is active.

Export
Import

 Caution: This menu item is only available in Multi-PLC operating mode.

Using the <Export> command, the current configuration can be exported to a text file. For this, the standard dialog 'Save file as' is opened where you can enter a file name. The default file name extension ".ini" is appended automatically. The ini file contains the configuration parameters and can be edited and re-imported using the command <File> <Import>. When importing a file, the stored ini files can be selected in the standard dialog 'File open'.

3.3.2 Menu <Edit>

The following commands are available depending on the selection in the configuration tree ('Server', 'PLC' or 'Connection') or depending on the type of configuration (single PLC or multi PLC).

 

Append PLC

 Caution: This menu item is only available in Multi-PLC operating mode.

Multi-PLC mode, settings for the OPC server:
Using this option, another controller is inserted to the configuration; refer to section 3.3.3.1 "General" in the OPC documentation.

Rename PLC

 Caution: This menu item is only available in Multi-PLC operating mode.

Multi-PLC mode, settings for the OPC server:
Using this option, a controller previously inserted to the configuration can be renamed; refer to section 3.3.3.1 "General" in the OPC documentation.

Delete PLC

 Caution: This menu item is only available in Multi-PLC operating mode.

Multi-PLC mode, settings for the OPC server:
Using this option, a controller can be deleted from the configuration; refer to section 3.3.3.1 "General" in the OPC documentation.

Reset PLC

Single-PLC and Multi-PLC, settings for the PLC:
The configuration parameters set with <Edit> <PLC Default Settings> are loaded from the registry.

PLC Default Settings

Always available:
The dialog 'PLC Default Settings' appears. Here, you can enter self-defined values for the PLC configuration settings. This dialog corresponds to the 'Settings for PLC' dialog (refer to OPC documentation, section 3.3.3.3 "Settings for the PLC"). The values set in this dialog are saved to the registry after confirming the dialog with <OK>. Using the command <Edit> <Reset PLC>, these settings can be re-loaded for a PLC selected in the configuration tree.

3.3.3 Multi-PLC configuration

3.3.3.1 General

  Note: Possibly appearing dialogs for saving are not mentioned in the following procedure.

Generally, we recommend to use the setting Multi-PLC. To activate this operating mode, the option 'Single-PLC' has to be deactivated in the <File> menu.

Start the OPCConfig.exe program. The operating mode Single-PLC must now be deactivated. The option 'Single-PLC' has to be deactivated in the <File> menu. -> Single PLC.

In the menu <File><New> the following dialog appears as a standard setting:

In the left part of the window, the entry 'Server' appears at first. The desired controllers (PLC, participants) are inserted with the command <Edit><Append PLC>. Then they can be configured individually.

In the Edit menu, the following commands are additionally available for the PLC currently selected in the configuration tree:

Append PLC

A new 'PLC' entry is inserted. Additional PLCs are always inserted below the currently highlighted entry. The name "PLC<n>" is automatically assigned, where n is counted up beginning with 1.

Delete PLC

The highlighted entry is removed from the total configuration.

Rename PLC

Each PLC can be assigned a user defined name. To do so, highlight the desired PLC entry and then select <Edit> <Rename PLC>. An edit field is opened where you can enter the name.

In the dialog 'Settings for PLC', it can be defined by switching on/off the option 'active', whether or not the controller shall be taken into account by the OPC server.

3.3.3.2 Settings for the OPC server

In the left part of the window, 'Server', controller ('PLC1') and 'Connection' are shown in a tree structure. These entries can be selected by mouse clicks. In the right part of the window, there is a dialog for configuration of the selected entry.

If 'Server' is selected, the following settings can be performed in the right part of the window:

Update Rate (ms): Default: 200

Basic update rate in milliseconds of the OPC server = Cycle time, with which all the item values are read from the controller anew. These values are written into the cash, with which the client communicates over a separately defined update rate.

 Caution: If the update rate is set to a too small value, no communication can be established with the controller. The status of the items is shown with BAD in the client. See also chapter 4 Behaviour of the OPC server.

Public Groups: Default: deactivated (no hooklet)

The OPC server creates a Public Group for each IEC function block and also for the global variables.

Sync Init: Default: activated (hooklet)

Synchronized initialization: The OPC server reacts at start only if the symbol configuration was loaded before.

Log Events: Default: deaktivated (no hooklet)

If this function is activated, the actions and occurred errors of the OPC server are logged and stored in a log file. The file is created in the project directory and given the name OPCServer.log. The messages of several OPC sessions are assembled in the same log file.

3.3.3.3 Settings for the PLC

If in the configuration tree the indented entry 'PLC1' (below 'Server') is selected, the following settings can performed in the right part of the windows:

Project name:

Name of the loaded project. This entry is not absolutely necessary for the operation. It is recommended to enter the corresponding project name in this place.

 Note: If with the OPC server is communicated with via the same Gateway channel over which the program was also sent to the SPS, then no project name must be given. If another Gateway channel is used for the OPC server, then the project name must be given in this place.

 

 Caution: It is important, though, that the individual OPC projects get different project names. The reason for it is that the symbol files are filed for the projects in the path Gatewayfiles. A ProjektID which is changed at every translating and download is in the symbol file. This ProjektID is compared with the one who is stored in the PLC. If these do not agree, then no communication takes place.

Communication Timeout (ms): Default: 10000

If the OPC server gets no request from the controller within this time interval, it terminates itself.

Number of Tries: Default: 3

Number of tries of the OPC server, to reconnect the connection to the controller after a timeout. The time intervals between the tries are specified under 'Reconnecttime'.

Buffer size (bytes): Default: 4800

Size of the communication buffer on the target system. For all AC500 control systems, a buffer size < 5000 must be entered.

Waiting time (s): Default: 10

Time in seconds, which the OPC server waits for readyness of the control system ( important with autostart of the control system).

After the start of the OPC server it is tried to establish communication with the configured controllers. Then it sends a message to the client whether a communication exists or not. Within the waiting time, the controllers have the possibility to register before the status is passed on to the client.

 Note: This time must be chosen long enough so that all participants can register. If this time is set too short, then it can happen that some participants are not registered at the start. In this case the time should be increased.

The time depends on the number of participants and also on the items defined in the symbol file.

 Note: If the CoDeSys project should be changed and new items be added in the symbol configuration, then it can happen that the previously set parameters are not correct any more. In this case the parameters must be adapted (i.e. increasing the waiting time).

Reconnecttime (s): Default: 10

Time interval between two tries in which the OPC server attempts to reconnect the connection to the control system via the gateway after a communication interruption had occurred. How often this takes place is specified under 'Number of Tries'.

Active: Default: activated (hooklet)

This parameter should be activated with a hooklet. If it is deactivated, communication is not possible with the corresponding participant.

With extensive configurations and using this parameter, it is possible to select with which participant shall be communicated (e.g. for putting participants into operation step-by-step or switching them off in case of errors).

Motorola Byteorder: Default: deactivated (no hooklet)

The target system of the project does not use the Motorola byte order. With all AC500 control systems, this option must be set to 'active'.

 Note: With all AC500 control systems, this function is active. With all AC31 control systems, this function is not active.

No Login Service: Default: activated (hooklet)

This option must be deactivated with such target system, where it is necessary to send a login service.

 Note: With all AC500 control systems, no login service must be sent. This function must be active.

3.3.3.4 Settings for the connection to the PLC

If the entry 'Connection' is selected, the settings for the connection to the PLC can be defined in the right part of the window.

If no settings are entered yet or if settings are to be modified, the dialog 'Communication Parameters' can be opened from the menu 'Edit'. This is equal with the available settings of the gateway in the CoDeSys programming software under <Online><Communication Parameters>.

At first, it is selected in this place, whether it should be communicated via a local or a TCP/IP gateway channel. Furthermore, a list is shown containing all the driver settings which already have been loaded via the gateway. Here, that driver is selected, with which the OPC server should start the communication. The selection is confirmed with <OK>.

For operation, see the chapter 3.2.3 Step 3: Setting of the communication parameters in the project or the CoDeSys documentation.

Now your selection should have been accepted. The dialog window looks like this:

3.3.4 Single-PLC configuration

3.3.4.1 General

Generally, we recommend to use the setting Multi-PLC, since the communication parameters are automatically set to the project sent last at the Single-PLC operating mode. Only if this function is particularly desired, this mode should be used. Proceed as follows to configure an OPC server for Single-PLC mode:

  Note: Possibly appearing dialogs for saving are not mentioned in the following procedure.

Start the program OPCConfig.exe. Start the program OPCconfig.exe. First, activate the Single-PLC mode by selecting the option <Single-PLC> from the <File> menu. The menu entry is then marked with a checkmark. -> √ Single PLC.

Via the menu item <File><New>, the following dialog appears as standard setting:

In the left area of the window, the server, the controller (PLC) and the connection are represented in a tree structure and can be selected by clicking with the mouse. The right part of the window displays the corresponding configuration dialog for the entry selected in the tree structure. The <Edit> menu is not used for the Single-PLC configuration.

In the dialog 'Settings for PLC', the option 'Active' is not available in contrast to the Multi-PLC mode.

3.3.4.2 Settings for the OPC server

The settings for the OPC server are equal in both operating modes. See also chapter 3.3.3.2 Settings for the OPC server.

Example:

3.3.4.3.Settings for the PLC

The settings for PLC are equal in both operating modes, except for the 'Active' parameter, which is not available in Single-PLC, see also chapter 3.3.3.3 Settings for PLC.

Example:

3.3.4.4 Setting for the connection to the PLC

The settings for the connection to the PLC are equal in both operating modes, see chapter 3.3.3.4 Settings for the connection to the PLC.

Example:

 

 

3.3.5 Registry entries (example)

The registry entries can be displayed using the command "regedit" in the command prompt.

Entries for the 'Settings for OPC server' dialog of the OPC configurator:

[HKEY_CURRENT_USER\Software\3S-Smart Software Solutions GmbH\CoDeSys OPC\Connections]

* corresponds to the values set in the dialog 'Settings for PLC' of the OPC configurator (refer to OPC documentation, section 3.3.3.3 Settings for PLC): *

- "Buffersize"="0x000012c0 (4800)"
- "Instances"="00 00 00 00 00 00 00 00
- "Motorola0"="Yes"
- "Name0"=""
- "NoLogin0"="No"
- "Project0"=hex (current communication parameters for the OPC server with project identifier)
- "Timeout0"="0x00002710 (1000)"
- "Tries0"="0x00000003 (3)"

[HKEY_LOKAL_MACHINE\SOFTWARE\3S-Smart Software Solutions GmbH\CoDeSys OPC\Config]

* corresponds to the values set in the dialog 'Settings for OPC server' of the OPC configurator (refer to OPC documentation, section 3.3.3.2 Settings for the OPC server): *

- "LogEvents"="No"
- "Multi"="no"
- "Public groups"="No"
- "Reconnect Interval"="0x00000005 (5)"
- "Sync startup"="yes"
- "Updaterate"="0x00000064 (100)"
- "Wait for target"="0x0000000a (10)"

[HKEY_LOCAL_MACHINE\SOFTWARE\3S-Smart Software Solutions GmbH\CoDeSys OPC\PLCDefaults]

* corresponds to the values entered at 'Edit' 'PLC Default Settings' of the OPC configurator (see OPC documentation, chapter 0)

"Menu <Edit>") *

- "Activ"="true"
- "Buffersize"="4800"
- "Motorola"="truee"
- "Nologin"="true"
- "project"=""
- "Reconnecttime"=10"
- "Timeout"="10000"
- "Tries"="3"
- "Waittime"="10"

3.4 Start of CoDeSysOPC.exe

The OPC server (and the gateway server) is automatically started by the operating system as soon as one of the clients establishes a connection. It is not necessary to start it explicitly. If an OPC server has already been started manually, the client automatically connects to the running server.

The server is automatically exited again as soon as all clients have cleared the connection.

While the OPC server is running, the icon is displayed on the right side of the status bar on the bottom of the screen.

Right-clicking on this icon displays information about the version of the OPC server.

Starting in test mode:

The connection between the OPC server and the client can also be tested if no controller is connected. For this purpose, the command

CoDeSysOPC.exe /TestMode

has to be entered to start the OPC server manually. The server then runs in test mode and automatically generates a series of test items which can be used to test the client communication.

 Caution: The items generated in test mode are only test variables. These are not the variables from the symbol file of your project.

The OPC icon in the status bar is also displayed while simulation mode is running.

3.5 End of CoDeSysOPC.exe

The OPC server is automatically exited as soon as all clients have cleared the connection.

3.6 Starting and ending of Gateway.exe

The gateway is automatically started by the operating system as soon as one of the subscribers (e.g. CoDeSys, OPC server, OPCConfig or similar) tries to access the gateway server.

The icon on the right side of the status bar on the bottom of the screen indicates that the gateway was started and whether it is in use or not.

Once the gateway is started, it stays opened. However, it is indicated whether it is in use or not. When the gateway is inactive, the icon is shaded in gray . It is not necessary to close the gateway.

If required, the gateway can be exited manually. To do so, right-click on the gateway icon to open the context menu. Select <Exit> to close the gateway server.