Programming an S7 Communication between two CPU modules for STEP 7 and CFC
You can use the communication blocks AS_BSEND and AS_BRECV for data communication between two CPU modules of an S7 Communication. These include the call of the system function blocks SFB12 (BSEND) for sending and SFB13 (BRCV) for receiving.
- In STEP 7 the communication blocks AS_BSEND and AS_BRECV are called in the prepared blocks SEND_S7 and RECV_S7. You can edit these blocks in the LAD/FBD/STL editor.
- In S7-SCL the communication blocks AS_BSEND and AS_BRECV are called in the prepared blocks SEND_SCL and RECV_SCL. You can edit these blocks in the S7-SCL editor.
This gives you the opportunity of individually adapting the structure of the data to be transferred.
The system function blocks BSEND and BRCV contain an ANY pointer as interface for the send and receive buffer so that you must copy the data to be transferred into the send buffer or receive buffer respectively before or after calling the communication blocks. You also need to program for the evaluation of the responses of the system function blocks, because the status bits DONE, NDR and ERR, and error display STATUS are available only for one cycle.
This S7 Communication can be used for CPU modules that support the communication blocks BSEND and BRCV. The communication is achieved with STEP 7 or with the options packages S7-SCL and CFC.
A connection of the data to be transferred and coordination of the communication jobs are made available. The blocks SEND_S7 and RECV_S7 are available as LAD/FBD/STL blocks and the blocks SEND_SCL and RECV_SCL are available as S7-SCL sources. In all blocks, all you have to do is change the interface if you wish to change the structure of the data to be transferred.
Description of the sample program:
The sample program includes the S7 stations "SIMATIC 400 SEND" and "SIMATIC 400 RECV". The two S7 stations are networked with each other via an MPI connection. An S7 connection has been set up between the two stations in NetPro in order to enable communication via BSEND and BRECV.
In the "SIMATIC 400 SEND" station a structure named DATA has been defined as a sample input parameter in the SEND_S7 or SEND_SCL block. The same structure is also included as output parameter in the "SIMATIC 400 RECEIVE" station. This structure is located in each case between the parameters FIRST_VAR and LIMIT_VAR, which serve to limit the send/receive buffer.
If you wish to change the data area to be transferred, then in the corresponding blocks SEND_S7 and RECV_S7 or SEND_SCL and RECV_SCL you must replace the DATA parameter by the required data structure that is identical in both blocks. Here, it doesn't have to be a structure, but can also be any number of variables up to the maximum possible data length. When using CFC you must make sure that the variables are not of the data type ARRAY.
- When using S7-SCL or in the LAD/FBD/STL editor, the parameters must set or cleared.
- In use with CFC you can interconnect the parameters as you wish.
Fig. 02 shows the interconnection of the SEND_SCL block in CFC.
Fig. 03 shows the interconnection of the RECV_SCL block in CFC.
Error displays are deleted when the CPU starts up. If the error history is to be reset, you must set the input RES_HIST at startup. You can program this in the SEND_S7 and SEND_SCL blocks or in the RECV_S7 and RECV_SCL blocks accordingly.
Connecting online help to the blocks "AS_BRECV" and "AS_BSEND":
In order to connect the help files for the "AS_BRECV" and "AS_BSEND" blocks you must make the appropriate entries in the Registry. Mark the blocks with the cursor and press the F1 key. Then the self-made online help for these blocks ("S7COMSCLA.hlp") is displayed. More information on connecting self-made online help and the necessary requirements are available in our FAQ:
- How do you link a self-made online help to a programmed block?
Entry ID 23174950.
The table below contains the interfaces of the input and output parameters of function blocks SEND_S7, RECV_S7, SEND_SCL and RECV_SCL.
|Input and output parameters of the communication blocks:||
|SEND_S7: Send block for the LAD/FBD/STL editor||Fig. 04|
|RECV_S7: Receive block for the LAD/FBD/STL editor||Fig. 05|
|SEND_SCL: Send block for the CFC editor:||Fig. 06|
|RECV_SCL: Receive block for the CFC editor||Fig. 07|
Notes on configuring when using other modules:
The two STEP 7 projects "COMM_STEP7" and "COMM_CFC_SCL" have been configured with the two S7-400 modules CPU 416-2DP and CPU 414-2DP. If, after loading the projects, you configure other CPU modules, then please follow the notes in the table below. The configurations given below after replacing the modules or reconfiguring the hardware are obligatory for the S7-MPI connection.
|No.||Notes on configuring new CPU modules for the MPI connection:|
|1||Open the hardware configuration in the S7 station at the point where you have replaced or reconfigured CPU modules and with a double-click open the Properties of the "MPI/DP" interface. Then in the "Properties - MPI/DP" dialog, you open the "General" tab and click on the "Properties..." button.
Check according to Fig. 08 whether the interface type is set to "MPI" and networked with the MPI bus. Both CPU modules in the stations must be networked with the same MPI bus (as here in the example "MPI(1)").
|2||Then also in the "Properties - MPI Interface" dialog you click on the "Properties..." button and in the "General" tab check the "S7 subnetwork ID". The number of the "S7 subnetwork ID" must be identical with the connection ID parameter "ID" for the blocks "AS_BSEND" and "AS_BRECV". The number "0001" has been configured for the "ID" of both blocks and thus the "S7 subnetwork IDs" should be set to "0001" (for Send/Receive) in both S7 stations. You can also change the connection ID in OB35 and in OB100 for both stations.
Terminate all the dialogs with OK and save and compile the hardware configuration.
|3||Then open NetPro either via the icon or via "Options > Configure Network". To set up an S7 connection you mark the CPU (e.g. CPU416-2DP) in a station and select the function "Add > New Connection...". In the dialog "Add new connection" you mark the CPU available for your connection (in our example CPU 414-2DP as shown in Fig. 10) and click on the "Apply" button.
Acknowledge the "Properties - S7 Connection" dialog that opens with OK. STEP 7 enters the connection of the node marked in the connection table and assigns the local ID for that connection, which you need for programming the communication blocks.
Save and compile the configuration in NetPro and load the stations into the modules via "PLC > Load in current project > Marked and partner stations".
More information about setting up an S7 connection is available in our FAQ "Notes on using the system function blocks SFB12 and SFB13 (BSEND/BRCV)" in Entry ID: 1152252.
Copy and extract the "ComSTEP7.zip" and "ComS7CFC.zip" in a separate directory. The STEP 7 projects are then extracted automatically with all the associated subfolders. You can then use the SIMATIC Manager to open and process the extracted projects.
Runnability and test environment:
The following table lists the components that have been used to create this entry and verify the functions described.
|PC platform||Intel(R) Pentium(R) M Processor 1.73 GHz, 1.49 GB RAM|
|PC operating system||MS Windows XP Professional SP2|
|STEP 7||STEP 7 Professional V5.3 SP3|
|Options packages||CFC V6.1 SP1|
(S7-SCL V5.3 SP1)*
|S7 CPUs||CPU 416-2DP (6ES7 416-2XK02-0AB0)|
CPU 414-2DP (6ES7 414-2XG03-0AB0)
The data type "UDT" is not supported by the "BSEND" and "BRECV" building block. More Information to this topic could you find under the online help of SFB12 "BSEND" and SFB13 "BRECV".