application example 04/2015 tcp file server for s7 controller · application example 04/2015 tcp...
TRANSCRIPT
https://support.industry.siemens.com/cs/ww/en/view/109475508
Application Example 04/2015
TCP File Server for S7 Controller S7-300/S7-1500/S7-1200
Warranty and Liability
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 2
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
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 responsible for the correct operation of the described products. These application examples do not relieve you of the responsibility of safely and professionally using, installing, operating and servicing equipment. When using these Application Examples, you recognize that we cannot be made liable for any damage/claims beyond the liability clause described. We reserve the right to make changes to these application examples at any time and without prior notice. If there are any deviations between the recommendations provided in this application example and other Siemens publications – e.g. Catalogs – the contents of the other documents shall 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 fundamental contractual obligations (“wesentliche Vertragspflichten”). The compensation for damages due to a breach of a fundamental contractual obligation is, however, limited to the foreseeable damage, typical for the type of contract, except in the event of intent or gross negligence or injury to life, body or health. The above provisions do not imply a change of the burden of proof to your detriment.
Any form of duplication or distribution of these application examples or excerpts hereof is prohibited without the expressed consent of Siemens AG.
Security informa-
tion
Siemens provides products and solutions with industrial security functions that support the secure operation of plants, solutions, machines, equipment and/or networks. They are important components in a holistic industrial security concept. With this in mind, Siemens’ products and solutions undergo continuous development. Siemens recommends strongly that you regularly check for product updates.
For the secure operation of Siemens products and solutions, it is necessary to take suitable preventive action (e.g. cell protection concept) and integrate each component into a holistic, state-of-the-art industrial security concept. Third-party products that may be in use should also be considered. For more information about industrial security, visit http://www.siemens.com/industrialsecurity.
To stay informed about product updates as they occur, sign up for a product-specific newsletter. For more information, visit https://support.industry.siemens.com.
Table of Contents
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 3
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Table of Contents Warranty and Liability ................................................................................................. 2
1 Task ..................................................................................................................... 4
1.1 Overview............................................................................................... 4
2 Solution............................................................................................................... 5
2.1 Overview............................................................................................... 5 2.2 Description of the core functionality ..................................................... 7 2.3 Hardware and software components ................................................. 11 2.3.1 Validity ................................................................................................ 11 2.3.2 Components used .............................................................................. 11
3 Mode of Operation ........................................................................................... 13
3.1 General overview ............................................................................... 13 3.2 Functionality in the S7 controller (TcpClient) ..................................... 14 3.2.1 DataGenerator function block ............................................................ 14 3.2.2 ErrorLogger function block ................................................................. 15 3.2.3 Data blocks ......................................................................................... 16 3.2.4 TcpClient function block ..................................................................... 18 3.2.5 General behavior of the TcpClient program block ............................. 20 3.3 Functionality in the TCP file server .................................................... 21 3.3.1 General behavior of the TCP file server software .............................. 21 3.4 Details on the interaction of TcpClient and TCP file server ............... 23
4 Installation and Commissioning .................................................................... 25
4.1 Installing the hardware ....................................................................... 25 4.2 Commissioning ................................................................................... 26
5 Operating the Application ............................................................................... 29
6 References ....................................................................................................... 35
7 History............................................................................................................... 35
1 Task
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 4
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
1 Task
1.1 Overview
Introduction
SCADA systems are usually used on PCs for the further processing of PLC data from controllers. However, it is often sufficient to only store few, essential data on PCs in order to then use it with office applications.
This application shows an economical alternative to complex SCADA systems in the lower performance range.
Overview of the automation task
The figure below provides an overview of the automation task.
Figure 1-1
Supervisory control level
Control level
Field level
File
Production data
Description of the automation task
Production data from different automated systems are to be stored via their assigned controller in the file system of a server. The format of the file is to be simply processed further with programs of the supervisory control level.
In detail, the following requirements are to be met:
The format and the name of the file are only to be assigned in the controller.
The files on the server are to be managed in a file system.
The server is to manage the data of several controllers.
The program example is to be easily adjustable to be able to process real production data as quickly as possible.
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 5
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
2 Solution
2.1 Overview
Schematic layout
The figure below shows a schematic overview of the most important components of the solution:
Figure -21
PROFINET IE
TcpClient
TcpClient
S7-1500 S7-1200S7-300
TCP file server
PG/PC
Files
Data
TcpClient
Structure
The relevant components of this solution are the STEP 7 blocks “TcpClient” in the individual S7 stations, which prepare the data and send it to the PC station. The PC program “TCP file server” receives the data from the SIMATIC stations and saves it line by line in the files.
The solution was realized for S7-300, S7-1200 and S7-1500 CPUs (simple porting to a S7-400 CPU is also possible).
Advantages
The solution presented here, offers you the following advantages
Economic alternative to SCADA systems for very small applications
Simple configuration
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 6
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Individual expandability by open source code
Transferring and saving any formats (CSV, XML, binary etc.), since any formatting is possible in the SIMATIC S7 controller
Delimitation
This application
does not create a special file format (in the example only a CSV string is created. If a XML, JSON or a different format is required, it has to be programmed individually in the controller).
does not automate data collection (all values that are to be transferred, have to be collected first).
does not include an introduction into SCL programming
does not include an explanation on C# programming
Assumed knowledge
Basic knowledge on programming in the TIA Portal and a general understanding of computer networks is assumed for commissioning and for operating this application.
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 7
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
2.2 Description of the core functionality
Overview of the PC program (TCP file server)
Here, the user interface of the TCP file server is described. With the help of the server you can manage the connection to the S7 stations and its files.
Figure 2-2 Log view
1 2 3 4 5 6 7
8
9
10
11
12
Table 2-1
No. Description
1. Button for starting (and stopping) the server
2. Button for adding a local TCP client for test purposes.
3. Displaying the current configuration of the active network adapter for an existing connection. This field serves as a reminder, what information the S7 CPUs require in order to establish a connection.
4. Display, whether server is active and how many clients are currently connected to it.
5. Path for the log file that continuously records the current server log.
6. Note on limitation of liability of the online support.
7. Standard buttons.
8. Selection of path and file name for the server log.
9. Table of the server log. It is automatically filled as soon as the server detects events.
10. Empties the content of the table of the server log.
11. Change between the log view and the connection management view.
12. Specifying the port for the connection with the S7 stations. The local host IP displayed is only used to display that the server is running locally.
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 8
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Figure 2-3 Connection view
The connection allows the management of the connections and their files. The last connection configuration is reloaded for each new start of the TCP file server.
Table 2-2
No. Description
1. Specifying the individual connection name directly in the table. Either press the enter button twice to save it or click the “Save Changes” button.
2. Display of the active connection status (either “Connected” or “Disconnected”).
3. Display of the IP address of the S7 station or the TCP client to which a connection was successfully established.
4. Port on the server side via which the connection is established.
5. Setting the mode of storage of the station data. Either the current data record is attached to configured file (“Append”) or it overwrites all previous data records (“Overwrite”).
6. The file name cannot be set on the server. It has to be explicitly transferred from the S7 station in the message intended for this purpose. All the data received on this connection is stored in the file specified by file name and file path.
7. The file path can be specified directly in the table. Optionally it can also be specified via the button with the number 8.
8. Assigning the file storage path. Click a file within the folder, to select the path you would like to choose.
9. Display of the current file path of the currently selected connection.
10. Display of the file path of one of the files that was already created for the selected connection.
11. Display of the number of data records/lines that already exist in the file.
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 9
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Description
12. Deleting the selected file. Caution: the actual file is deleted and not only dissociated from the connection.
13. Open the selected file in the text editor preferred by the user for this file type.
14. File name that is assigned to this connection.
15. Update of the connection list. This should normally not be necessary.
16. Saves all changes of the connection table. Optionally the enter button can be pressed twice for this.
17. Deletes the currently selected connection. If the connection is still active at the time of deleting, the same data record is instantly created empty again. The files associated with the connection are not deleted but dissociated.
Integrated TCP client
Here, the TCP client included in the TCP file server is described. It simulates the behavior of an S7 station and can therefore be used to get to know the program examples without a SIMATIC S7 station. This test TCP client can send TCP messages across networks and independent from the rest of the application
Figure 2-4
1 2
3
4
5
6
7
8
9
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 10
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Table 2-3
No. Description
1. Establishing the connection of the client to the server with the specified IP address and the specified port (theoretically, it also works via the Internet).
2. Standard buttons.
3. Specifying the desired message type for a transfer to the server.
4. Monitoring the client events. One click on this button deletes the content of this client log.
5. Entering the message that is to be sent to the server.
6. Information on the status of the client/server connection.
7. Transfer of the entered message to the server according to specified message type. Optionally, when focusing on the text field, the enter button can also be used for this purpose.
8. Setting the port on the client side. The communication with the server takes place via this port.
9. Entering the IP address of the server. By default, it is assumed that client and server are located on the same PC.
Sequence of the core functions
The following diagram displays the rough functionality and interaction of the two software components. For more details, please refer to Chapter 3.
Figure -25
S7-CPU (TcpClient) Computer (TCP file server)
Start/Stop
Establish connection
SendFile name
SendCSV string
Disconnectconnection
Start/Stop
Acceptconnection
Createfile
Write CSVin file
Switch offserver
When the TCP connection is active, the S7 stations can send either
the individual user data or
a file name
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 11
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
to the TCP file server.
You can specify a file path on the server for the file name. The server now saves the transferred data in the file which was specified with the file name and the file path.
There are two modes for saving the data in the file:
In the append mode, the current data is attached to the file.
In the overwrite mode, the current data overwrites the entire file content each time.
2.3 Hardware and software components
2.3.1 Validity
This application is valid for
STEP 7 from V13 SP1 (TIA Portal)
SIMATIC S7-1500
SIMATIC S7-1200
SIMATIC S7-300
Microsoft Visual Studio 2012 (Express)
2.3.2 Components used
The application was generated and tested with the following components:
Hardware components
Table 2-4
Component No. Article number Note
CPU 1516-3PN/DP 1 6ES7 516-3AN00-0AB0 Alternatively: all 1500 CPUs.
CPU 1212C-DC/DC/DC
1 6ES7 212-1AD30-0XB0 Alternatively: all 1200 CPUs.
CPU 319-3 PN/DP 1 6ES7-318-3EL00-0AB0 Alternatively: all 300 CPUs with PN interface.
Software components
Table 2-5
Component No. Article number
Note
TIA Portal V13 SP1 1 6ES7.. Required for configuring the S7 stations.
Microsoft Visual Studio Express
1 (Optional) Only to change the TCP file server code. We recommend a version 2008 or later
2 Solution
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 12
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Example files and projects
The following list includes all files and projects that are used in this example.
Table 2-6
Component Note
109475508_PLC_to_CSV CODE_v10.zip
This zip file includes the STEP 7 project and the TCP file server (Visual Studio 2012 project and executable file).
109475508_PLC_to_CSV DOC_v10_en.pdf
This document.
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 13
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
3 Mode of Operation
3.1 General overview
The following overview shows the individual steps that occur between S7 controller and the PC. The details in STEP 7 and the PC program are elaborated in the following chapters.
In this application example the S7 CPU independently generates the individual CSV strings that are then sent to the file server when an input is triggered.
Figure 3-1
HDD
TCP
File server
Connect
Send
data
Send
File name
Write
data to file
TcpClient
File name
Connectiondata
S7 station PC
1
2
3
4
5
Create
file
Table 3-1
No. Action Comments
1. Establishing connection
The “TcpClient” function block of the S7 station establishes a connection to the TCP file server. For this purpose both sides have to know the IP address of the respectively other and use the same port. (For local networks both IP addresses have to be located in the same subnet).
2. Sending file name
The file name is transferred in the TCP message.
3. Sending the CSV string
The CSV string is transferred in the TCP message.
4. Creating the file On arrival of a new CSV string, the TCP file server creates a new file (provided a new combination of file path and file name exists). The server uses the file name last transferred and a file path specified by the server administrator.
5. Writing the CSV string in the file
The string is now written in the file. Depending on whether the server administrator has specified either an append or an overwrite mode on the server, the string is either attached or overwrites it every time (can be changed on the server side).
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 14
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
3.2 Functionality in the S7 controller (TcpClient)
Program overview
Below, the program structure in the S7 CPU (call structure of the TcpClient and all other components of the project) is explained.
Figure 3-2
Main
DataGeneratorTcpClient ErrorLogger
Parameters ErrorLogStatus
Table 3-2
Block Comments
TcpClient Manages the entire connection to the server. It connects by means of the parameters in the Parameters-DB. The file name as well as the CSV data can be sent through it.
DataGenerator Generates one of five possible example CSVs and stores them in the Parameters-DB.
ErrorLogger Writes all the errors from the TcpClient to the ErrorLog-DB.
Status-DB Provides a mirror image of all inputs and outputs of the TcpClient –
suitable for controlling and monitoring the program sequence.
Parameters-DB
Includes the connection parameters.
ErrorLog-DB Includes all recorded errors.
3.2.1 DataGenerator function block
Introduction
This function block simulates the test data for the FB “TcpClient”.
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 15
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Parameter interface
Figure 3-3
Table 3-3
Parameter Declaration Type Comments
SimulationData INPUT exampleDataType The tag includes different tag types that are to be processed to a connected CSV string.
GeneratedCSV OUTPUT String This tag includes the now complete CSV string.
Block description
The block generates one of five possible data records - depending on a hash function and makes a CSV string out of it. The function block receives the currently selected data for the data record via the “SimulationData” input and also writes it back there. The ready CSV string is always created on the “GeneratedCSV” output.
3.2.2 ErrorLogger function block
Introduction
This function block records all occurring errors in a data block.
Parameter interface
Figure 3-4
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 16
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Parameter Declaration Type Comments
ErrorTrigger INPUT Bool As soon as this tag creates a positive edge, the current error code of the TcpClient FB is saved in the “ErrorLog” data block.
Status INPUT Word The status pending here is processed in the block as soon as a positive edge is pending at ErrorTrigger. The status arises from the status DB in the program example, which gets it directly from the TcpClient.
Block description
The block shifts all data records of the ErrorLog DB down by one data record and then writes the current error in the first place that has become free now. The function block is triggered via the error status bit of the TcpClient on the “ErrorTrigger” input. As soon as the DB is filled, the oldest errors are overwritten by newer ones.
3.2.3 Data blocks
ErrorLog data block
Figure 3-5
The ErrorLog DB includes an array with 100 elements of the “errorDataType” type. It is made up of an “Error Time” time tag which shows the time the error occurred and an “Error Code” error tag which includes the error code.
The current error is always in the array index 0. Some of the possible error messages belong to the regular sequence of the program, such as, for example, the stopping of the server on the PC side. It is easiest to look for the error messages in the TIA Portal help by pressing the F1 button. For this purpose, simply enter the displayed ErrorCode in the search. The ErrorCodes usually come from one of the following blocks:
TCON
TDISCON
TSEND
TRCV
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 17
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Parameters data block
Figure 3-6
Table 3-4
Tag Description
statSendData The CSV string generated by the DataGenerator FB is temporarily stored here for sending.
statFileName The name of the current file for this connection. It can be entered here. If required, it is later sent to the TCP file server.
statSimulationData Data record currently selected by the DataGenerator FB. It is written in the above mentioned statSendData tag in CSV format.
statConnectionParameters The connection parameters for the TcpClient-FB are configured here. See chapter Getting Started for details.
Status data block
Figure 3-7
The Status DB includes all current output and input data of the TcpClient FBs. Among others, this data block servers for monitoring and controlling the TcpClient FB. The ErrorLogger FB includes its error status of the “statSTATUS” tag, visible here.
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 18
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
3.2.4 TcpClient function block
Introduction
The “TcpClient” function block is the heart of the application on the S7 side. It manages the establishment of the connection as well as its disconnection, and also the sending file name and data to the TCP file server.
Parameter interface
Figure 3-8
Table 3-5
Parameter Declaration Type Comments
EnableCommunication INPUT Bool
Starts a connection establishment.
SendFilename INPUT Bool A rising edge sends the file name to the TCP file server
SendData INPUT Bool A rising edge sends the current data to the TCP file server
ConnectionParameters INPUT TCON_PAR Includes the connection configuration.
Filename INPUT String[50] File name for the transfer.
Data INPUT String User data for the transfer.
ReadyToSend OUTPUT Bool If true: last established connection was successful.
Done OUTPUT Bool Is true, if sent successfully or connected
Busy OUTPUT Bool Is true if a job is still carried out.
Error OUTPUT Bool Is true if there is an error. This value is pending until another operation has been completed successfully (during operation in the millisecond range)
Status OUTPUT Word Gives information on the current connection status or error status. The respective status is pending until another operation has been
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 19
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Parameter Declaration Type Comments
completed or another error occurred (during operation this means in the millisecond range)
Operating status of the TcpClient FB
Status Description
7001 Busy
8202 Connected
8201 Not connected
The error statuses are instantly passed on by TCON, TSEND, TRCV and TDISCON blocks. These are referenced in the official documentation.
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 20
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
3.2.5 General behavior of the TcpClient program block
Below, you can see a diagram that explains the behavior of the TcpClient function block from the application view. The trapezoids correspond to user actions.
Figure 3-9
Connect
Is there aconnection?
Positive edge:
EnableCommunication
noyes
Positive edge:
SendFilename
Positive edge:
SendData
Send
file name
Error?yes
no
Send
data
DataGenerator
creates CSV
Record
error
ErrorLogger
logs error
Negative edge:
EnableCommunication
Disconnect
connection
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 21
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
3.3 Functionality in the TCP file server
3.3.1 General behavior of the TCP file server software
Introduction
The diagram below describes the concept of all possible sequences within the TCP file server. The trapezoids correspond to user actions. This diagram is deliberately designed in the same style as the above diagram. The two diagrams explain to you the effects of user actions on both sides of the application.
Overview
Figure 3-10
Load GUI
Load the configuration
of known connections
Startserver
Accept
connection requests
Start loggingChange
connection name, file path or write mode
Save
connection configuration
Update
connection table
Accept
connection?
yes
no
Specify port
File name
received?
yes
noData
received?
no
yes
Write data in file
depending on write mode
Stop server
Close
GUI
Update
file table
Does file exist?
Create file
yes
no
Explanation
The TCP file server was programmed in the .NET language C# in Visual Studio 2012. TCP sockets are used for communication.
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 22
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
The server currently allows up to 100 simultaneous connections. The TCP functionality is located in the “TcpLib” class, the largest part of the user interface is managed in the “ServerForm” class and the connections and files are implemented in the “ClientConnection” container class.
With each start of the program, furthermore the last known connection configuration is loaded (deserialization of the ClientConnection object) which also include the associated files. When ending the program the configuration is also respectively saved (serializing of the ClientConnection object). You can adjust the well document C# code to your requirements anytime.
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 23
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
3.4 Details on the interaction of TcpClient and TCP file server
Introduction
The following chapter shows you comprehensively how the two software components “TcpClient” on the S7 side and “TCP file server” on the computer side, interact with each other.
Overview
The diagram shows you what actions lead to what responses in the overall project. For the abbreviations on the side of the TCP file server there is a table under the diagram with paths to the respective methods. The abbreviations on the side of the S7 CPU describe the name of the called blocks.
Figure -311
Computer (TCP file server) S7-CPU (TcpClient)
Co
nn
ecti
on
es
tab
lish
men
tC
om
mu
nic
atio
nD
isco
nn
ecti
ng
pro
cess
Not connected
TCP-SYNReceived?
yes
noyes
Send TCP-SYN
Successful?
no
[File name]
Send file name
Received?
Send data
Receiving
Updating Connection
Write Data in file
[Data
no
Disconnectconnection?
Update connection
Not connected
yes
yes
no
yes
Disconnect connection
TCP handshake
TCONTCON
TSEND
TSEND
TDISCON
Ready for communication
TCONTCR
CW
CU
CU
EO
TTC
TCON
Table 3-6
Abbreviation Method path
TCR TcpLib/ConnectionState/Read()
3 Mode of Operation
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 24
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
Abbreviation Method path
TTC TcpLib/TcpServer/ConnectionReady_Handler()
CW ClientConnection/writeCSVToFile()
CU ClientConnection/updateClientConnections()
EO EchoServiceProvider/OnAcceptConnection()
In the table you can see the method paths in the C# project for the abbreviations used in the above diagram.
Explanation
The status diagram displays the correlation between the TcpClient block on the S7 CPU and the TCP file server on a computer. Relevant block calls are marked on some states of the TcpClient.
The not shown TRCV block is used between the states “Not connected” and “Send TCP-SYN”. TRCV is used to detect connection errors and to restart the connection once an error is detected.
4 Installation and Commissioning
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 25
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
4 Installation and Commissioning This chapter describes the steps necessary to start up the example with the code from the download and the hardware list.
4.1 Installing the hardware
The figure below shows the hardware configuration of the application.
Figure 4-1
PROFINET IE
SIMATIC S7-1500 SIMATIC S7-1200SIMATIC S7-300
M (0 V)
L+ (24 V)
PS
TCP fi le server
Hardware configuration of a SIMATIC S7 CPU
Table 4-1
No. Action
1. Insert the individual modules to a suitable module rack.
2. Connect the voltage supply to the power grid (230V AC).
3. Connect the voltage supply to the S7 CPU. Ensure correct polarity.
4. Connect the PROFINET interface of the PG/PC (TCP file server PC) with the subnet of the S7 CPU.
4 Installation and Commissioning
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 26
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
4.2 Commissioning
The following instruction shows how to commission the example project.
Table 4-2
No. Action
1. Install TIA V13 SP1 or higher.
2. Assign an IP from IP band 192.168.0.8-254 to your programming device (subnet: 255.255.255.0). The S7 CPU of the project has the following IP addresses:
S7 1500: 192.168.0.1
S7 1200: 192.168.0.2
S7-300: 192.168.0.3
3. Unzip the .zip file with the S7 project.
4. Start the TCP file server.
5. Click the start server button at the top left.
6. Double-click on the ap13 file in the S7 project folder in order to start the project in TIA Portal.
7. Open the folder with your S7 CPU configuration in the project tree.
8. Open the device configuration of the CPU and exchange it if required, with your specific CPU type and its own specific firmware version.
4 Installation and Commissioning
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 27
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Action
5.a Connection configuration of a 300- or 400-series CPU
In the parameters-DB the statConnectionParameters are to be adjusted as follows:
local_device_id
o 16#2 – for 314C, 315 or 317 CPUs
o 16#3 for 319 CPUs
o 16#6 for 400 CPUs
local_tsap_id: Here, the port number (default is 2000) of the client has to be entered in the first (higher order hex) and the second byte (lower order hex).
rem_staddr: The IP address of the server has to be entered in the first four bytes here. It is the IP address of the local network adapter of the server
4
4 Installation and Commissioning
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 28
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Action
computer which is located in the same subnet as the S7 CPU.
rem_tsap_id: Here, in the first and second byte the port number of the server has to be entered (default is 2000).
5.b Configuring the connection of 1200 or 1500 CPU
In the parameters-DB the statConnectionParameters are to be adjusted as follows:
LOCAL_TSAP_ID: Here, in the first and second byte, the port number of the client has to be entered (default is 2000).
REM_STADDR: The IP address of the server has to be entered in the first four bytes here.
REM_TSAP_ID: Here, in the first and second byte the port number of the server has to be entered (default is 2000).
6. Download the project into the device and confirm all dialogs.
5 Operating the Application
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 29
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
5 Operating the Application The instructions below show how the example project is operated.
Table 5-1
No. Action
1. Open the Main block (OB1) in the TIA Portal and go online.
2. Double-click the TcpFileserver.exe and start the TCP file server.
3. Start the monitoring mode and set a positive edge at “EnableCommunication” on the TcpClient. You can do this in OB1 as well as in the status DB.
OB1:
5 Operating the Application
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 30
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Action
Status-DB:
4. The connection should now be visibly registered at the TCP file server. *
5 Operating the Application
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 31
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Action
5. Assign a value to the file name parameter on the TcpClient in OB1.
6. Set a positive edge on the TcpClient at SendFilename.
7. The file server should now have received the file name.
5 Operating the Application
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 32
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Action
8. Now select a file path for the current connection in order to store all received data in this location with the transferred file names. Once the dialog was confirmed, the file path is automatically saved.
9. Set a positive edge at SendData on the TcpClient in OB1.
10. The TCP file server should now receive the data and attached it in a file.
5 Operating the Application
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 33
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Action
You can see the attached file in the “Connections” tab.
11. Now open the file. You can find the transferred data there.
5 Operating the Application
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 34
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
No. Action
*If the data was not transferred, check your firewall and network adapter settings. The
firewall has to allow a connection via the configured ports and the IP addresses of the network adapter have to be located in the same subnet (provided they have no static IP in the Internet).
6 References
S7-CSV_Server Entry ID: 109475508, V1.0, 04/2015 35
S
iem
en
s A
G 2
01
5 A
ll ri
gh
ts r
ese
rve
d
6 References Table 6-1
Topic Title
\1\ Siemens Industry Online Support
https://support.industry.siemens.com
\2\ Download page of the entry
https://support.industry.siemens.com/cs/ww/en/view/109475508
\3\
7 History
Table 7-1
Version Date Modifications
V1.0 04/2015 First version