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. Any form of duplication or distribution of these Application Examples or excerpts hereof is prohibited without the express consent of Siemens Industry Sector. 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 Version 1.0, Entry ID: 81367009 2
Table of Contents Table of Contents Warranty and Liability... 2 1 Task... 4 2 Solution... 6 2.1 Overview... 6 2.2 Core functionality... 8 2.2.1 Principle of the core functionality... 8 2.2.2 Overview of the user interface... 10 2.3 Hardware and software components... 11 2.3.1 Validity... 11 2.3.2 Components used... 11 3 Basics... 13 4 Mode of Operation... 14 4.1 Overview... 14 4.2 Description of scenario 1: sending process data to an FTP server... 17 4.2.1 Details on the FTP function block: FTP_1200_CMD... 17 4.2.2 Details on FB SEND_DATA... 20 4.2.3 Details on FB GENERATE_DATA... 21 4.2.4 Details on FB GENERATE_FILENAME... 21 4.2.5 Details on the used data types and constants... 22 4.3 Description of scenario 2: receiving process data from an FTP server... 25 5 Installation and Commissioning... 28 5.1 Hardware installation... 28 5.2 Installation of the software... 29 5.3 Commissioning... 29 5.3.1 FTP server... 29 5.3.2 S7-1200 controller and HMI... 31 5.3.3 Adapting the S7 program... 34 6 Operating the Application... 35 6.1 Menu navigation... 35 6.2 Scenario 1 (storing data)... 36 6.3 Scenario 2 (fetching data)... 37 6.4 Settings... 38 7 Related Literature and Links... 39 8 History... 39 Version 1.0, Entry 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 FTP 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 FTP server PROFINET / IE + F T P 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. Version 1.0, Entry ID: 81367009 4
1 Task Requirements of the automation task The following table shows the automation requirements for this application. Table 1-1 Requirement Saving data from the S7-1200 controller on the server Requesting data from the FTP server of S7-1200 Explanations Scenario 1 shall demonstrate how process data can be loaded from the controller to a server using an FTP block. Scenario 2 shall demonstrate how data (e.g. recipes) can be loaded from a server into the controller using an FTP block. Version 1.0, Entry 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 FTPclient - S7-1200 controller: S7 program with FTP function block FTP_1200_CMD and process data PROFINET / IE HMI: HMI screen Note The FTP function block (FTP_1200_CMD) is delivered with the example project 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. Version 1.0, Entry 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 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: SCALANCE products FTP servers HMI panels PLCs (especially S7-1200) SCL programming Basic knowledge of these topics is assumed. Note The FTP function block delivered with this application exclusively fulfils FTP client functions Assumed knowledge 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 Via CP FTP feature S7-300/400 S7-1500 S7-1200 (CP 343-1 / 443-1) (CP 1543-1) FTP server Number of parallel client connections 10/20 32 4 FTP active FTP passive FTPS Full S7-FTP command set Version 1.0, Entry ID: 81367009 7
2 Solution 2.2 Core functionality 2.2 Core functionality The example project for this application contains two scenarios: Scenario 1: transferring process data to the FTP server Scenario 2: retrieve data from the FTP server 2.2.1 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 2 3 Connected? Yes Trigger data exchange Data sent/ received? No 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 disconnected? No Yes Version 1.0, Entry ID: 81367009 8
2 Solution 2.2 Core functionality Table 2-2 Action Note 1. After a start trigger was output with START, the PLC connects with the FTP server 2. The program checks the connection status: OK: triggers sending or receiving the data NOK: terminates the program sequence outputs the error-specific status 3. The program checks the data exchange: OK: triggers the disconnection process NOK: terminates the program sequence and outputs the error-specific status 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 5. Wait for the new trigger The connection data are entered via the user interface (IP address, User name, Password) For NOK, the red display lights up in the HMI interface For NOK, the red display lights up in the HMI interface For OK, the green display lights up. For NOK, the red display lights up. Version 1.0, Entry 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 Scenario 2 The figure below shows the user interface for scenario 2 Figure 2-4 Version 1.0, Entry 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 STEP 7 Professional as of V12 SP1 WinCC Professional as of V12 SP1 S7-1200 controller common FTP servers 2.3.2 Components used This application has been generated using the following components: Hardware components Table 2-3 Component No. Order number Note SIMATIC S7-1200 CPU 1214C DC/DC/DC SCALANCE X XB008 1 6ES7 214-1AG31-0XB0 Alternatively, any other SIMATIC S7-1200 can also be used. 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 SIMATIC RACK PC IPC647C 1 6AV2 181-4GB00-0AX0 Starter kit with WinCC; alternatively, another SIMATIC HMI panel can also be used. 1 6AG4 112-1GP21-0BX0 Alternatively, another server/pc can also be used. Software components Table 2-4 Component No. Order number Note STEP 7 PROFESSIONAL V12 SP1 WinCC PROFESSIONAL V12 SP1 1 6ES7 822-1AA02-0YA5 Alternatively, a smaller package is also possible. 1 6AV2 101-0AA02-0AA5 Included in the TP700 Comfort starter kit; when using a different HMI, a smaller WinCC package can be used. Version 1.0, Entry ID: 81367009 11
2 Solution 2.3 Hardware and software components Component No. Order number Note FileZilla Server V0.9.41 1 Freeware (GPL) The download link for FileZilla Server 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 Note 81367009_FTP_S7-1200_CODE_V1_0.zip This zip file contains the STEP 7 project. 81367009_FTP_S7-1200_DOKU_V1_0_en.pdf This document Version 1.0, Entry 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 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. Version 1.0, Entry 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 GENERATE_ DATA SEND_ DATA DB_FTP_ DATA DB_FTP_ USER_ PARAM Scenario 1 MAIN [OB 1] User program RECIEVE_ DATA FTP_1200_ CMD Library block -TCON -TSEND -TDISCON -TRCV System blocks DB_FTP_ DATA2 DB_HMI Data blocks Scenario 2 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. Version 1.0, Entry 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 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 Scenario 2: FTP manager for receiving data from the FTP server FB10 GENERATE_FILENAME Creates a file name for the FTP data exchange for scenario 1. FB11 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 Interface DB for controlling the application via HMI DB200 DB_FTP_DATA DB for process data of scenario 1 DB101 DB_FTP_DATA2 DB for process data of scenario 2 DB102 DB_FTP_USER_PARAM DB for communication parameters and FTP registration information DB1 idb_send_data Instance DB for FTP Manager for scenario 1 DB2 idb_retrieve_data Instance DB for FTP Manager for scenario 2 DB10 idb_generate_filen Instance DB for GENERATE_FILENAME AME DB11 idb_generate_data Instance DB for 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 Note Each function block includes an instance data block (idb_xxxx). These are not depicted in the program structure (Figure 4-1). Version 1.0, Entry 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 mutually 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. 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. The job trigger only reacts to a positive edge. For details see chapter 4.3. Version 1.0, Entry 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 Establish connection with FTP server FB: FTP_1200_CMD Transferring data Terminate connection with FTP server Output the status FB: FTP_1200_CMD FB: FTP_1200_CMD 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 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) Version 1.0, Entry 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). Parameter interface Figure 4-3 Input Inputs Output InOut Input Subsequently, all parameters for the FTP function block are explained: 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 Bool True=passive; False=active FTP_SERVER_DAT FTP_SERVER FTP server information (see 4.2.5 UDTs) _PARAM FTP_CLIENT_DAT FTP_CLIENT_ FTP client information (see 4.2.5 UDTs) PARAM FTP_FILENAME String File name for FTP communication FTP_SERVER_TYPE Bool For determining the FTP server type True=other; False=SIEMENS CP FTP_FILE_HEADER FTP_HEADER _1200 FTP header for intermediate storage of various meta data (see 4.2.5 UDTs) FTP_FILE_DATA Variant Process or user data for FTP communication (see 4.2.5 UDTs) Version 1.0, Entry ID: 81367009 18
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server Outputs Table 4-3 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 Note The output values are only pending for one cycle. STATUS HEX codes Table 4-4 Description of the status DONE BUSY ERROR STATUS Description X 0 Job completed successfully without error X 8181 Job running X 8D11 Unexpected error while establishing the connection X 8D22 Passive mode could not be activated (STORE) X 8D24 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 Note Further STATUS messages are possible and result from the OUC blocks used in the FTP function block (see reference /3/). Version 1.0, Entry 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 Input Output InOut 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 FTP client information (see 4.2.5 UDTs) T_PARAM SERVER_PARAM FTP_SERVE FTP server information (see 4.2.5 UDTs) R_PARAM FILENAME String File name for FTP communication MODE Bool True=passive; False=active 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. Version 1.0, Entry ID: 81367009 20
4 Mode of Operation 4.2 Description of scenario 1: sending process data to an FTP server Name Data type Description APPE_STOR Bool For differentiation whether to overwrite or attach: True= overwrite; False= attach FTP_HEADER 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 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 automatically generates process data according to the following principle: NR=#, temp1=#c, temp2=#c, Voltage=#V, Speed=#rpm, Date=YYYY- MM-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_DATA generates file names according to the following principle: FILE_#_YYYY-MM-DD.dat (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. Version 1.0, Entry 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 Data type Description IP_ADDRESS Struct Consists of four USInt fields for the client IP address octets 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 String[32] FTP user name PASSWORD String[32] FTP password Version 1.0, Entry 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 MAX_LENGTH DInt Maximal data array size in bytes FTP_REPLY_CODE Int Contains the last FTP server response DATE_TIME DTL Time stamp for last change date FTP_DATA_1200 (used in DB_FTP_DATA and DB_FTP_DATA_2) Table 4-10 Name Data type Description DATA Array[0..1000] Char-type data array of 1000 bytes. Note An array can include a maximum of 32767 characters. Version 1.0, Entry 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 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). The following user constants were created for this: Table 4-12 Name Value Description CMD_CONNECT 1 Connecting with server; logging on CMD_STORE 2 Storing data on server under a file name CMD_RETRIEVE 3 Fetching data from the server under a file name CMD_DELETE 4 Deleting file under file name CMD_QUIT 5 Logging off; disconnecting from the server CMD_APPEND 6 Attaching data on server under a file name Version 1.0, Entry ID: 81367009 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 file name Delete process data Deletion optional Trigger START Establish connection with FTP server FB: FTP_1200_CMD Transferring data Terminate connection with FTP server Output the status FB: FTP_1200_CMD FB: FTP_1200_CMD 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. Version 1.0, Entry 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 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 FTP server information (see 4.2.5 UDTs) _PARAM CLIENT_PARAM FTP_CLIENT_ FTP client information (see 4.2.5 UDTs) PARAM FILENAME String File name for FTP communication. SERVER_TYPE Bool For determining the FTP server type: True=standard FTP server; False=SIEMENS CP FTP_HEADER FTP_HEADER _1200 FTP header for intermediate storage of various meta data (see 4.2.5 UDTs). FTP_DATA Variant Process or user data for FTP communication (see 4.2.5 UDTs) Version 1.0, Entry ID: 81367009 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. Version 1.0, Entry 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 PM 1207 24 V S7-1200 24 V SIMATIC HMI TP700 Comfort 24 V NOTICE 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). Version 1.0, Entry 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. Note It is recommended to run the latest versions of any installed software. FTP server software Table 5-2 No. Action Note 1. Download an FTP server software. The download link for FileZilla server 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. 2 Install WinCC V12 on your programming unit. Follow the instructions of the program. Follow the instructions of the program. 5.3 Commissioning NOTICE 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. 5.3.1 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. Version 1.0, Entry ID: 81367009 29
5 Installation and Commissioning 5.3 Commissioning Table 5-4 No. Action Screenshot 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. All of your desired settings can be made here. For this application example you can use the default settings. Confirm with OK. 3. 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. 4. Activate the Password checkbox and enter the password in the field on the right, for example ftp_user. Version 1.0, Entry ID: 81367009 30
5 Installation and Commissioning 5.3 Commissioning No. Action Screenshot 5. 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 Read, Write, Delete and Append. Confirm with OK again. 6. 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 Table 5-5 The table below shows how to commission the S7-1200: 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). When using the same controller as in the example, proceed with step 5. SIMATIC S7-1200 CPU 1214C DC/DC/DC Version 1.0, Entry ID: 81367009 31
5 Installation and Commissioning 5.3 Commissioning No. Action Picture / Note 4. 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. 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 controller with a subnet. 6. In the project navigation you select the controller and download the program into the controller. The configuration of the controller has now been completed. Version 1.0, Entry ID: 81367009 32
5 Installation and Commissioning 5.3 Commissioning HMI The table below shows how to commission the HMI: Table 5-6 No. Action Picture / Note 1. Open the Device configuration of the HMI ( HMI_1 ). 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. 3. Right-click on the HMI and click on Properties. In the area navigation of the inspection window you select PROFINET interface. 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 transfer, the WinCC Runtime starts automatically. The configuration of the HMI has now been completed. Version 1.0, Entry 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). 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. Version 1.0, Entry 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 Note Example application Industry Online Support Information 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. Version 1.0, Entry 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 Note 3 4 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. 6 Table 6-1 The following table gives a step-by-step description of operating scenario 1: No. 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. Create a file name via the Create file name button or manually enter one into the respective field. 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 or overwrite everything. Look out for subfolders, for example: FTP_Server/Datei1.dat Any file ending is possible. If the file does not yet exist, it is generated on the server. Version 1.0, Entry ID: 81367009 36
6 Operating the Application 6.3 Scenario 2 (fetching data) No. Action Note 6. 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 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: 6.3 Scenario 2 (fetching data) Figure 6-3 1 2 3 4 5 Note 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. Version 1.0, Entry ID: 81367009 37
6 Operating the Application 6.4 Settings Table 6-2 The following table gives a step-by-step description of operating scenario 2: No. 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. 4. Delete the process data on the controller via the Delete data record button Look out for subfolders in the server root directory, for example: CPU1/Datei1.dat 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 Terminate PLC connection Version 1.0, Entry ID: 81367009 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 Topic \1\ Siemens Industry Online Support \2\ Downloadseite des Beitrages \3\ OUC-Bausteine: TCON; TDISCON; TSEND; TRCV; Title / Link http://support.automation.siemens.com http://support.automation.siemens.com/ww/view/de/81367009 http://support.automation.siemens.com/ww/view/de/77991795 \4\ FileZilla Server https://filezilla-project.org/download.php?type=server 8 History Table 8-1 Version Date Modifications V1.0 10/2013 First version Version 1.0, Entry ID: 81367009 39