A brief discussion on Modbus TCP communication technology of S7-300 CPU integrated PN port configuration

Publisher:gamma13Latest update time:2024-03-06 Source: elecfansKeywords:S7-300  CPU  Modbus  TCP Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

2. Configure the S7-300 single-station system to use the CPU integrated PN port as a Client for Modbus TCP communication

The following takes the S7-300 single-station system and Modbus Slave software as an example to introduce in detail how to configure the integrated PN port of the S7-300 single-station system CPU as a Client and the Modbus Slave as a Server for Modbus TCP communication.


2.1 Hardware and Software

The hardware devices used in this example are as follows:

name quantity Order Number
S7-300 power supply module PS 307 10A 1 6ES7307-1KA02-0AA0
S7-300 CPU317-2PN/DP 1 6ES7317-2EK14-0AB0(V3.2)
Network cable Several
Laptop 1

The software used is as follows:

name Order Number
STEP7 V16 Update3 configuration and programming software
Modbus Slave License-free Version Available free online

2.2 S7-300 single station system and Modbus Slave software configuration

Open the TIA software, create a new project file, name it "PN_MODBUS TCP Client", and insert an S7-300 station under the project, as shown in Figure 1 below:

0aa95a00-6c1d-11ee-939d-92fbcf53809c.png

Figure 1 New S7-300 Station

Open the device view and modify the IP address of the CPU. In this example, set the PN port IP address of the CPU to 192.168.0.220, as shown in Figure 17 below:

0ace6886-6c1d-11ee-939d-92fbcf53809c.png

Figure 2 Setting the CPU IP address in the device view

2.3 Configuring technology objects

①Select and add the technological object "Modbus" --- "Other" --- "MODBUS TCP" --- "MB_PN_PARAM"

0ae53dae-6c1d-11ee-939d-92fbcf53809c.png

Figure 3 Adding a new process object

②Set “Connection Settings”

Connection ID: Connection reference identifier (range 1~4095), which will be used when calling the command later

Connection establishment: PLC acts as MODBUS TCP client and selects active.

Remote IP address: The IP address in the figure (192.168.0.228) is the IP address of the laptop

Local Device ID: Select the device type of the PLC

Local port: As a client, you do not need to specify a fixed port

Partner port: Port 502 in the figure is the port number of Modbus Slave

0b0714b0-6c1d-11ee-939d-92fbcf53809c.png

Figure 4 Configuration technology object

③Modbus setting "Internal"

0b0e875e-6c1d-11ee-939d-92fbcf53809c.png

Figure 5 Configuration technology object

③Modbus setting "data area"

In the figure below, 4 Modbus data areas are set

0b326db8-6c1d-11ee-939d-92fbcf53809c.png

Figure 6 Configuration technology object

2.4 Add data blocks according to the data areas created in the technology object

According to the data area set in step 3.3 of the process object, add four data blocks, as shown in the figure below

0b44d390-6c1d-11ee-939d-92fbcf53809c.png

Figure 7 Creating a data block

0b5e1756-6c1d-11ee-939d-92fbcf53809c.png

Figure 8 Creating a data block to store MODBUS coil data

0b73c524-6c1d-11ee-939d-92fbcf53809c.png

Figure 9 Creating a data block to store MODBUS digital input types

0b85d2aa-6c1d-11ee-939d-92fbcf53809c.png

Figure 10 Creating a data block to store MODBUS holding register data

0b8b96cc-6c1d-11ee-939d-92fbcf53809c.png

Figure 11 Creating a data block to store MODBUS input register data

2.5 Create a data block with registry keys that can be used for authorization

Create an authorization key data block DB3 (name REG_KEY), select the type as "Global DB", open the DB block, create a variable "REG_KEY", and set the data type to "String[17]", as shown in the figure:

0ba37d14-6c1d-11ee-939d-92fbcf53809c.png

Figure 12 Creating a data block to store the authorization code

For how to obtain the authorization key, refer to //www.ad.siemens.com.cn/productportal/Prods/published/Comm/Comm_9.4/Comm_9.4.html

2.6 Calling OB121

Because the "MODBUSPN" instruction is in an unauthorized state before obtaining the authorization key, the CPU will report an error and shut down. In order to read the "IDENT_CODE" code of the CPU, the CPU needs to be running, and the programming error organization block OB121 must be added, as shown in the following figure:

0bc00178-6c1d-11ee-939d-92fbcf53809c.png

Figure 13 Calling OB121

2.7 Calling communication instructions

Call the MODBUS TCP instruction (Communication---Others---MODBUS_TCP---MODBUSPN) and fill in the parameters.

In order to find the cause when communication fails, program segment 2 is written to capture the error code.

0bda45ba-6c1d-11ee-939d-92fbcf53809c.png

Figure 14 Calling the "MODBUSPN" instruction

2.8 Initialization Instructions

Create a startup organization block OB100 (name COMPLETE RESTART), the language is "STL", open the OB block, and set the initialization bit input pin register, as shown in the figure:

0bf251dc-6c1d-11ee-939d-92fbcf53809c.png

Figure 15 Initialize the "MODBUSPN" instruction

2.9 Communication Test

Example 1: The client reads the server's [digital input], offset 3, length 2 data

0bfd2bd4-6c1d-11ee-939d-92fbcf53809c.png

Figure 16 Communication test example

Example 2: The client reads the server's [input register], offset 0, length 3 data

0c2ae84e-6c1d-11ee-939d-92fbcf53809c.png

Figure 17 Communication test example

Example 3: The client reads the server's [coil register], offset 0, length 8 data

0c3588a8-6c1d-11ee-939d-92fbcf53809c.png

Figure 18 Communication test example

Example 4: The client reads the server's [holding register], offset 0, length 3 data

0c4e4794-6c1d-11ee-939d-92fbcf53809c.png

Figure 19 Communication test example

Example 5: The client writes data to the server [holding register], offset 5, length 5 data

0c5b1e24-6c1d-11ee-939d-92fbcf53809c.png

Figure 20 Communication test example

Example 6: The client writes data to the server [coil register], offset 0, length 8 data

0c6588c8-6c1d-11ee-939d-92fbcf53809c.png

Figure 21 Communication test example

3. Configure the S7-300 single-station system to use the CPU integrated PN port as a server for Modbus TCP communication

The following takes the S7-300 single-station system and ModScan32 software as an example to introduce in detail how to configure the integrated PN port of the S7-300 single-station system CPU as a server and ModScan32 as a client for Modbus TCP communication.

3.1 Hardware and software used in the examples

The hardware devices used in this example are as follows:

name quantity Order Number
S7-300 power supply module PS 307 10A 1 6ES7307-1KA02-0AA0
S7-300 CPU317-2PN/DP 1 6ES7317-2EK14-0AB0(V3.2)
Network cable Several
Laptop 1

The software used is as follows:

name Order Number
STEP7 V16 Update3 configuration and programming software
ModScan32 License-free version Available free online

3.2 S7-300 single station system and ModScan32 software configuration

Open the TIA software, create a new project file, name it "PN_MODBUS TCP Server", and insert an S7-300 station under the project, as shown in the following figure:

0aa95a00-6c1d-11ee-939d-92fbcf53809c.png

Figure 22 Create a new S7-300 Station

Open the device view and modify the IP address of the CPU. In this example, set the PN port IP address of the CPU to 192.168.0.220, as shown in Figure 17 below:

0ace6886-6c1d-11ee-939d-92fbcf53809c.png

Figure 23 Setting the CPU IP address in the device view

3.3 Configuring technology objects

① Add a new process object, select "Modbus"---"Other"---"MODBUS_TCP"---"MB_PN_PARAM"

0ae53dae-6c1d-11ee-939d-92fbcf53809c.png

Figure 24 Adding a new process object

②Set “Connection Settings”

Connection ID: Connection reference identifier (range 1~4095), which will be used when calling the command later

Connection establishment: PLC acts as MODBUS TCP server and selects passive.

Remote IP address: You can specify or not specify the IP address of the connection partner.

Local Device ID: Select the device type of the PLC

Local port: Specify a fixed port

Partner port: Not specified

0cb958f4-6c1d-11ee-939d-92fbcf53809c.png

Figure 25 Configuring technology objects

③Modbus setting "Internal"

0cde1ad6-6c1d-11ee-939d-92fbcf53809c.png

Figure 26 Configuring technology objects

④Modbus Setting "Data Area"

In the figure below, 4 Modbus data areas are set

0cf9821c-6c1d-11ee-939d-92fbcf53809c.png

Figure 27 Configuring technology objects

3.4 Add data blocks according to the data areas created in the technology object

According to the data area set in step 3.3 of the process object, add four data blocks, as shown in the figure below

0b44d390-6c1d-11ee-939d-92fbcf53809c.png

Figure 28 Creating a data block

0b5e1756-6c1d-11ee-939d-92fbcf53809c.png

Figure 29 Creating a data block to store MODBUS coil data

0b73c524-6c1d-11ee-939d-92fbcf53809c.png

Figure 30 Creating a data block to store MODBUS digital input types

0b85d2aa-6c1d-11ee-939d-92fbcf53809c.png

Figure 31 Creating a data block to store MODBUS holding register data

0b8b96cc-6c1d-11ee-939d-92fbcf53809c.png

Figure 32 Creating a data block to store MODBUS input register data

3.5 Create a data block with registry keys that can be used for authorization

Create an authorization key data block DB3 (name REG_KEY), select the type as "Global DB", open the DB block, create a variable "REG_KEY", and set the data type to "String[17]", as shown in the figure:

0ba37d14-6c1d-11ee-939d-92fbcf53809c.png

Figure 33 Creating a data block to store the authorization code

For how to obtain the authorization key, refer to //www.ad.siemens.com.cn/productportal/Prods/published/Comm/Comm_9.4/Comm_9.4.html

3.6 Calling OB121

Because the "MODBUSPN" instruction is in an unauthorized state before obtaining the authorization key, the CPU will report an error and shut down. In order to read the "IDENT_CODE" code of the CPU, the CPU needs to be running, and the programming error organization block OB121 must be added, as shown in the following figure:

0bc00178-6c1d-11ee-939d-92fbcf53809c.png

Figure 34 OB121

3.7 Calling communication instructions

Call the MODBUS TCP instruction (Communication---Others---MODBUS_TCP---MODBUSPN) and fill in the parameters.

In order to find the cause when communication fails, program segment 2 is written to capture the error code.

0bda45ba-6c1d-11ee-939d-92fbcf53809c.png

Figure 35 Calling the "MODBUSPN" instruction

3.8 Initialization Instructions

Create a startup organization block OB100 (name COMPLETE RESTART), the language is "STL", open the OB block, and set the initialization bit input pin register, as shown in the following figure:

0bf251dc-6c1d-11ee-939d-92fbcf53809c.png

Figure 36 Initialization "MODBUSPN" instruction

3.9 Establishing a connection with the client

Enable the server side and establish a connection using ModScan32 according to the following settings:

0dba4718-6c1d-11ee-939d-92fbcf53809c.png

Figure 37 Establishing a connection with the client

3.9 Communication Test

Example 1: The client reads and writes the server [coil register], offset 0, length 10 data

[1] [2]
Keywords:S7-300  CPU  Modbus  TCP Reference address:A brief discussion on Modbus TCP communication technology of S7-300 CPU integrated PN port configuration

Previous article:S7-200 PROFINET communication and SINAMICS library configuration and programming steps
Next article:For permanent magnet motors, what aspects are included in the processes required to complete motor manufacturing?

Recommended ReadingLatest update time:2024-11-16 09:24

Master the methods and techniques to easily learn 51 single chip microcomputer
A single-chip microcomputer is a type of microcomputer. Currently, there are 8051, AVR, ARM7, ARM9 and other series. Among them, "8051" is derived from Intel's MCS-51 series chips, but different manufacturers currently focus on compatible chips, such as Ateml's 89C51/89S51 system and Macrocrystalline's STC89C52RC. Thi
[Microcontroller]
Master the methods and techniques to easily learn 51 single chip microcomputer
Five times in seven years! Andes Technology becomes the largest supplier of RISC-V CPU IP
Since its IPO in 2017, Andes Technology has been continuously strengthening its leadership position in the RISC-V CPU IP field, with sales increasing fivefold in the past seven years and annual revenue exceeding NT$1 billion. Andes invests capital and R&D manpower to accelerate the launch of high-end products to ensur
[Semiconductor design/manufacturing]
Five times in seven years! Andes Technology becomes the largest supplier of RISC-V CPU IP
MCU Interrupt System (I)
        I have wanted to summarize the interruption for a long time, but I always feel that there are too many things in one chapter and I don’t know where to start.         A few days ago, I saw a sentence: "You have really learned something only if you can express it." Today, I will learn about this interrupt syst
[Microcontroller]
MCU Interrupt System (I)
Processor Architecture (V) armv4v5v6 Architecture Reference Manual (1) Overview and CPU Architecture
Overview DDI0100I_armv5_architecture_reference_manual is divided into several parts CPU architecture Memory and system architecture VFP Architecture Debug architecture CPU architecture (part A) CPU architecture Introduction to arm architecture Achieving small size, high performance and very low power con
[Microcontroller]
AMD is coming with great momentum. Has Intel launched a price killer for its server CPU?
Industry sources said that in response to the impact from AMD, Intel is offering more competitive prices for its server CPUs, and many data center operators that have begun using AMD-based servers have considered switching to Intel. According to Electronic Times, in March this year, AMD released the EPYC 3 serv
[Mobile phone portable]
Huawei: ARM supply cut has no impact, we have prepared our own CPU
Recently, Liang Quan, spokesperson and head of the marketing department of ARM China, clarified for the first time as an official of ARM China that it was untrue that Arm and Arm China had stopped supplying Huawei, and said that they are still cooperating with Huawei and that the subsequent infrastructure can also be
[Embedded]
Latest Embedded Articles
Change More Related Popular Components
Guess you like

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号