You are on page 1of 43

Cover

Measurement and Sensors: Reading


Data Matrix Codes With S7-1200 and
archiving them in an MS Access
Database
S7-1200 Set 27

Application Description July 2013

Applications & Tools


Answers for industry.
Warranty and Liability

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

Act (“Produkthaftungsgesetz”), in case of intent, gross negligence, or injury of life,


body or health, guarantee for the quality of a product, fraudulent concealment of a
deficiency or breach of a condition which goes to the root of the contract
(“wesentliche Vertragspflichten”). The damages for a breach of fundamental
contractual obligations are, however, limited to the foreseeable damage, typical for
the type of contract, except in the event of intent or gross negligence or injury to
life, body or health. The above provisions do not imply a change of the burden of
proof to your detriment.
Copyright

Any form of duplication or distribution of these Application Examples or excerpts


hereof is prohibited without the expressed consent of Siemens Industry Sector.

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

Reading Data Matrix Codes and archiving them in a Database


2 V2.0, Entry ID: 40603943
Table of Contents

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

3.6 Transfer and server status ............................................................... 23


4 Installation ....................................................................................................24
4.1 Hardware setup ...............................................................................24
4.2 Software installation......................................................................... 25
4.3 Installation of the STEP 7 V12 project .............................................. 25
5 Starting up the application...........................................................................26
5.1 Set factory settings S7-1200 CPU.................................................... 26
5.2 IP addresses used ...........................................................................27
Copyright

5.3 Change IP address of the PC station ............................................... 27


5.4 Configuration of the PC station ........................................................ 28
5.5 Change IP address of the PC station ............................................... 30
5.6 Configuration of the MV340 reader .................................................. 32
5.7 Load the STEP 7 V12 project into the S7 CPU................................. 33
5.8 Loading the configuration into the PC station ................................... 33
5.9 Creating the symbols for the SIMATIC NET OPC server from
the STEP 7 variables ....................................................................... 34
6 Operation of the Application........................................................................ 36
6.1 Start the HMI simulation................................................................... 36
6.2 Open OPC Client / MS Access database ......................................... 37
6.3 Change the contents of the “Product_List” ....................................... 38
6.4 Read DataMatrix code and find out the product name ...................... 39
6.5 Error states......................................................................................40
6.6 Example codes................................................................................41
7 Literature ......................................................................................................42
7.1 Bibliography.....................................................................................42
7.2 Internet link specifications................................................................ 42
8 History ..........................................................................................................43

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 3
1 Task

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.

Overview of the automation task


At the incoming goods department of a company, a reader should record the goods
received and transmit the data to a SIMATIC S7 station. For the identification of the
recorded products, the S7 station should pass on the code that was scanned to a
PC station via an OPC server. The scan code is archived in an MS Access
database, which is searched for a product name of a code that has been read in
(scan code).
The OPC server transmits the product name back to the S7 station.
The scanning of the every product should be recorded with a time stamp in the
Siemens AG 2013 All rights reserved

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

Reading Data Matrix Codes and archiving them in a Database


4 V2.0, Entry ID: 40603943
1 Task

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

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 5
2 Solution
2.1 Solution overview

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

SIMATIC Basic Panel PC station


KTP1000
4 SIMATIC NET
5
OPC-Server
MS Access
OPC-Client
STEP 7 V12
Siemens AG 2013 All rights reserved

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)

Reading Data Matrix Codes and archiving them in a Database


6 V2.0, Entry ID: 40603943
2 Solution
2.2 Description of the core functionality

2.2 Description of the core functionality


Realized functions
The following functions have been realized in the application example:
S7 station:
Configuration of the point-to-point connection of the communication module
CM1241 RS232
Receiving of the code from MV340 from the CM1241 and storing it in a data
block
PC station:
Using an MS Access database, in which an OPC client has been realized in
VBA for the communication with the PLC.
Monitoring the communication between the PC and the PLC.
Visualization of the scanning procedure “on site”

Note A detailed description of this function can be found from Chapter 3 onwards.
Siemens AG 2013 All rights reserved

Surface of the MS Access database “DB_DataMatrix”


The following picture shows the surface of the MS Access database used.
A detailed description can be found in Chapter 3.4.
Figure 2-2
Copyright

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 7
2 Solution
2.2 Description of the core functionality

User interface in the SIMATIC Basic Panel


The following picture shows the user surface of the panel used. A detailed
description can be found in Chapter 3.5.
Figure 2-3
Siemens AG 2013 All rights reserved
Copyright

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.

Operating the Application


all S7-1200 CPUs from the SIMATIC product range
STEP 7 V12
WINCC Basic V12
MS Office 2010
SIMATIC NET SOFTNET-IE S7 V8.2
Windows 7

Reading Data Matrix Codes and archiving them in a Database


8 V2.0, Entry ID: 40603943
2 Solution
2.3 Hardware and software components used

Advantages of this solution


Reusable STEP 7 and VBA codes. They can be adapted easily for extensions.
The communication between the PLC and the PC has been realized in a
separate block in the project and can also be used for other applications.

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

2.3 Hardware and software components used


The application was set up with the following components:
Siemens AG 2013 All rights reserved

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

SIMATIC product range.


Communication 1 6AG1241-1AH30-4XB0
module
CM1241 RS232
SIMATIC MV340 1 6GF3340-0HT01
reader
RS232 Cable 1 6GF3 020-0AC40-0AC4
(EU)
6GF3 020-0AC40-0AC3
(US)

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.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 9
2 Solution
2.3 Hardware and software components used

Standard software components


Table: 2-3
Component No. Order number Note
TIA Portal V12 1 6ES7822-1AE02-0YA5
SIMATIC NET 1 6GK1704-1CW08-2AA0
SOFTNET-IE S7 V8.2
MS Access 2010 1 www.office.microsoft.com

Sample files and projects


The following list includes all files and projects used in this example.
Table: 2-4
Component Note
40603943_DataMatrixCode_S7-1200_CODE_V20.zip This zip-file contains
the STEP 7 project and
the MS Access
database.
Siemens AG 2013 All rights reserved

40603943_DataMatrixCode_S71200_DOKU_V20_de.pdf This document.


Copyright

Reading Data Matrix Codes and archiving them in a Database


10 V2.0, Entry ID: 40603943
3 Function mechanisms of this application
3.1 Overview of the process

3 Function mechanisms of this application


3.1 Overview of the process
The following picture shows you the program for this application:
Figure 3-1 Overview of the functionality
Start
Initialization
S7 1 PC
station Port station
configuration
NE
DO

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.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 11
3 Function mechanisms of this application
3.2 Description of the STEP 7 V12 project

3.2 Description of the STEP 7 V12 project


3.2.1 Overview

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

Main (OB1) CALL


IDB HMI-Panel
(DB1) interface

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.

Reading Data Matrix Codes and archiving them in a Database


12 V2.0, Entry ID: 40603943
3 Function mechanisms of this application
3.2 Description of the STEP 7 V12 project

Element Symbolic name Description


FB2 OPC_Client_COM The FB OPC_Client_COM (FB2) serves as
the communication interface to the OPC
server. A timer checks whether there is a
communication to the OPC server.
DB3 Data_Buffer Global data block for storing the code that was
read out most recently and its product name.
DB1 DataMatrixCode_DB Instance data block of the block
DataMatrixCode (FB1)
DB2 OPC_Client_COM_DB Instance data block of the block
OPC_Client_COM (FB2)
R_TRIG Set variable at positive signal edge
PORT_CFG Configure communication parameters of the
System
blocks

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

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 13
3 Function mechanisms of this application
3.2 Description of the STEP 7 V12 project

3.2.2 FB DataMatrixCode (FB1)

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

INIT BOOL Activates the port configuration and the


resetting of all the parameters
Reacts to a positive edge
ENO BOOL Release output. Only relevant in the FUP and
KOP depiction
NDR BOOL Is activated when new data arrived.
OUTPUT

Only TRUE for one cycle


Default value: FALSE
ERROR BOOL Is set when the block PORT_CFG
or RCV_PTP was closed with an error.
Remains at TRUE as long as the ERROR is
pending at the blocks called.

Reading Data Matrix Codes and archiving them in a Database


14 V2.0, Entry ID: 40603943
3 Function mechanisms of this application
3.2 Description of the STEP 7 V12 project

Symbol Data type Description


STATUS DWord Indicates the values of the errors pending for
evaluation if ERROR=TRUE.
Structure:
16#0001_xxxx: Status of the instruction
PORT_CFG (Online Help in STEP 7)
16#0011_xxxx: Status of the instruction
RCV_PTP (Online Help in STEP 7)

3.2.3 FB OPC-Client_CON (FB2)

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

the OPC client and the search for the


corresponding data set in the MS Access
database.
Reacts to a positive edge
ENO BOOL Release output Only relevant in the FUP and
KOP depiction
DONE BOOL Is set when the search for the corresponding
OUTPUT

data set in the MS Access database and the


transmission of the product name to the PLC via
the SIMATIC NET OPC server was successful.
Remains at TRUE, until REQ is set.
Default value: FALSE

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 15
3 Function mechanisms of this application
3.2 Description of the STEP 7 V12 project

3.2.4 Call in the OB1: FB DataMatrixCode and FB OPC-Client_COM

The calling of the program blocks DataMatrixCode and OPC-Cient_COM in the


OB1 is shown in the following picture: Only when new data arrive at the reader is
the FB OPC_Client_COM started.
Figure 3-5
Siemens AG 2013 All rights reserved
Copyright

3.2.5 Global data block DB Data_Buffer (DB3)

The following data are stored in the Data_Buffer:


input parameters for the calling of the function blocks in OB1
scan code (RCV_DATA and Matrix_ID)
– RCV_DATA: data received from CM1241
– Matrix_ID: received data converted into string
corresponding product name for the MS Access database
Figure 3-6

Reading Data Matrix Codes and archiving them in a Database


16 V2.0, Entry ID: 40603943
3 Function mechanisms of this application
3.3 Communication of the S7 station with the PC via the OPC interface

3.3 Communication of the S7 station with the PC via the


OPC interface
Introduction
This chapter shows how the data can be read from the PLC via the OPC interface
or can be written into the PLC.
Microsoft Access as the OPC client initiates the communication via the OPC
interface and provides the OPC server with reading/writing requests. The OPC
server carries out these reading and/or writing requests.

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

defined (see Chapter 5-9).

Figure 3-7
S7-1200
OPC client OPC server station

Connect
1
Copyright

Create groups and items


2
Change to CMD?
.
.
Change to CMD?

Change detected
DataChange CMD=„1“ 3

4 Read Matrix_ID Read Matrix_ID from the DB-


buffer
Data_
Buffer
Search ID Reply: Matrix_ID
MS Access 6
DB 5 Write Productname
Write product name in the DB buffer
Found
Data_
Productname 7 Buffer
Write CMD=“0”
ResetCMD

The following table shows you the most important code fragments from the
documented VBA code.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 17
3 Function mechanisms of this application
3.3 Communication of the S7 station with the PC via the OPC interface

Table 3-5
No. Description/code fragment
1. The connection to the OPC server is established (Connect).

2. New groups and items are created.

3. The CPU has received data from the reader.


4. The OPC client detects the change of data CMD=“1” (DataChange function) and reads (Read
function) the “Matrix_ID” from the PLC.

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.

Reading Data Matrix Codes and archiving them in a Database


18 V2.0, Entry ID: 40603943
3 Function mechanisms of this application
3.4 Description of the surface of the MS Access database “DB_DataMatrix”

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

SIMATIC 1200 station_1.PLC_1. Data_Buffer_Product_Name synchronous writing


Data_Buffer_Product_Name
SIMATIC 1200 station_1.PLC_1. OPC_Client_COM_DB_cmd observing the
OPC_Client_COM_DB_Command variable

3.4 Description of the surface of the MS Access database


“DB_DataMatrix”
Siemens AG 2013 All rights reserved

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.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 19
3 Function mechanisms of this application
3.4 Description of the surface of the MS Access database “DB_DataMatrix”

No. Element Description


2 Delete all Items Button:
All the entries are deleted from the table
3 Export Items Button:
A PDF file is exported from the table
4 Product_List List box:
Shows all the available scan codes and product
names from the table “Product_List”.
5 Refresh Button:
Refreshes the list box “Product_List”.
6 Connect Button:
Creates the connection to the OPC server.
7 Disconnect Button:
Interrupts the connection to the OPC server.
8 SERVER status Text box:
shows the servers status:
Connected
Disconnected
9 Transfer status Text box:
shows the status of the frame traffic:
Siemens AG 2013 All rights reserved

Wait for command


No Data can be received/sent
Transfer_START
Transfer_READY
Transfer_ERROR
Copyright

Reading Data Matrix Codes and archiving them in a Database


20 V2.0, Entry ID: 40603943
3 Function mechanisms of this application
3.5 Description of the SIMATIC Basic Panel used

3.5 Description of the SIMATIC Basic Panel used


Overview
The application is operated via a configured SIMATIC Basic Panel KTP 1000.
Table 3-8
Name/description Note
Start screen
This screen opens up automatically when
the HMI Simulator has been started.
Read Matrix Code:
Open the Matrix_Code application
Support:
Open the support information

Change language
Siemens AG 2013 All rights reserved

Matrix_Code
In this screen the application is operated.

Open start screen

, Open Support
Copyright

Change language

Quit Simulator
Support
Information about the Siemens Industry
Online Support

Open start screen

Change language

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 21
3 Function mechanisms of this application
3.5 Description of the SIMATIC Basic Panel used

Description of the user interface in the SIMATIC Basic Panel


Figure 3-9

2
3
4

5 6 7
Siemens AG 2013 All rights reserved

For the visualization, variables of the instance data blocks DataMatrixCode_DB


(BD1), OPC_Client_COM_DB (DB2) and the global data blocks Data_Buffer (DB3)
are integrated in WinCC. In the screen Matrix_Code the following variables are
used:
Copyright

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.

Reading Data Matrix Codes and archiving them in a Database


22 V2.0, Entry ID: 40603943
3 Function mechanisms of this application
3.6 Transfer and server status

No. Element S7 variable Description


6. ERROR DataMatrixCode_DB_ERROR Display element
On: Error
Off: OK
7. STATUS DataMatrixCode_DB_STATUS Output box:
Status word of the FB
DataMatrixCode (FB1)
(see Table 3-3)

3.6 Transfer and server status


For the connection to the OPC server and for the data traffic, the block FB
OPC_Client_COM (FB2) has two outputs:
Transfer_STATUS
Server_STATUS
Table 3-10
Transfer STATUS SERVER status Description
Transfer_START Wait for Reply Start the procedure.
Siemens AG 2013 All rights reserved

Waiting for response from the


OPC client
Transfer_READY Server Connected Procedure terminated
successfully.
Connection to the OPC server.
MatrixID not found Server Connected Procedure terminated
successfully. The scan code was
not found in the list “Product_List”
Copyright

Connection to the OPC server.


Transfer_ERROR Server not Connected Connection to the OPC server. No
product description was transmitted.
Download MS Access database
(Chapter 6.2)
Check the “Server_Status” on the
surface of the MS Access
database.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 23
4 Installation
4.1 Hardware setup

4 Installation

4.1 Hardware setup


The required hardware components are listed in Chapter 2.3 (Hardware and
software components used).

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!

The figure below shows the hardware setup of the application.


Figure 4-1

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.
.

Reading Data Matrix Codes and archiving them in a Database


24 V2.0, Entry ID: 40603943
4 Installation
4.2 Software installation

No. Action Note:


3. Inter-connect the following PROFINET interfaces:
PROFINET interface of the PC station with the PROFINET interface of the
S7-CPU
RS232 interface of the MV340 with the RS232 interface of the communication
module CM1241

4.2 Software installation


Table 4-2
No. Action Note:
1. Install TIA V12
2. Install WinCC Basic V12 Follow the instructions of the installation
program.
3. Install SIMATIC NET
4. Install the Microsoft Office 2010

4.3 Installation of the STEP 7 V12 project


Siemens AG 2013 All rights reserved

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

2. Unpack the project.


3. Open the TIA Portal V12 and retrieve the
STEP 7 V12 project.
“Project > Retrieve” (“Project > Retrieve”).

If you have opened the project already, it


will be closed when the message pops up.

4. Navigate to “40603943_DataMatrixCode_S7-1200_CODE_V20.zap12” and open


the file.
5. Select any project storage path. Confirm with “OK”.
6. Now the project is at your disposal.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 25
5 Starting up the application
5.1 Set factory settings S7-1200 CPU

5 Starting up the application


5.1 Set factory settings S7-1200 CPU
Before you begin with the commissioning of the application, the S7-1200 CPU must
have the factory settings.
Under the following circumstances you can reset the S7-1200 to the original factory
settings:
No memory card is inserted in the CPU.
The CPU is in the operational mode STOP.

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

“Functions > Reset to factory settings > Delete IP address“.


Check the box “Delete IP address”.
Click the “Reset” button.

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.)

Reading Data Matrix Codes and archiving them in a Database


26 V2.0, Entry ID: 40603943
5 Starting up the application
5.2 IP addresses used

5.2 IP addresses used


The following table provides an overview of the IP addresses used in this sample
program.
Table 5-1
Module IP address
CPU 1214 192.168.0.2
PC station 192.168.0.5
SIMATIC Basic Panel KTP1000 192.168.0.9

5.3 Change IP address of the PC station

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”.

4. If your PG has an IWLAN interface, switch it off.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 27
5 Starting up the application
5.4 Configuration of the PC station

5.4 Configuration of the PC station


You need the components configurator for the initial configuration of your PC
station. This application assumes that there is no PG/PC configured on your PC
station.
Table 5-3
No. Action
1. Open the component configuration with the
symbol in the Windows task bar.

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.

Reading Data Matrix Codes and archiving them in a Database


28 V2.0, Entry ID: 40603943
5 Starting up the application
5.4 Configuration of the PC station

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

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 29
5 Starting up the application
5.5 Change IP address of the PC station

5.5 Change IP address of the PC station


Before the STEP 7 project can be loaded into the CPU, the IP address of the
S7-1200 CPU with which you can the project into the CPU, must be changed.

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

2. First open the tree for PLC_1


and then double-click on the
function “Online & diagnostic”.

Reading Data Matrix Codes and archiving them in a Database


30 V2.0, Entry ID: 40603943
5 Starting up the application
5.5 Change IP address of the PC station

No. Action
3. Under “Functions”, select “Assign IP address”. Click on the button “Accessible
devices”.

4. If necessary, select the PG / PC interface. The search for accessible devices is


carried out automatically. The result is shown in a list. Identify the PLC you use as
PLC_1 via the MAC address and click on “Apply”
Siemens AG 2013 All rights reserved
Copyright

5. Assign the IP address stored in the project with “Assign IP address”.

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 31
5 Starting up the application
5.6 Configuration of the MV340 reader

No. Action
Result:
The PLC_1 now owns the IP address stored in the project.

5.6 Configuration of the MV340 reader


Before you use it for the first time, the reader must be set up. The setting of the
MV340 reader is carried out by scanning special codes. Scan the following codes
one after another. After every Data Matrix code, wait for the Feedback from the
reader.
Table 5-5
Siemens AG 2013 All rights reserved

No. Action
1. Reset the reader to factory settings.
8 data bits
1 stop bit
Baud rate 57600
No parity
Copyright

2. Save the changes.

3. Set the baud rate to 4800 bits per


second.

Please note: The baud rate of the reader


must match the baud rate set in the
communication module.

4. Save the changes.

Reading Data Matrix Codes and archiving them in a Database


32 V2.0, Entry ID: 40603943
5 Starting up the application
5.7 Load the STEP 7 V12 project into the S7 CPU

5.7 Load the STEP 7 V12 project into the S7 CPU


Prerequisite:
The STEP 7 V12 project has been installed and retrieved (see Chapter 4.3).
The PC station is connected to S7-1200 CPU via the PROFINET interface.

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”

5.8 Loading the configuration into the PC station


Siemens AG 2013 All rights reserved

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

Open the project view.


Open the project “DataMatrix_V12”
In the project navigation:
– Select “PC_System_1[SIMATIC PC Station]”
– Rightclick and select:
“Download to device > Hardware configuration”

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 33
5 Starting up the application
5.9 Creating the symbols for the SIMATIC NET OPC server from the STEP 7 variables

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

3. In the menu “S7 > OPC tags”, click on configuration.

Confirm with “OK”.


4. Select all the S7 variables from which the symbols of the SIMATIC NET OPC server
are to be created, and confirm with “OK”.

Reading Data Matrix Codes and archiving them in a Database


34 V2.0, Entry ID: 40603943
5 Starting up the application
5.9 Creating the symbols for the SIMATIC NET OPC server from the STEP 7 variables

No. Action
Siemens AG 2013 All rights reserved
Copyright

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 35
6 Operation of the Application
6.1 Start the HMI simulation

6 Operation of the Application


Introduction
In this chapter you will learn how to operate the functions of this application
described above.
The operation of the application is carried out
with a configured SIMATIC Basic Panel KTP1000 or higher
with the simulation of the panel directly in the programming device.

6.1 Start the HMI simulation


Table 6-1
No. Approach:
1. Open the STEP 7 V12 project “MatrixCode_V12”.
2. Start the simulation of the SIMATIC Basic Panel KTP1000.
Siemens AG 2013 All rights reserved
Copyright

3. Open the operating screen “DataMatrixCode”


“Startscreen > Read Matrix Code”.

Reading Data Matrix Codes and archiving them in a Database


36 V2.0, Entry ID: 40603943
6 Operation of the Application
6.2 Open OPC Client / MS Access database

6.2 Open OPC Client / MS Access database


Prerequisite:
The STEP 7 V12 project has been installed and retrieved (see Chapter 4.3).

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

The communication to the OPC server is set up automatically.


Result:
The MS Access database is now ready for operation. The connection to the OPC
server has been established (see SERVER status).
Copyright

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 37
6 Operation of the Application
6.3 Change the contents of the “Product_List”

6.3 Change the contents of the “Product_List”


The following table shows how to add more products to the table “Product_List” or
delete products from the table.
Table 6-3
No. Approach:
1. Open the project MatrixCode.accdb.
2. Doubleclick on the table “Product_List”.

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

4. Close the table “Product_List”.


5. On the surface of the MS Access database “DB_DataMatrix”, click on “Refresh”.
Copyright

Result:
The table was changed.

Reading Data Matrix Codes and archiving them in a Database


38 V2.0, Entry ID: 40603943
6 Operation of the Application
6.4 Read DataMatrix code and find out the product name

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

The box “transfer status” shows the status of the transmission.


Result:
The data can be observed in three places
User interface OPC Client / MS Access database
User interface in the SIMATIC Basic Panel
Data block “Data_Buffer” in STEP 7

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 39
6 Operation of the Application
6.5 Error states

6.5 Error states


The reasons could be the following:
no connection to the OPC server.
the MS Access database has not been loaded.
The following table shows an example for such a situation.
Table 6-5
No. Approach:
1. With the MV340 reader, scan one of the codes in table 5-3.
2. The S7 PLC waits for a reply from the OPC client.
Siemens AG 2013 All rights reserved

Server_STATUS Wait for Reply


Transfer_STATUS Transfer_START
3. A timer (5 sec) supervises the transmission of the product name. If no data arrive
within the 5 sec, the process is terminated.
Server_STATUS Server not Connected
Copyright

Transfer_STATUS Transfer_ERROR

4. Transfer_STATUS and Server_STATUS will assume the values for the new order.

Reading Data Matrix Codes and archiving them in a Database


40 V2.0, Entry ID: 40603943
6 Operation of the Application
6.6 Example codes

6.6 Example codes


Here are some sample codes and the corresponding product names for a
transmission test:
Table 6-6
DataMatrix Code
Product description

S7-300 STEP 7 V5.5


Siemens AG 2013 All rights reserved

S7-1200
S7-400
Copyright

STEP 7 V11 S7-1500

STEP 7 V12 Read System

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).

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 41
7 Literature
7.1 Bibliography

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

7.2 Internet link specifications


The following list is by no means complete and only provides a selection of
appropriate information.
Table: 7-2
Subject Title
Siemens AG 2013 All rights reserved

/1/ Link to this document http://support.automation.siemens.com/WW/view/en/406


03943
/2/ Siemens Industry http://support.automation.siemens.com
Online Support
/3/ Data Matrix Code https://www.automation.siemens.com/mcms/industrial-
Generator sensors/de/code-lesesysteme/Seiten/default.aspx

/4/ SIMATIC S7 S7-1200 http://support.automation.siemens.com/WW/view/en/36932465


automation system
Copyright

/5/ SIMATIC HMI control http://support.automation.siemens.com/WW/view/en/31032678


panels Basic Panels
/6/ SIMATIC NET http://support.automation.siemens.com/WW/view/en/61630140
Industrial
communication with
PG/PC Volume 2 -
Interface Programming
Manual
/7/ STEP 7 BasicV12 http://support.automation.siemens.com/WW/view/en/68113678
/8/ STEP 7 Professional http://support.automation.siemens.com/WW/view/en/68113685
V12
/9/ SIMATIC MV340. http://support.automation.siemens.com/WW/view/en/61909865

Reading Data Matrix Codes and archiving them in a Database


42 V2.0, Entry ID: 40603943
8 History

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

Reading Data Matrix Codes and archiving them in a Database


V2.0, Entry ID: 40603943 43