FTP Data Exchange between FTP Server and a SIMATIC S7-1200 Controller
Application Description October 2013
Applications & Tools Answers for industry.
Warranty and Liability
Warranty and Liability Note
The Application Examples are not binding and do not claim to be complete with regard to configuration, equipment or any contingencies. The application examples do not represent customer-specific solutions; they are only intended to provide support for typical applications. You are solely responsible for the correct operation of the described products. These application examples do not relieve you of the responsibility to use sound practices in application, installation, operation and maintenance. Through using these Application Examples, you acknowledge that we will not be 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 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 a substantial contractual obligation 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 in the burden of proof to your disadvantage.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Any form of duplication or distribution of these Application Examples or excerpts hereof is prohibited without the express consent of Siemens Industry Sector.
t h g i r y p o C
Caution The functions and solutions described in this entry predominantly confine themselves to the realization of the automation task. Please also take into account that corresponding protective measures have to be taken in the context of Industrial Security when connecting your equipment to other parts of the plant, the enterprise network or the Internet. For more information, please refer to Entry ID 50203404. http://support.automation.siemens.com/WW/view/en/50203404
Siemens Industry Online Support This entry is from the Siemens Industry Online Support. The following link will take you directly to the download page of this document: http://support.automation.siemens.com/WW/view/en/81367009
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
2
Table of Contents
Table of Contents Warranty and Liability ................................................................................................. ................................................................................................. 2 1
Task ...................................................................................................... ..................................................................................................................... ............... 4
2
Solution............................................................................................................... Solution............................................................................. .................................. 6 2.1 2.2 2.2.1 2.2.2 2.3 2.3.1 2.3.2
3
Basics ............................................................................................................. ............................................................................................................... .. 13
4
Mode of Operation ...................................................................... ........................................................................................... ..................... 14 4.1 4.2
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Overview............................................................................................... 6 Overview............................................................................................... Core functionality ............................................................ .................................................................................. ...................... 8 Principle of the core functionality ......................................................... 8 Overview of the us er interface ........................................................... 10 Hardware and software components ................................................. 11 Validity ................................................................................................ ................................................................................................ 11 Components used .............................................................................. .............................................................................. 11
4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.3 5
Installation and Commissioning .................................................................... .................................................................... 28 5.1 5.2 5.3 5.3.1 5.3.2 5.3.3
t h g i r y p o C
6
Overview............................................................................................. 14 Overview............................................................................................. Description of scenario 1: sending process data to an FTP server.................................................................................................. server.................................................................. ................................ 17 Details on the FTP function block: FTP_1200_CMD ......................... 17 Details on FB “SEND_DATA” ..................................................... ............................................................. ........ 20 Details on FB “GENERATE_DATA” “G ENERATE_DATA” ................................................... 21 Details on FB “GENERATE_FILENAME” .......................................... 21 Details on the used data types and constants ................................... 22 Description of scenario 2: receiving process data from an FTP server.................................................................................................. server................................................................... ............................... 25
Hardware installation ...................................................... .......................................................................... .................... 28 Installation of the software.................................................................. 29 Commissioning ................................................................................... ................................................................................... 29 FTP server ........................................................... .......................................................................................... ............................... 29 S7-1200 controller and HMI ............................................................... 31 Adapting the S7 program ................................................................... ................................................................... 34
Operating the Application ........................................................... ............................................................................... .................... 35 6.1 6.2 6.3 6.4
Menu navigation ................................................................................. ................................................................................. 35 Scenario 1 (storing data) .................................................................... .................................................................... 36 Scenario 2 (fetching data) .................................................................. .................................................................. 37 Settings............................................................................................... Settings................................................................ ............................... 38
7
Related Literature and Links .......................................................................... .......................................................................... 39
8
History............................................................................................................... History..................................................................... .......................................... 39
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
3
1 Task
1
Task
Introduction The widely distributed FTP (File Transfer Protocol) offers you the possibility of filing data on almost any server system of all the known operating systems. All S7-300/400/1500 controller families already have the option of operating FT P communication via special CPs (communication processors). This application shows how an S7-1200 can also use FTP.
Overview of the automation task The following figure provides an overview of the automation task. Figure 1-1
Integration of S7-1200 in existing FTP environment d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
FTP server
F T P
PROFINET / IE
t h g i r y p o C
+ S7-300 with CP 343-1
S7-400 with CP 443-1
S7-1500 with CP 1543-1
S7-1200
Standard solution
Description In many projects and on many systems it is necessary to exchange process data between controller and servers/PCs, in order to enable working with the there produced data outside of the control level as well. This is made possible by standardized protocols. FTP is a simple protocol which works according to the client-server principle and fulfills this task. So far, users were able to exchange process data with FTP via an FTP server using S7-300/400/1500 and using a communication processor. With this application, the S7-1200 is included into the existing FTP environment.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
4
1 Task
Requirements of the automation task The following table shows the automation requirements for this application. Table 1-1 Requirement
Explanations
Saving data from the S7-1200 controller on the server
Scenario 1 shall demonstrate how process data can be loaded from the controller to a server using an FTP block.
Requesting data from the FTP server of S7-1200
Scenario 2 shall demonstrate how data (e.g. recipes) can be loaded from a server into the controller using an FTP block.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
5
2 Solution 2.1 Overview
2
Solution
2.1
Overview
Display The following figure gives a schematic overview of the most important components of the solution and its interconnection: Figure 2-1
FTP server: FTP server software with file storage •
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
PROFINET / IE
FTPclient - S7-1200 controller: S7 program with FTP function block “FTP_1200_CMD FTP_1200_CMD”” and process data •
HMI: HMI screen •
t h g i r y p o C
Note
The FTP function block (FTP_1200_CMD ( FTP_1200_CMD)) is delivered with the example pr oject of this application. This block enables the FTP data exchange.
Description In order to operate FTP communication without CP, a function block (FTP_1200_CMD) must map the FTP in the S7-CPU. The block must establish logic connections from a controller to FTP servers as well as send and receive commands and data taking into consideration the FTP. In this application, two scenarios are explained which illustrate using the above mentioned block.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
6
2 Solution 2.1 Overview Advantages The solution presented here offers you the following advantages: •
•
•
Simple and easy to understand FTP communication with an S7-1200 via via the “FTP_1200_CMD” block. The command set of the block corresponds to that of the FTP communication via S7-300/400/1500 controller (with CP). Expandability of the example application by some process data and different FTP servers. Illustration of the data exchange by an HMI operation.
Topics not covered This application does not contain a description of:
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
•
SCALANCE products
•
FTP servers
•
HMI panels
•
PLCs (especially S7-1200)
•
SCL programming
Basic knowledge of these topics is assumed.
The FTP function block delivered with this application exclusively fulfils FTP client functions
Note
Assumed knowledge
t h g i r y p o C
Basic knowledge of STEP 7 V12, WinCC V12, FUP, SCL, Ethernet and TCP/IP is assumed.
Comparing the most important FTP features in the SIMATIC S7 environment Table 2-1 FTP feature
S7-300/400
S7-1500
S7-1200
(CP 343-1 / 443-1)
(CP 1543-1)
10/20
32
4
FTP active
FTP passive
FTPS
Full S7-FTP command set
Via CP
FTP server Number of parallel client connections
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
7
2 Solution 2.2 Core functionality
2.2
Core functionality The example project for this application contains two scenarios:
2.2.1
•
Scenario 1: transferring process data to the FTP server
•
Scenario 2: retrieve data from the FTP server
Sequence of the core functionality The following figure shows the schematic sequence of the entire application: Figure 2-2
5
Wait for the new trigger
1
START
Connecting with FTP server d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
2
No Connected?
Yes Trigger data exchange
t h g i r y p o C
3
Data sent/ received?
No
Activate error display Terminate program sequence Display specific status (depending on error)
Activate OK display Terminate program sequence Display specific status (OK; 0000)
Yes Disconnect from FTP server
4
Properly Properly disconnected?
No
Yes
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
8
2 Solution 2.2 Core functionality Table 2-2 Action
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Note
1.
After a start trigger was output with “START”, the PLC connects with the FTP server
The connection data are entered via the user interface (IP address, User name, Password)
2.
The program checks the connection status: OK: triggers sending or receiving the data NOK: terminates the program sequence outputs the e rror-specific status
For NOK, the red display lights up in the HMI interface
3.
The program checks the data exchange: OK: triggers the disconnection process NOK: terminates the program sequence and outputs the error-specific status
For NOK, the red display lights up in the HMI interface
4.
The program checks the proper disconnection process: OK: terminates program sequence and outputs the status; job completed successfully; wait until job triggered again. NOK: terminates the program sequence and outputs the error-specific status
For OK, the green display lights up. For NOK, the red display lights up.
5.
Wait for the new trigger
t h g i r y p o C
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
9
2 Solution 2.2 Core functionality
2.2.2
Overview of the user interface
Scenario 1 The figure below shows the user interface for scenario 1 Figure 2-3
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
Scenario 2 The figure below shows the user interface for scenario 2 Figure 2-4
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
10
2 Solution 2.3 Hardware and software components
2.3
Hardware and software components
2.3.1
Validity This application is valid for
2.3.2
•
STEP 7 Professional as of V12 SP1
•
WinCC Professional as of V12 SP1
•
S7-1200 controller
•
common FTP servers
Components used This application has been generated using the following components:
Hardware components Table 2-3 d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Component
No.
Order number
Note
SIMATIC S7-1200 CPU 1214C DC/DC/DC
1
6ES7 214-1AG31-0XB0
Alternatively, any other SIMATIC S7-1200 can also be used.
SCALANCE X XB008
1
6GK5 008-0BA00-1AB2
Alternatively, another switch can be used.
PM 1207
1
6EP1 332-1SH71
Alternatively, a different voltage supply can also be used.
SIMATIC HMI TP700 Comfort
1
6AV2 181-4GB00-0AX0
Starter kit with WinCC; alternatively, another SIMATIC HMI panel can also be used.
SIMATIC RACK PC IPC647C
1
6AG4 112-1GP21-0BX0
Alternatively, another server/PC can also be used.
t h g i r y p o C
Software components Table 2-4 Component
No.
Order number
Note
STEP 7 PROFESSIONAL V12 SP1
1
package 6ES7 822-1AA02-0YA5 Alternatively, a smaller package is also possible.
WinCC PROFESSIONAL V12 SP1
1
6AV2 101-0AA02-0AA5
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
Included in the TP700 Comfort starter kit; when using a different HMI, a smaller WinCC package can be used.
11
2 Solution 2.3 Hardware and software components Component
FileZilla Server V0.9.41
No.
1
Order number
Freeware (GPL)
Note
The download link for FileZilla Server is is given in the Literature section: /4/ Alternatively, any other FTP server program can also be used.
Sample files and projects The following list includes all files and projects that are used in this example. Table 2-5 Component
81367009_FTP_S7-1200_CODE_V1_0.zip 81367009_FTP_S7-1200_COD E_V1_0.zip 81367009_FTP_S7-1200_DOKU_V1_0_en.pdf 81367009_FTP_S7-1200_DOKU _V1_0_en.pdf
Note
This zip file contains the STEP 7 project. This document
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
12
3 Basics
3
Basics
FTP general FTP was developed to exchange data between a client and a server; furthermore, it is designed for directory management via remote access. In the world of automation technology, this is a useful protocol for making the data exchange as simple as possible. There are two modes for FTP communication: •
active FTP
•
passive FTP
FTP active
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
In this mode, the FTP client opens a random port (>1023) and sends it and its own IP address to the FTP server using a special command (PORT or EPRT). As a standard, it is sent to port 21 of the FTP server (it must be open at the server or forwarded, otherwise no communication will be established). When data transfer is requested, the FTP server now initiates a TCP connection to the transferred IP address and the port from FTP server port 20. The active mode is used when the FTP server is located behind a firewall, since the data connection is initiated from the FTP server outwards, hence, not blocked by the firewall; i.e. the FTP server acts actively.
FTP passive In this mode, the FTP client sends a PASV or EPASV command to port 21 of the FTP server, which prompts it to open a random port and transferring it to the FTP client with its IP address. For the data transfer, the FTP client now initiates a TCP connection to the IP address sent by the FTP server and the port. The passive mode is used when the FTP client is located behind the firewall since the data connection is initiated from the FTP client outwards and the firewall normally does not block any packages. The FTP server hence reacts passively.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
13
4 Mode of Operation 4.1 Overview
4
Mode of Operation
4.1
Overview
Program structure The figure below shows the program structure of the S7 user program. Figure 4-1
GENERATE_ FILENAME DB_FTP_ DATA GENERATE_ DATA
DB_FTP_ USER_ PARAM
SEND_ DATA
FTP_1200_ CMD
MAIN [OB 1]
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
-TCON -TSEND -TDISCON -TRCV
RECIEVE_ DATA
DB_FTP_ DATA2
DB_HMI
t h g i r y p o C
User program
Library block
1 o i r a n e c S
System blocks
2 o i r a n e c S
Data blocks
Description In Scenario 1 (SEND_DATA), process data is generated and filed in a data block. In scenario 1, TCP connections with a server are established via the FTP function block “FTP_1200_CMD”. The FTP is mapped in the block in order to transfer data to the FTP server via FTP. In scenario 2 (RETRIEVE_DATA), TCP connections with a server are also established via the FTP function block. In contrast to scenario 1, data is loaded here from the FTP server to the controller (data block). The data is located on the FTP server in the form of files. The data type of this file can be selected at will by the user according to file names. Principally, any data type can be written to or read.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
14
4 Mode of Operation 4.1 Overview Block list The table below gives you an overview of the program blocks of this application. Table 4-1 Element
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
Note
Symbolic name
Description
OB1
MAIN
Cyclic OB: calls the blocks for scenario 1 and 2
FB1
SEND_DATA
Scenario 1: FTP manager for sending data to the FTP server.
FB2
RETRIEVE_DATA RETRIEVE_DATA
Scenario 2: FTP manager for receiving data from the FTP server
FB10
GENERATE_FILENAME GENERATE_FILENAME
Creates a file name for the FTP data exchange for scenario 1.
FB11
GENERATE_DATA GENERATE_DATA
Creates randomly generated process data for FTP data exchange for scenario 1.
FB60
FTP_1200_CMD
Protected FTP function block: enables FTP communication for S7-1200 controllers.
DB100
DB_HMI_INTERFACE DB_HMI_INTERFACE
Interface DB for controlling the application via HMI
DB200
DB_FTP_DATA
DB for process data of scenario 1
DB101
DB_FTP_DATA2 DB_FTP_DATA2
DB for process data of scenario 2
DB102
DB_FTP_USER_PARAM DB_FTP_USER_PARAM
DB for communication parameters and FTP registration information
DB1
iDB_SEND_DATA iDB_SEND_DATA
Instance DB for FTP Manager for scenario 1
DB2
iDB_RETRIEVE_DATA iDB_RETRIEVE_DATA
Instance DB for FTP Manager for scenario 2
DB10
iDB_GENERATE_FILEN AME
Instance DB for GENERATE_FILENAME GENERATE_FILENAME
DB11
iDB_GENERATE_DATA iDB_GENERATE_DATA
Instance DB for GENERATE_DATA GENERATE_DATA
DB60
iDB_FTP_1200_CMD
Instance DB for FTP_1200_CMD in scenario 1
DB61
iDB_FTP_1200_CMD_2
Instance DB for FTP_1200_CMD in scenario 2
Each function block includes an instance data block (iDB_xxxx). These are not depicted in the program structure (Figure 4-1).
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
15
4 Mode of Operation 4.1 Overview
MAIN OB 1 calls the FTP Manager for scenario 1 and 2 (FB SEND_DATA, FB RETRIEVE_DATA). Furthermore, it calls the FBs for generating data names and process data (GENERATE_FILENAME and GENERATE_DATA) for scenario 1. The process data of the FTP DBs (DB_FTP_DATA and DB_FTP_DATA_2) are in OB 1 prepared for the display on the HMI and then stored in the HMI interface DB. Another function for deleting the process data of scenario 2 is realized within MAIN. A tag in DB_HMI_INTERFACE is used (STOR_RETR) for m utually interlocking scenario 1 and 2.
SEND_DATA (scenario 1) The FTP Manager for scenario 1 contains a step chain consisting of three steps: CONNECT STORE/APPEND DISCONNECT. In FB SEND_DATA, the FTP function block FTP_1200_CMD is called up three times to perform the above mentioned steps. The job trigger only reacts to a positive edge. For details see chapter 4.2.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
RETRIEVE_DATA (scenario 2) The FTP Manager for scenario 2 also contains a step chain consisting of three steps: CONNECT RETRIEVE DISCONNECT. In RETRIEVE_DATA, the FTP function block FTP_1200_CMD (see 4.2.1 Details on the FTP function block: FTP_1200_CMD)) is called up three times to perform the above mentioned steps. FTP_1200_CMD The job trigger only reacts to a positive edge. For details see chapter 4.3.
t h g i r y p o C
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
16
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server
4.2
Description of scenario 1: sending process data to an FTP server The figure below shows the program sequence for scenario 1: Figure 4-2
Enter connection data
Generate file name
Generate process data
Trigger START
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Establish connectionwith connectionwith FTP server
FB: FTP_1200_CMD
Transferring data
FB: FTP_1200_CMD
Terminate connectionwith connectionwith FTP server
FB: FTP_1200_CMD
Output the status
t h g i r y p o C
In scenario 1, file names and process data can be generated. These are transferred to an FTP server and stored under the given file name. The data exchange for scenario 1 runs entirely within FB “SEND_DATA”.
4.2.1
Details on the FTP function block: FTP_1200_CMD FTP_1200_CMD
General FTP function block “FTP_1200_CMD” maps the FTP and hence enables the actual FTP communication. It can perform the following FTP commands: •
CONNECT (connect / login)
•
DISCONNECT (disconnect / log off)
•
STORE (save data)
•
APPEND (attach data)
•
RETRIEVE (fetch data)
•
DELETE (delete file)
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
17
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server To be able to use the block correctly, two data blocks must be created; one for user data and transfer, another one for the connection parameters. User data types are included in the delivery scope of this application (see 4.2.5 Details on the used data types and constants) constants ).
Parameter interface Figure 4-3
Input
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Output
InOut Input
Subsequently, all parameters for the FTP function block are explained: Inputs
t h g i r y p o C
Table 4-2 Name
Data type
Description
FTP_REQ
Bool
Job triggered at positive edge
ID
Int
Freely selectable connection ID of the TCP connection. NOTICE: ID and ID+1 are reserved and unique across the project.
FTP_CMD
Int
FTP command (see 4.2.5 User constants)
FTP_MODE FTP_MODE
Bool
True=passive; False=active
FTP_SERVER_DAT
FTP_SERVER _PARAM
FTP server information (see 4.2.5 UDTs)
FTP_CLIENT_DAT
FTP_CLIENT_ PARAM
FTP client information (see 4.2.5 UDTs)
FTP_FILENAME FTP_FILENAME
String
File name for FTP communication
FTP_SERVER_TYPE FTP_SERVER_TYPE
Bool
For determining the FTP server type True=other; False=SIEMENS CP
FTP_FILE_HEADER FTP_FILE_DATA
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
FTP_HEADER _1200 Variant
FTP header for intermediate storage of various meta data (see 4.2.5 UDTs) Process or user data for FTP communication (see 4.2.5 UDTs)
18
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server Outputs Table 4-3 Name
Note
Data type
Description
DONE
Bool
True, if job successful
BUSY
Bool
True, while job running
ERROR
Bool
True, if job failed
STATUS
Word
Outputs the current job status in form of a HEX code
The output values are only pending for one cycle.
STATUS HEX codes Table 4-4 Description of the status DONE
BUSY
ERROR
X
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
0 X
t h g i r y p o C
Note
STATUS
Description
Job completed successfully without error
8181
Job running
X
8D11
Unexpected error while establishing the connection
X
8D22
Passive mode could not be activated (STORE)
X
8D24
STORE/APPEND STORE/APPEND could not be executed
X
8D27
Data connection not terminated properly
X
8D32
Passive mode could not be activated (RETRIEVE)
X
8D34
RETRIEVE could not be executed
X
8DF1
Time exceeded (5s)
X
8F56
NEW bit still set at RETRIEVE, see chapter 4.2.5.
X
8F60
Invalid user data
X
8F62
Invalid file name
X
8F69
Connection attempt to existing connection
Further STATUS messages are possible and result from the OUC blocks used in the FTP function block (see reference /3/ /3/). ).
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
19
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server
4.2.2
Details on FB “SEND_DATA” Scenario 1 manages an entire FTP communication send cycle. FTP function block FTP_1200_CMD is called here in a sequencer in order to perform the following individual functions: •
Establish a connection with the FTP server
•
Performing the authentication
•
Transferring data
•
Disconnect from the FTP server
The inputs of the FTP function block FTP_1200_CMD are supplied with the respectively required parameters via FB SEND_DATA.
Parameter interface Figure 4-4
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Input
Output InOut
t h g i r y p o C
Subsequently, all parameters for scenario 1 are explained: Inputs Table 4-5 Name
Data type
Description
SEND_REQ
Bool
Job initiation at positive edge; starts a send job
CLIENT_PARAM
FTP_CLIEN T_PARAM
FTP client information (see 4.2.5 UDTs)
SERVER_PARAM
FTP_SERVE R_PARAM
FTP server information (see 4.2.5 UDTs)
FILENAME
String
File name for FTP communication
MODE
Bool
True=passive; False=active
SERVER_TYPE SERVER_TYPE
Bool
For determining the FTP server type True=other; False=SIEMENS CP
FTP_DATA
Variant
Process or user data for FTP communication (see 4.2.5 UDTs)
ID
Int
Freely selectable connection ID of the TCP connection. NOTICE: ID and ID+1 are reserved and unique across the project.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
20
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server Name
APPE_STOR FTP_HEADER
Data type
Description
Bool
For differentiation whether to overwrite overwrite or attach: True= overwrite; False= attach
FTP_HEAD ER_1200
FTP header for intermediate storage of various meta data (see 4.2.5 UDTs)
Outputs Table 4-6 Name
Data type
Description
DONE
Bool
True, if job successful
BUSY
Bool
True, while job running
ERROR
Bool
True, if job failed
STATUS
Word
Outputs the current job status in form of a HEX code
STATUS HEX codes d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
The STATUS HEX codes are taken from the STATUS of the FTP function block, see 4.2.1 Details for FTP function block: FTP_1200_CMD.
4.2.3
Details on FB “GENERATE_DATA” “GENERATE_DATA” GENERATE_DATA automatically generates process data according to the following principle:
t h g i r y p o C
NR=#, temp1=#C, temp2=#C, Voltage=#V, Speed=#rpm, Date=YYYYMM-DD, Time=HH:MM:SS;;
Example: NR=2, temp1=25C, temp2=87C, Voltage=221V, Speed=2102rpm, Date=2013-09-28, Time=11:15:01;;
These data are stored in DB_FTP_DATA (as array of chars) and DB_HMI_INTERFACE (as string).
4.2.4
Details on FB “GENERATE_FILENAME” “GENERATE_FILENAME” GENERATE_DATA generates file names according to the following principle: # _ YYYY-MM-DD YYYY-MM-DD.dat” (example “FILE_ # (example:: FILE_5_2013-09-28.dat). The number is generated continuously and the data read from the CPU. These file names are stored in DB_FTP_USER_PARAM and DB_HMI_INTERFACE.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
21
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server
4.2.5
Details on the used data types and constants
UDTs Additionally, to the blocks of the S7 user program of this application, the following UDTs (User Defined data types) are necessary to supply the parameter interfaces of FB FTP_1200_CMD.
FTP_CLIENT_PARAM (is used in DB_FTP_USER_PARAM) Table 4-7 Name
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
Data type
Description
IP_ADDRESS
Struct
Consists of four USInt fields for the client IP address octets
PORT_START_ADRESSE PORT_START_ADRESSE
Int
Port start address for the FTP client
FTP_SERVER_PARAM (is used in DB_FTP_USER_PARAM) Table 4-8 Name
Data type
Description
IP_ADDRESS
Struct
Consists of four USInt fields for the server IP address
USERNAME USERNAME
String[32]
FTP user name
PASSWORD
String[32]
FTP password
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
22
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server FTP_HEADER_1200 (used in DB_FTP_DATA and DB_FTP_DATA_2) Table 4-9 Name
Data type
Description
Reserve_Byte 0
Byte
Wildcard for further functions
EXIST
Bool
True: data array verified
LOCKED
Bool
True: data array locked; no communication possible
NEW
Bool
True: new data were saved to the data array
ACT_LENGTH
DInt
Current data array size in bytes bytes
MAX_LENGTH MAX_LENGTH
DInt
Maximal data array size in bytes
FTP_REPLY_CODE FTP_REPLY_CODE
Int
Contains the last FTP server response
DATE_TIME
DTL
Time stamp for last change date
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
FTP_DATA_1200 (used in DB_FTP_DATA and DB_FTP_DATA_2) Table 4-10 Name
DATA
Note
Data type
Array[0..1000]
Description
Char-type data array of 1000 bytes.
An array can include a maximum of 32767 characters.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
23
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server
FTP_TELEGRAM (used in DB_FTP_DATA and DB_FTP_DATA_2) Data type FTP_TELEGRAM combines FTP_DATA_1200 and FTP_HEADER_1200. Table 4-11 Name
Data type
Description
FTP_HEADER
FTP_HEADER_1200 FTP_HEADER_1200
UDT: FTP_HEADER_1200
FTP_DATA
FTP_DATA_1200
UDT: FTP_DATA_1200
User constants FTP function block FTP_1200_CMD distinguishes its operations by constant INT values at a parameter interface (see 4.2.1 Details on FTP function block: FTP_1200_CMD). FTP_1200_CMD). The following user constants were created for this: d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
Table 4-12 Name
Value
CMD_CONNECT CMD_CONNECT
1
Connecting with server; logging on
CMD_STORE CMD_STORE
2
Storing data on server under a file name
CMD_RETRIEVE CMD_RETRIEVE
3
Fetching data from the server under a file name
CMD_DELETE CMD_DELETE
4
Deleting file under file name
CMD_QUIT CMD_QUIT
5
Logging off; disconnecting from the server
CMD_APPEND CMD_APPEND
6
Attaching data on server under a file name
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
Description
24
4 Mode of Operation 4.3 Description of scenario 2: receiving process data from an FTP server
4.3
Description of scenario 2: receiving process data from an FTP server The figure below shows the program sequence for scenario 2: Figure 4-5
Enter connection data
Enter Enter file name
Delete process data
Deletion optional
Trigger START
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Establish connectionwith FTP server
FB: FTP_1200_CMD
Transferring data
FB: FTP_1200_CMD
Terminate connectionwith FTP server
FB: FTP_1200_CMD
Output the status
t h g i r y p o C
In scenario 2, process data is loaded from an FTP server into the controller (giving the file name). The user can delete them again from the respective DB on the controller. The data exchange for scenario 2 runs entirely within FB “RETRIEVE_DATA”.
Details on FB “RETRIEVE_DATA” Scenario 2 manages an entire FTP communication receive cycle. FTP function block FTP_1200_CMD (see 4.2.1 FTP function block FTP_1200_CMD) is called here in a sequencer in order to perform the following individual operations: •
Establish a connection with the FTP server
•
Performing the authentication
•
Receiving data from the server
•
Disconnect from the FTP server
•
The inputs of the FTP function block FTP_1200_CMD are supplied with the respectively required parameters via FB RETRIEVE_DATA.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
25
4 Mode of Operation 4.3 Description of scenario 2: receiving process data from an FTP server Parameter interface Figure 4-6
Input
Output InOut
Subsequently, all parameters for scenario 2 are explained:
Inputs d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
Table 4-13 Name
Data type
Description
RETR_REQ
Bool
Job initiation with positive edge starts a receive job
ID
Int
Freely selectable connection ID of the TCP connection. NOTICE: ID and ID+1 are reserved and unique across the project.
MODE
Bool
True=passive; False=active
SERVER_PARAM
FTP_SERVER _PARAM
FTP server information (see 4.2.5 UDTs)
CLIENT_PARAM
FTP_CLIENT_ PARAM
FTP client information (see 4.2.5 UDTs)
FILENAME
String
File name for FTP communication.
SERVER_TYPE SERVER_TYPE
Bool
For determining the FTP server type: True=standard FTP server; False=SIEMENS CP
FTP_HEADER FTP_DATA
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
FTP_HEADER _1200 Variant
FTP header for intermediate storage of various meta data (see 4.2.5 UDTs). Process or user data for FTP communication (see 4.2.5 UDTs)
26
4 Mode of Operation 4.3 Description of scenario 2: receiving process data from an FTP server Outputs Table 4-14 Name
Data type
Description
DONE
Bool
True, if job successful
BUSY
Bool
True, while job running
ERROR
Bool
True, if job failed
STATUS
Word
Outputs the current job status in form of a HEX code
STATUS HEX codes The STATUS HEX codes used here are taken from the STATUS of the FTP function block, see 4.2.1 Details for FTP function block: FTP_1200_CMD.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
27
5 Installation and Commissioning 5.1 Hardware installation
5
Installation and Commissioning
5.1
Hardware installation The figure below shows the hardware setup of the application: Figure 5-1 SIMATIC RACK PC IPC647C
Programming unit
XB008 PROFINET / IE d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
PM 1207
t h g i r y p o C
S7-1200
SIMATIC HMI TP700 Comfort
24 V
24 V
NOTICE
24 V
In general, the installation guidelines for all components have to be observed.
Table 5-1 No.
Action
1.
Connect the switch, the HMI and the controller to a 24 V voltage supply.
2.
Connect the server and the programming unit to a 230 V power supply.
3.
Connect each component to a port at the switch vie Ethernet cable (RJ45).
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
28
5 Installation and Commissioning 5.2 Installation of the software
5.2
Installation of the software This chapter describes the steps for the installation of the example code. It is recommended to run the latest versions of any installed software.
Note
FTP server software Table 5-2 No.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Action
Note
1.
Download an FTP server software.
The download link for FileZilla server is is contained in the literature section: /4/ This program is recommended for the application since it is easy to operate and set up in a very functional way.
2.
Install the FTP server software on your server.
Follow the instructions of the program.
TIA Portal with STEP 7 and WinCC Table 5-3 No.
Action
Note
1
Install STEP 7 V12 on your programming unit.
Follow the instructions of the program.
2
Install WinCC V12 on your programming unit.
Follow the instructions of the program.
t h g i r y p o C
5.3 NOTICE
5.3.1
Commissioning When assigning the IP addresses of your devices please ensure that they are all located in the same subnet and each IP is only assigned once across the subnets.
FTP server The following table shows how to commission FileZilla Server. If another FTP server software is used, their manuals need to be followed for commissioning. It is important to create a user with password and full access to the data in his root directory. directory.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
29
5 Installation and Commissioning 5.3 Commissioning Table 5-4 No.
Action
1.
Start the FileZilla server interface on your FTP server and click on “OK”. Now you are logged on at the server interface. Here you could track any of the actions running on the server and make settings.
2.
In the menu bar, click on “Edit” and then on “Settings” to get to the server settings.
Screenshot
All of your desired settings can can be made here. For this application example you can use the default settings. Confirm with “OK”. 3. d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
In the menu bar, click on “Edit” and then on “Users” to get to the Users management. Select the “General” page and click on “Add”. In the field you enter an FTP user name, for example “ftp_user”. Confirm with “OK”.
t h g i r y p o C
4.
Activate the “Password” checkbox and enter the password in the field on the right, for example “ftp_user”.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
30
5 Installation and Commissioning 5.3 Commissioning No.
5.
Action
Screenshot
Select the “Shared folders” page and in the “Shared folders” section you click on “Add”. In the now opened Explorer you navigate to the folder you wish to use as FTP root directory for the created user, select the folder (for example, a previously created folder: “FTP_Server”) and acknowledge with “OK”. Activate the checkboxes checkboxes “Read”, “Write”, “Delete” and “Append”. Confirm with “OK” again.
6.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Make sure that the server is online: the online icon must be activated. Now you have created an FTP user with password, root directory with all of the rights. The FTP server is now ready for the application example and for processing user requests.
5.3.2
S7-1200 controller and HMI
Controller
t h g i r y p o C
The table below shows how to commission the S7-1200: Table 5-5 No.
Action
Picture / Note
1.
Load the example application to your programming unit and unzip the archive.
http://support.automation.siemens.com/WW/view/ en/81367009
2.
Open the example project
FTP_1200_CMD.ap12
3.
Open the “Device configuration” of the controller (PLC_1).
SIMATIC S7-1200 CPU 1214C DC/DC/DC
When using the same controller as in the example, proceed with step 5.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
31
5 Installation and Commissioning 5.3 Commissioning No.
4.
Action
Picture / Note
Right-click on the controller and click on “Change device”. Select your S7-1200 from the tree and confirm with “OK”.
5.
Right-click on the controller and click on “Properties”. In the area navigation of the inspection window you select “PROFINET interface”.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
In “Ethernet addresses” you enter an I P address and Subnet mask. Please ensure that these match the IP address and subnet mask of the server. Network the controller with a subnet. 6.
In the project navigation you select the controller and download the program into the controller.
t h g i r y p o C
The configuration of the controller has now been completed.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
32
5 Installation and Commissioning 5.3 Commissioning HMI The table below shows how to commission the HMI: Table 5-6 No.
1.
Action
Open the “Device configuration” of the HMI (“HMI_1”).
Picture / Note
TP700 Comfort
When using the same HMI as in the example, proceed with step 3. 2.
Right-click on the HMI and click on “Change device”. Select your used HMI from the tree and confirm with “OK”.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
3.
Right-click on the HMI and click on “Properties”. In the area navigation of the inspection window you select “PROFINET interface”.
t h g i r y p o C
In “Ethernet addresses” you enter an IP address and Subnet mask. Please ensure that these match the IP address and subnet mask of the server. Network the HMI with a subnet. 4.
In the project navigation you select the HMI and load the program into the HMI. Note: if the HMI is currently not in Runtime, you need to activate “Transfer” on the HMI.
After a successful successful transfer, the WinCC Runtime starts automatically. The configuration of the HMI has now been completed.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
33
5 Installation and Commissioning 5.3 Commissioning
5.3.3
Adapting the S7 program Three parameters of the FTP function block or the FTP Manager respectively (SEND_DATA / RECEIVE_DATA) are in this application statically transferred to the parameter interfaces of the blocks and cannot be controlled via the HMI. In the TIA project you open the “MAIN” block to change these. Please read the respective notes on the parameter interfaces in chapter 4.2.2 and 4.3.1. The three parameters are described as follows. •
Adjusting to the hardware
If your hardware setup deviates from that of the example application, it may be necessary to change the parameters “SERVER_TYPE” of both FTP managers (SEND_DATA and RETRIEVE_DATA).
•
Adjustment to the configuration
When using this application within a comprehensive project where some of the TCP connections have already been configured, you adjust the “ID” parameter of both FTP managers (each ID (hence ID and ID+1) must only be used once). d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
•
Adjustment to the FTP server
The standard setting for the FTP mode of the server is usually “passive”. When using “active”, you need to adjust the “MODE” parameter of the FTP manager.
Modifications at the user program You can change the data volume to be sent or received by adjusting the DATA (Array of Char) tag in the UDT FTP_DATA_1200 (at PLC data types). The maximal possible array length is 32767 chars, the minimal is 1. Please ensure that the complete program is recompiled after the modification.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
34
6 Operating the Application 6.1 Menu navigation
6
Operating the Application
6.1
Menu navigation Figure 6-1 Operator user interface of HMI Runtime Main menu
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Example application
Industry Online Support Information
t h g i r y p o C
Note
In the user interface of the HMI you can change the display language of each picture from German to English and vice versa by clicking on the flag icons
The example application can be started via the main menu and continuing information be called up via the Industry Online support. In the left tree in the example application you can switch between scenario 1 and 2.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
35
6 Operating the Application 6.2 Scenario 1 (storing data)
6.2
Scenario 1 (storing data) Figure 6-2
1 2
5 d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
3
Note
t h g i r y p o C
4
6
If IP address, user name, password and file name have already been entered in scenario 2, these are adopted as a standard for scenario 1. You can change the parameters afterwards manually.
The following table gives a step-by-step description of operating scenario 1: Table 6-1 No.
Action
1.
Enter the IP address of your FTP server into the provided fields.
2.
Enter the user name and the appropriate password for the FTP user created in the server.
3.
Create a file name via the “Create file name” button or manually enter one into the respective field.
Note
Look out for subfolders, for example: “FTP_Server/Datei1.dat” Any file ending is possible.
4.
Generate process data via the “Generate process data” button.
5.
In the “Overwrite / Append” drop-down list you chose whether you wish to append the data to the already existing data in the given file o r overwrite everything.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
If the file does not yet exist, it is generated on the server.
36
6 Operating the Application 6.3 Scenario 2 (fetching data) No.
6.
Action
Note
Start the data transfer via the “START” button.
6.3
If the green status display lights up, the job has been executed successfully. The process data can now be viewed on the FTP server at the given file name. If the red status display lights up, then problems occurred during the job. Further information is available in the error report:
Scenario 2 (fetching data) Figure 6-3
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
1 2
t h g i r y p o C
3
4
Note
5
If IP address, user name, password and file name have already been entered in scenario 1, these are adopted as a standard for scenario 2. You can change the parameters afterwards manually.
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
37
6 Operating the Application 6.4 Settings The following table gives a step-by-step description of operating scenario 2: Table 6-2 No.
d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
t h g i r y p o C
Action
Note
1.
Enter the IP address of your FTP server into the provided fields.
2.
Enter the user name and the appropriate password for the FTP user created in the server.
3.
Enter the file name of the file to be transferred into the respective field.
Look out for subfolders in the server root directory, for example: “CPU1/Datei1.dat”
4.
Delete the process data on the controller via the “Delete data record” button
Optional
5.
Start the data transfer via the “START” button.
If the green status display lights up, the job has been executed successfully. The process data can now be viewed in the “Process data” field. If the red status display lights up, then problems occurred during the job. Further information is available in the error report:
6.4
Settings The figure below shows the settings options of HMI Runtime: Figure 6-4
Enable monitor keyboard
Open the Task Manager
Terminate Runtime; Trigger the transfer
Stop runtime Calibrate screen
Extablish connection with PLC
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
Terminate PLC connection
38
7 Related Literature and Links
7
Related Literature and Links This list is not complete and only represents a selection of relevant literature. Table 7-1
8 d e v r e s e r s t h g i r l l A 3 1 0 2 G A s n e m e i S
Topic
Title / Link
\1\
Siemens Industry Online Support
http://support.automation.siemens.com
\2\
Downloadseite des Beitrages
http://support.automation.siemens.co http://support.auto mation.siemens.com/WW/view/de/81 m/WW/view/de/81367009 367009
\3\
OUC-Bausteine: TCON; TDISCON; TSEND; TRCV;
http://support.automation.siemens.co http://support.auto mation.siemens.com/WW/view/de/77 m/WW/view/de/77991795 991795
\4\
FileZilla Server
https://filezilla-project.org/do https://filezilla -project.org/download.php?ty wnload.php?type=server pe=server
History Table 8-1 Version
Date
V1.0
10/2013
Modifications
First version
t h g i r y p o C
FTP-Kommunikation FTP-Kommunikation S7‑1200 Version 1.0, Entry ID: 81367009 ID: 81367009
39