communicate two PLC CPU
Hi, see this tread from Siemens Site, hope u will find useful,
(Khairul Basar)
**How is an open TCP communication connection established between two S7-300 PN CPUs, and how is data exchanged?
Instructions:
The attached sample program shows how two ST-300 stations with the CPU315-2 PN/DP are connected via the integrated PROFINET interface and how data can be exchanged with the aid of open TCP/IP communication.
( 36 KB )
Fig. 01: Communication between two CPU315-2 PN/DPs via Ethernet
The connection on the PN CPU is not configured in NetPro. The requisite parameters are saved in a user-defined structure (UDT) in a data block. The connection is established in runtime by calling the FB65 ("TCON") function block. Once the connection with the partner station is established, data can be exchanged by means of the FB63 ("TSEND") and FB64 ("TRCV") function blocks. The FB66 ("TDISCON") function block disables the connection again.
Features of communication and of the function blocks for open communication:
- Communication is connection-oriented, i.e. data transfer does not occur until (and only for as long as) a connection is established with the partner station
- All the requisite connection settings (e.g. IP address) must be saved in a data block whose structure is specified by the UDT65
- If a connection has been established, it is monitored by the CPU and, if it is interrupted, reconnection occurs automatically
- All four function blocks work asynchronously and can last several OB1 cycles
- TSEND and TRCV can communicate simultaneously via one connection
- Data blocks up to a size of 1460 bytes can be sent and received
- The blocks are contained under "Standard Library -> Communication Blocks"
Description of the sample program:
The sample program comprises two separate projects. The projects are separated in terms of the way the connection is established (active/passive). In the description below, the station which establishes the connection actively is called the active station and the station which establishes the connection passively is called the passive station. This designation has nothing to do with transmitting and receiving. Both the active and the passive stations can transmit and receive (including on the same connection).
The connection settings are saved in the DB5 ("CON settings") data block and have been created using the Open Communication Wizard. You can find this wizard and a guide to it in Entry ID
25209116.
The following figure illustrates which parameters are, or have to be, known in the active and passive stations, apart from the unique IP address.
Active stationPassive stationOwn IP address140.140.140.62140.140.140.64
Subnet mask255.255.0.0255.255.0.0Remote IP address140.140.140.64140.140.140.62Local TSAP/port(2000)2001Remote TSAP/port2001(2000)
In this example, the functionality of the T-blocks is encapsulated in an FB with a simple user interface. Here, the FB100 ("my_SEND") is called in the active station, and the FB101 ("my_RECV") is called in the passive station.
How the FB100 ("my_SEND") operates:
The FB100 is called in the OB1 cycle. The calls for the FB65 ("TCON"), FB63 ("TSEND") and FB66 ("TDISCON") can be found in this FB.
Fig. 02
REQ:Communication job starts on receipt of a positive edgeDONE:Signals that a job has been successfully completedHOLD_CON:If this marker is set, disconnection does not occurBUSY:Signals that a job is being processedID:Connection ID (must match the ID in the connection data block)ERROR:Signals that an error has occurred during the processing of an order (precise error codes in the instance data block)LEN:Length of data being sent in bytesSTATUS:Internal status of the FB100CON settings:ANY pointer to the connection data block
A communication job is initiated when the REQ input receives a positive edge, and the data with length LEN is transmitted from the DB6 ("SEND_DATA"). Since communication runs asynchronously, the block is locked internally, i.e. a new job cannot be started until there is no other job running. Via the HOLD_CON input parameter you can indicate whether to maintain the connection with the partner or to disconnect after each transmission.
The ID input parameter must match the connection ID in the "CON settings" data block. The LEN input parameter characterizes the length of data being sent in bytes. At the "CON settings" parameter, a reference is made to the connection parameters in the form of a UDT65 as an ANY pointer (in this example, a reference to DB5 "CON settings").
The output parameters DONE, BUSY, ERROR and STATUS are required for the job evaluation and are only valid in the same cycle. N.B. The output parameters only describe the status of the FB100. You can find further status parameters (TCON, TSEND, TDISCON) in the instance data block for the FB100.
Note:
Since data can only be transmitted while there is a connection in place, the partner may receive incomplete data, and thus an invalid frame, if disconnection occurs immediately after transmission. Therefore, we would advise you to set the HOLD_CON parameter to "true", in general, when calling the FB100.
Pn_cpu_a.zip ( 341 KB )
The STEP 7 project contains an executable sample program for calling the FB100, as well as the FB100 with all the sub-blocks. It has been created with STEP 7 V5.4.
How the FB101 ("my_RECV") operates:
The FB101 is called in the OB1 cycle. The calls for the FB65 ("TCON"), FB64 ("TRCV") and FB66 ("TDISCON") can be found in this FB.
Fig. 03 EN_R
ata can be received if "true" is setNDR:Signals that a new data record has been receivedHOLD_CON:If this marker is set, disconnection does not occurERROR:Signals that an error has occurred during the processing of an order (precise error codes in the instance data block)ID:Connection ID (must match the ID in the connection data block)STATUS:Internal status of the FB100LEN:Length of data due to be received in bytesRCVD_LEN:Length of data received in bytesCON settings:ANY pointer to the connection data block
If an input EN_R is set (true), the communication blocks are called and data is received. The received data is saved in DB7 ("RECV_DATA"). If EN_R is not set (false), communication is interrupted. Re-initialization occurs the next time a positive edge is received. Via the HOLD_CON input parameter you can indicate whether to maintain the connection with the partner or to disconnect after receiving each communication.
The ID input parameter must match the connection ID in the "CON settings" data block. The LEN input parameter characterizes the length of data being received in bytes. At the "CON settings" parameter, a reference is made to the connection parameters in the form of a UDT65 as an ANY pointer (in this example, a reference to DB5 "CON settings").
The output parameters DONE, ERROR and STATUS are required for the job evaluation and are only valid in the same cycle. N.B. The output parameters only describe the status of the FB101. You can find further status parameters (TCON, TRECV, TDISCON) in the instance data block for the FB101.
Pn_cpu_p.zip ( 335 KB )
The STEP 7 project contains an executable sample program for calling the FB101, as well as the FB101 with all the sub-blocks. It has been created with STEP 7 V5.4.
Commissioning the active and passive stations:
No.Procedure1Load the file "Pn_cpu_a.zip" or "Pn_cpu_p.zip" onto your PC.
2Extract the archive with STEP 7.
3If you wish to change the PC's IP address or subnet mask, you have to do this in the HWCONFIG as well as in the connection specification. In the event of a change in the connection specification, you are advised to generate a new UDT (using the Open Communication Wizard, Entry ID
25209116). You can then also recreate the connection data block (in this case, DB5 "CON settings").
4Load the project into the station.5Start to establish the connection by activating the FB100 and FB101 blocks via the M120.0 ("Control" variables table).