Professional Documents
Culture Documents
Note The Application Examples are not binding and do not claim to be complete
regarding the circuits shown, equipping and any eventuality. The Application
Examples do not represent customer-specific solutions. They are only intended
to provide support for typical applications. You are responsible for ensuring that
the described products are used correctly. These application examples do not
relieve you of the responsibility to use sound practices in application,
installation, operation and maintenance. When using these Application
Examples, you recognize that we cannot be made liable for any damage/claims
beyond the liability clause described. We reserve the right to make changes to
these Application Examples at any time without prior notice. If there are any
deviations between the recommendations provided in these application
examples and other Siemens publications – e.g. Catalogs – the contents of the
other documents have priority.
We do not accept any liability for the information contained in this document.
Any claims against us – based on whatever legal reason – resulting from the use of
the examples, information, programs, engineering and performance data etc.,
described in this Application Example shall be excluded. Such an exclusion shall
not apply in the case of mandatory liability, e.g. under the German Product Liability
Siemens AG 2013 All rights reserved
Caution:
The functions and solutions described in this article confine themselves to the
realization of the automation task predominantly. Please take into account
furthermore that corresponding protective measures have to be taken up in the
context of Industrial Security when connecting your equipment to other parts of the
plant, the enterprise network or the Internet. Further information can be found
under the Entry ID 50203404.
http://support.automation.siemens.com/WW/view/en/50203404
Table of Contents
Warranty and Liability ..............................................................................................2
1 Task.................................................................................................................4
2 Solution...........................................................................................................6
2.1 Solution overview ..............................................................................6
2.2 Description of the core functionality....................................................7
2.3 Hardware and software components used .........................................9
3 Function mechanisms of this application ................................................... 11
3.1 Overview of the process .................................................................. 11
3.2 Description of the STEP 7 V12 project ............................................. 12
3.2.1 Overview .........................................................................................12
3.2.2 FB DataMatrixCode (FB1) ............................................................... 14
3.2.3 FB OPC-Client_CON (FB2) ............................................................. 15
3.2.4 Call in the OB1: FB DataMatrixCode and FB OPC-Client_COM ....... 16
3.2.5 Global data block DB Data_Buffer (DB3) ......................................... 16
3.3 Communication of the S7 station with the PC via the OPC
interface ..........................................................................................17
3.4 Description of the surface of the MS Access database
“DB_DataMatrix”..............................................................................19
3.5 Description of the SIMATIC Basic Panel used.................................. 21
Siemens AG 2013 All rights reserved
1 Task
Introduction
For state-of-the-art production systems, the traceability of products and product
parts by means of a machine-readable identification is an essential requirement.
With an unambiguous coding, all the production processes can be planned and
carried out for every part produced, and changes in the production process or in
the materials used can be documented. The 2D codes are a coding technique
which makes it possible to identify products during manufacturing and to trace
them after they have been delivered.
MS Access database.
The figure below provides an overview of the automation task.
Figure 1-1
SIMATIC Basic
Panel
Copyright
PC-STATION
OPC-Server
Scan code SIMATIC PLC
MS Database Product
name
Requirements
This application should meet the following requirements:
A compact PLC from the S7-1200 series should be used.
MS Access should be used as a simple database.
The SIMATIC NET OPC server should be used as a communication
component between PC and PLC.
A simple database structure for recording every scan process
A simple database structure of a product table containing the information about
the corresponding scan code
Visualization of the complete procedure in a SIMATIC Basic Panel.
Siemens AG 2013 All rights reserved
Copyright
2 Solution
2.1 Solution overview
Display
The following figure gives a schematic overview of the most important components
of the solution:
Figure 2-1
MV340 6
2 1
User program of the
3 S7 CPU:
• FB DataMatrixCode
• FB OPC_Client_CON
CM1241 S7-1214C
Copyright
RS232
Contained components
Table 2-1
No. Component Description
1 S7-1200 CPU Any S7-1200 CPU can be used.
2 CM1241 RS232 Communication module, supports Freeport
3 MV340 Reader
4 PG/PC Programming device serving as the PC station:
SIMATIC NET
MS Office 2010
STEP 7 V12
5 SIMATIC Basic Panel Basic Panel for the visualization of the task. The
KTP1000 application is operated with the simulation of the
panel directly in the programming device.
6 User program of the S7- FB DataMatrixCode (FB1)
CPU FB OPC-Client_CON (FB2)
Note A detailed description of this function can be found from Chapter 3 onwards.
Siemens AG 2013 All rights reserved
Delimitation
This application does not include a basic description of
SIMATIC MV340. Please refer to document \9\.
STEP 7 V12 Please refer to documents \7\, \8\.
SIMATIC NET. Please refer to document \6\.
MS Office
SIMATIC HMI control panels Basic Panels Please refer to document \5\.
Basic knowledge of these topics is assumed.
Typical uses
This application example is suitable for production, logistics quality control and
maintenance and servicing. Application examples:
automotive industry
machine industry
tobacco industry
food industry
Hardware components
Table 2-2
Component No. Order number Note
Power supply 1 6EP1332-1SH71
PM1207
CPU 1214C 1 6ES7214-1AE30-0XB0 As an alternative, you can
DC/DC/DC also use a different
S7-1200 CPU from the
Copyright
Note A SIMATIC Basic Panel KTP1000 is not absolutely necessary. For simulating the
user interface, the PC runtime of STEP 7 V12 will be used.
2
Waiting for
new data
Searching
Data Data saved 5
uc
t the
received to the CPU od e
r
P am 4 database
n
Siemens AG 2013 All rights reserved
ND ID
R 3 rix
OPC at
M
commu-
nication
Copyright
The following table shows you which individual steps will be carried out throughout
the application example.
Table 3-1
No. Description
1. The configuration of the point-to-point connection (PORT_CFG) of the
communication module CM1241 RS232 is started:
automatically when the function block DataMatrixCode FB1 in the OB1 is called
for the first time.
when you click on INIT on the interface of the SIMATIC panel (HMI).
2. The function block DataMatrixCode receives scan codes from the MV340
(RCV_PTP) and evaluates them.
3. The function block OPC_Client_COM, which is the communication interface to the
OPC server, is triggered when data arrive.
4. The PC station searches the MS Access database (OPC client) for scanned
information (scan codes). In addition, the scanning process is recorded.
5. The OPC server transmits the product name back to PLC.
Introduction
The STEP 7 V12 project contains:
user program for the S7-CPU
– the function block DataMatrixCode (FB1)
– the function block OPC_Client_COM (FB2)
the configuration and setting of the PC station for the connection to the S7
station via OPC
configuration and settings of the SIMATIC Basic Panel.
Display
The following picture shows the program structure of the whole STEP 7 project.
Figure 3-2
PORT_CFG
Siemens AG 2013 All rights reserved
DataMatrixCode
(FB1)
RCV_PTP
OPC_Client_COM
(FB2) IDB
Copyright
(DB2)
PC Station
interface
OPC server
Data_Buffer
(DB3)
Program modules
The application program of the SIMATIC S7-1200 CPU consists of the following
elements:
Table 3-2
Element Symbolic name Description
OB1 Main In the OB1 the blocks DataMatrixCode (FB1)
and OPC_Client-COM (FB2) including the
corresponding instance data block
DataMatrixCode_DB (DB1) and
OPC_Client_COM_DB (DB2) are called
cyclically.
FB1 DataMatrixCode The FB DataMatrixCode (FB1) contains the
configuration of the communication module
CM1241, the receiving function and evaluation
of the scan codes.
CM1241 dynamically.
RCV_PTP Receive messages from the CM1241
Note Calling the PORT_CFG is optional and overwrites the settings of the hardware
configuration if you wish to change your communication settings dynamically.
Siemens AG 2013 All rights reserved
Copyright
Function
The FB DataMatrixCode (FB1) realizes
the configuration of the communication module CM1241
the receive function and evaluation of the scan code
Parameters
The following figure and table show the calling interface towards the user block FB
DataMatrixCode (FB1).
Figure 3-3
INPUT OUTPUT
Siemens AG 2013 All rights reserved
Table 3-3
Symbol Data type Description
EN BOOL Release input. Only relevant in FUP and KOP
PORT Uint ID of the communication port (HW-ID)
Copyright
INPUT
Function
The FB OPC_Client_COM (FB2) serves as communication interface towards the
OPC server and realizes the data exchange with the OPC client (MS Access
database).
Parameters
The following figure and table show the calling interface of the user block FB
OPC_Client_COM (FB2).
Siemens AG 2013 All rights reserved
Figure 3-4
INPUT OUTPUT
Copyright
Table 3-4
Symbol Data type Description
EN BOOL Release input. Only relevant in the FUP and
KOP depiction
ACT_Transfer BOOL Activates the transfer of the scan code to
INPUT
Program flow
The following diagram shows the basic function of the application example.
The diagram represents a complete sequence from the data source to the saving
of the scan code on the MC Access database and storage of the corresponding
product name into the PLC.
In this application example, the data exchange is carried out symbolically. All the
variables symbols defined in the data blocks of the S7 station are visible for the
OPC server and their authorizations (read/write, read, write or none) have been
Siemens AG 2013 All rights reserved
Figure 3-7
S7-1200
OPC client OPC server station
Connect
1
Copyright
Change detected
DataChange CMD=„1“ 3
The following table shows you the most important code fragments from the
documented VBA code.
Table 3-5
No. Description/code fragment
1. The connection to the OPC server is established (Connect).
5. The “Matrix_ID” (scan code) which is read from the PLC, is filed in the MS Access database
(Scanned_DMC).
Siemens AG 2013 All rights reserved
6. After the storage of the “Matrix_ID”, the OPC client looks for the corresponding product name in a
table of the MS Access database (Product_List) and writes it into the PLC (Write function).
Copyright
7. The OPC server resets the communication variable CMD=“0” (Write function).
Note For more information, please refer to the well documented VBA code.
OPC interface
For the realization of the functions described above, variables from the instance
data block OPC_CLient_COM_DB (DB2) and the global data block Data_Buffer
(DB3) are read/ observed/ described in the OPC client.
For the communication between the S7 station and the OPC client, the following
variables are used:
Table 3-6
OPC variable S7 variable OPC services
SIMATIC 1200 station_1.PLC_1. Data_Buffer_Matrix_ID synchronous
Data_Buffer_Matrix_ID reading
Figure 3-8
1 4
Copyright
2 3 5
6 7 8 9
Table 3-7
No. Element Description
1 Scanned Items List box:
This field shows all the read entries with a time stamp
and the corresponding product name.
Change language
Siemens AG 2013 All rights reserved
Matrix_Code
In this screen the application is operated.
, Open Support
Copyright
Change language
Quit Simulator
Support
Information about the Siemens Industry
Online Support
Change language
2
3
4
5 6 7
Siemens AG 2013 All rights reserved
Table 3-9
No. Element S7 variable Description
1. Scanned Code Data_Buffer_Matrix_ID Output box:
Scan code
2. Product Name Data_Buffer_Product_Name Output box:
Response of the OPC
Client with the product
name from the database
3. Server_STATUS OPC_Client_COM_DB_Server_ Output box:
Status Status of the OPC server
(see Table 3-10)
4. Transfer_STATUS OPC_Client_COM_DB_Comma Output box:
nd Status of the frame traffic
(see Table 3-10)
5. INIT Data_Buffer_INIT Button:
Activates the initialization
of the communication
module. Deletes all
entries.
4 Installation
ATTENTION The installation guidelines for S7-1200 must always be observed. Please
read the respective device manual \4\.
ATTENTION Before you switch on the power supply, complete and check the
installation!
24 V
MV340
Siemens AG 2013 All rights reserved
230 V > 5V
230 V
CM
PM 1207 1241 S7-1214C
Copyright
RS232
SIMATIC NET
OPC-Server
MS Access
OPC-Client
STEP 7 V12
PC-Station
Table 4-1
No. Action Note:
1. Insert the individual modules into a suitable Look at Table 2-2
module rack.
2. Connect the PM 1207 with the power When wiring the 24V, make sure that
supply system (230 V alternating current). the polarity is correct.
.
The necessary steps for the installation of the STEP 7 project are listed in the
following table:
Table 4-3
No. Approach:
1. The STEP 7 V12 project is available on the HTML page from, from where you
downloaded this document. Save the project “40603943_DataMatrixCode_S7-
1200_CODE_V20.zip” to your hard disk.
Copyright
Approach:
Select the S7-1200 CPU in the project navigation (Project tree).
In the toolbar, push the button
“Go online”.
Rightclick and select: “Online & diagnostics” of the S7-1200 CPU.
Select:
Siemens AG 2013 All rights reserved
Result:
The module might be reset to the operational mode STOP and reset to the
factory settings:
Copyright
The main memory and internal load memory and all the operand areas are
deleted
All parameters are reset to their standard values.
The diagnostics buffer is deleted.
The clock is reset.
The IP address is deleted. (The MAC address is firmly assigned and is never
changed.)
Note The IP address configured in the STEP 7 V12 project (TIA Portal) for the PC
station must match the IP address set in Windows. If you do not use a router, the
IP addresses of the PC station and of the S7-1200 CPU must be in the same
subnet.
Siemens AG 2013 All rights reserved
The figure below shows the network settings to which you have to change the PC
station.
Table 5-2
No. Action
1. Open the Internet Protocol (TCP/IP) Properties by selecting
“Start > Settings > Network Connection >Local Connections”.
Copyright
2. In the open window, select the Internet Protocol (TCP/IP) and open the Properties.
3. Select the option box “Use following IP address” and fill in the box as shown in the
picture. Close the dialog boxes with “OK”.
2. Enter the station names in the components configurator. The name of the PC
station must be the same in STEP 7 V12 project (TIA Portal) and in the station
configurator.
Siemens AG 2013 All rights reserved
3. In the components configurator, add the OPC server to slot 1 according to the
hardware configuration.
Copyright
4. In the components configurator, add the network card to slot 2 according to the
hardware configuration.
No. Action
5. In “Parameter assig.” select the interface used.
6. When the configuration has been loaded into the PC station (see Chapter 5.8) the
status in the components configurator must display the status of the two
components added, as shown in the picture.
Siemens AG 2013 All rights reserved
Copyright
Note The IP address configured in the STEP 7 V12 project (TIA Portal) for the
S7-1200 CPU must be in the same subnet as the IP address set in Windows.
Table 5-4
No. Action
1. Open the portal view of the TIA portal project.
Siemens AG 2013 All rights reserved
Copyright
No. Action
3. Under “Functions”, select “Assign IP address”. Click on the button “Accessible
devices”.
No. Action
Result:
The PLC_1 now owns the IP address stored in the project.
No. Action
1. Reset the reader to factory settings.
8 data bits
1 stop bit
Baud rate 57600
No parity
Copyright
Approach:
Start the TIA Portal.
Open the project view.
Open the project “DataMatrix_V12”
In the project navigation:
– Select “PLC_1 [CPU 1214C DC/DC/DC]”
– Rightclick and select:
“Download to device > Hardware and software”
Prerequisite:
The STEP 7 V12 project has been installed and retrieved (see Chapter 4.3).
The necessary settings for the PC station have already been made (see
Chapter 5.4).
Approach:
Start the TIA Portal.
Copyright
5.9 Creating the symbols for the SIMATIC NET OPC server
from the STEP 7 variables
Note The following settings need not be made in the application example any more,
they are already contained in the project. The present chapter is only for your
information.
Table 5-6
No. Action
1. In the TIA Portal, open the Device configuration of the Station PC_System_1.
2. In the device view, doubleclick on the OPC server. The “Properties” window opens
up.
Siemens AG 2013 All rights reserved
Copyright
No. Action
Siemens AG 2013 All rights reserved
Copyright
Approach:
Table 6-2
No. Approach:
1. Doubleclick on the file “MatrixCode.accdb” in Windows.
2. Doubleclick on the form “DB_DataMatrix”.
Siemens AG 2013 All rights reserved
3. In the column Matrix_Code, enter the 2D code and the corresponding product name
(or delete the entry).
Siemens AG 2013 All rights reserved
Result:
The table was changed.
6.4 Read DataMatrix code and find out the product name
The application can be operated easily and intuitively with the HMI interface
provided.
Prerequisite:
The MS Access database has been loaded.
the OPC server is active (see Chapter 6.2).
Approach:
Table 6-4
No. Approach:
1. With the MV340 reader, scan the codes of the Table 6-6.
2. In the window “Scanned Items”, the scan code will be displayed with the
corresponding product name.
Siemens AG 2013 All rights reserved
Copyright
Transfer_STATUS Transfer_ERROR
4. Transfer_STATUS and Server_STATUS will assume the values for the new order.
S7-1200
S7-400
Copyright
On the Siemens website \3\ you can create your own Data Matrix codes, which can
then be integrated into the MS Access database. You must adapt the Product_List
in the MS Access database (see Chapter 5.4).
7 Literature
7.1 Bibliography
This list is not complete and only represents a selection of relevant literature.
Table: 7-1
Subject Title
/1/ STEP7 Automating with SIMATIC S7-1200
SIMATIC S7-1200 Author: Hans Berger
Publicis MCD Verlag
ISBN: 978-3-89578-355-5
8 History
Table: 8-1
Version #Datum# Modifications
V1.0 01/2010 First version
V2.0 05/2013 Complete revision
07/2013 Table 2-2 has been changed
Siemens AG 2013 All rights reserved
Copyright