Professional Documents
Culture Documents
Configuration of S7-1200
2. In the new window choose option Configure a device, and then Add new device. Choose
available PLC controller and click Add.
3. On the left side in the Project view, choose Device configuration, and then Configuration
view. Place the mouse pointer on the picture of PLC and click mouse right button. From the
menu choose option Properties. Choose option PROFINET interface in General tab, and then
Ethernet addresses. In part of IP protocol in field IP address write PLCs IP and in the field
Subnet mask right subnet mask.
4. In the next step, choose from the tab PLC_1- at first Program blocks, and then Main. We
are in the main program.
5. From the library Communication choose TRCV_C block and drag to the main window of
program. Click mouse right button on the TRCV_C, choose Properties, and then Connection
parameter. As a Partner choose Unspecified, and then write in the field Address the IP of the
computer with you want to connect. Finally, check Establish active connection on the side of
Partner and write the number of port on which the PLC will work (Picture 1).
1
6. To use TRCV_C function block it is necessary to define three data blocks: TRCV_C_Data,
RECEIVED_Data and PLC_1_Receive_DB. In the first case of TRCV_C_Data block, from
the tab Program blocks you have to choose Add new block, then Data block. In the name of
the block write TRCV_C_Data (the names of all blocks are optional, depend only on user, but
it is recommended to use suggested names), choose as a type Global data. The next step is to
write the names of fields of structure, according to diagram from picture 2.
The last element is to match right fields from TRCV_C_Data with fields in TRCV_C function
block according to their names (e.g. in field DONE you should choose TRCV_C_Data.Done).
7. The next step is to define data type Received_Data_Type which will be type of received
data. In tab PLC data types choose Add new data type. Then change the name of this type and
write right names and types of fields, according to the picture 3.
8. The next step is a definition of RECEIVED_Data block that will be used to save the
received data. From the tab Program blocks choose Add new block, choose Data block, write
its name and choose as a type Received_Data_Block, as in the picture 4.
2
Picture 4. Definition of data block that is a type of Received_Data_Type
After the definition of RECEIVED_Data, write its name in TRCV_C function block in a field
DATA.
9. In a field CON you should choose structure called PLC_1_Receive_DB, as in the picture 5.
3
10. The final effect of the configuration of TRCV_C function block should look like this from
the picture 6.
4
Picture 7. Confguration of TSEND_C
2. The next step is to define a TSEND_C_Data data block, like in the case of structure
TRCV_C_Data. The names of fields of this structure should be declared as in the diagram
from picture 8.
After the definition of TSEND_C_Data data block, you have to match right fields from
TSEND_C_Data with fields in TSEND_C function block according to their names (e.g. in a
field DONE you should choose TSEND_C_Data.Done).
3. The next step is to declare data type Send _Data_Type which will be type of sent data. In
tab PLC data types choose Add new data type, write the name of a type, the field names and
types of fields, according to the picture 9.
5
4. Next, create SEND_Data block that will be used to send program data. From the tab
Program blocks choose Add new block, choose Data block, write its name and choose as a
type Send _Data_Block, as in the picture 10.
After the definition of SEND_Data, write its name in TSEND_C function block in the field
DATA.
5. In a field CON you should choose structure called PLC_1_Receive_DB, as in the picture
11.
6
6. The last stage is a definition of a signal whose positive edge will give a signal to send data
from TSEND_C block. There are a lot of ways to do it and it only depends on the
programmer, but probably one of the best way is to use timer, like in the picture 12. The name
of the variable that activates sending of data should be written in field REQ in TSEND_C
block (in this example this variable is called timer1).
7. The final effect of the configuration of TSEND_C function block should look like this from
the picture 13.
7
1.2. Configuration of UDP protocol
1.2.1. TCON function block
1. Open TIA Portal and choose Portal view. Choose tab Create new project. Write the name of
the project and choose the place to save it.
2. In the new window choose option Configure a device, and then Add new device. Choose
available PLC controller and click Add.
3. On the left side in the Project view, choose Device configuration, and then Configuration
view. Place the mouse pointer on the picture of PLC and click mouse right button. From the
menu choose option Properties. Choose option PROFINET interface in General tab, and then
Ethernet addresses. In the part of IP protocol in field IP address write PLCs IP and in field
Subnet mask right subnet mask.
4. In the next step, choose from the tab PLC_1 - at first Program blocks, and then Main. We
are in the main program.
5. From the library Communication choose block TCON and drag to the main window of
program. Click mouse right button on the TCON, choose Properties, and then Connection
parameter. As a Partner choose Unspecified, and then write in the field Address the IP of the
computer with you want to connect. Finally, check Establish active connection on the side of
Partner and write the number of port on which the PLC will work (Picture 14).
8
9
6. In a field CONNECT you should choose structure called PLC_1_ Connection_DB, as in the
picture 15.
7. Next, write the ID of the connection, e.g. 1 (the value should be from 1 to 4095). In field
REQ you should write TRUE.
9. The last element is to match right fields from CON_Data with fields in TCON function
block according to their names, as in the picture 17.
10
1.2.2. TURCV function block
1. From the library Communication choose TURCV block and drag to the main window of
program. Next, in the fields EN and EN_R write names of variables that should activate this
block. In the field ID write PLC_1_Connection_DB.ID (this structure was used during the
configuration of TCON block and the number ID was defined by the user).
2. The next step is to define a TURCV_Data data block, like in the case of structure
TCON_Data. The names of fields of this structure should be declared as in the diagram from
picture 18.
You have to match right fields from TURCV_Data with fields in TURCV function block
according to their names.
3. Next, you have to create a block that will be used to save IP address and port number of the
computer which communicates with the PLC. In Program blocks choose Add new block, then
Data block and its type TADDR_Param. The name of this Block is ADDRESS_Data,
according to the picture 19.
11
Picture 19. Declaration of ADDRES_Data data block
12
4. The last step is to define data type Received_Data_Type which will be type of received
data. In tab PLC data types choose Add new data type. Then change the name of this type and
write right names and types of fields, according to the picture 20.
5. Next, create RECEIVED_Data block that will be used to save the received data. From the
tab Program blocks choose Add new block, choose Data block, write its name and choose as a
type Received_Data_Block. RECEIVED_Data data block should be assigned to the field
DATA in TURCV function block.
6. The final effect of the configuration of TURCV function block should look like this from
the picture 21.
13
1.2.3. TUSEND function block
1. Drag TUSEND block from library Communication to the main window of the program.
2. We start the configuration of TUSEND block in the same way as in the case of TURCV
block. In the field ID write PLC_1_Connection_DB.ID (this structure was used during the
configuration of TCON block and the number ID was defined by the user). Next, in the field
ADDRESS write ADDRESS_Data (this variable was created in the paragraph 1.2.2 in point 3).
Now, you have to create TUSEND_Data, data block according to picture 22.
Match fields of TUSEND function block with fields from TUSEND_Data data block
according to the names.
3. Next step consists of definition of Send_Data_Type data type. To do this, in tab PLC data
types choose Add new data type, write the right name and create a structure like this from the
picture 23.
4. Create SEND_Data data block it means that you have to choose Program blocks tab, then
Add new block tab, then Data block and choose Send_Data_Type as a datatype. SEND_Data
data block should be assigned to the field DATA in TUSEND function block.
14
5. In the TUSEND function block in field REQ it is necessary to write the name of the variable
that is responsible for cyclic activation of this function block. It seems that the best way is to
use a timer like in the picture 24. In this case, the data will be sent cyclically with the
positive edge of variable timer1.
6. The final effect of the configuration of TURCV function block should look like this from
the picture 25.
15
1.3. Program on the side of PLC
1. When you have configured the function and data blocks according to the instructions from
paragraph 1.1 or 1.2, the programmer must decide which variables will be sent and received.
The programmer can send and receive boolean (Byte) and float (Real) variables.
2. In the case of receiving data by PLC, the programmer copies variables from
RECEIVED_Data block (this block was defined in par. 1.1.1 point 8 for TCP protocol and in
par. 1.2.2 point 5 for UDP protocol). In the picture 26, it is shown how to do it the variable
RECEIVED_Data.table_DI[0] .x0 is a boolean variable (which is being sent from Simulink
and it is being received in the PLC), then this value is being copied to the variable zmienna2
which is of BOOL type. Some explanation - the boolean variables in the computer are of type
boolean which is the same one as unsigned char or BYTE, but on the side of PLC bool means
single BIT, so to get the value of this bit you have to use .x0. In the picture 27, it is shown
how to copy float variable RECEIVED_Data.table_AI[0] to the variable zmienna1 of type
REAL.
16
3. In the case of sending data from PLC to PC, the user moves variables to SEND_Data block
(this block was defined in par. 1.1.2 point 4 for TCP protocol and in par. 1.2.3 point 4 for UDP
protocol). In the picture 28, it is shown how to do it the variable zmienna3 which is of
BOOL type is being moved to the variable SEND_Data.table_DI[0] .x0 of Byte type (that
variable is being received in Simulink), then this value is being copied to the variable
zmienna3 which is of BOOL type. In the picture 29, it is shown how to move Real variable
zmienna4 to the variable RECEIVED_Data.table_AI[0] that is of type REAL.
17
2. Configuration on the side of Simulink
18
2.2. Simulation on the side of Simulink
1. To send data to PLC of type:
float the programmer must assigns appropriate signals (analog) to the port AI of
KLIENT block,
boolean the programmer must assigns appropriate signals (digital) to the port DI of
KLIENT block,
3. Exemplary assignment of signals is presented in the picture 31. You have to be aware that
in the case of feedback you cannot match directly output ports with input ports of KLIENT
block, but you have to use Unit Delay block, otherwise Simulink will show errors (this block
Unit Delay is not necessary when you use any S-function or digital blocks in the feedback
loop). Similarly you cannot match boolean signals with float port and on the contrary (if you
have to use any kind of converter).
19