Share this

Modbus-based remote temperature sampling control system

2026-04-06 05:09:49 · · #1

Abstract: Modbus is the most commonly used bus in fieldbus applications. This paper mainly introduces a remote temperature sampling control based on Modbus, presents the PLC hardware wiring principle, and explains the software settings and programming. It has achieved good results in practical applications.

Keywords : Modbus; PLC; remote temperature sampling

1. Introduction

Modbus was invented in 1978 by Modicon (now a brand of Schneider Electric). It is a groundbreaking and milestone network protocol, and the world's first bus protocol truly used in industrial field applications.

Modbus's tremendous success can be attributed to the following three aspects:

a. Standardized and Open: Users can use the Modbus protocol for free and with confidence, without paying license fees or infringing on intellectual property rights. Currently, more than 400 manufacturers support Modbus, and there are more than 600 products that support Modbus. Moreover, there are many users in China who support and use Modbus products.

b. Modbus is a message-oriented protocol. It supports various electrical interfaces, such as RS232, RS422, and RS485, and can transmit data over various media, such as twisted-pair cable, fiber optic cable, and wireless radio frequency. It's important to note that, unlike many fieldbuses, it does not use dedicated chips or hardware; it utilizes commercially available standard components. This ensures that products using Modbus are among the most cost-effective.

c. The Modbus protocol's frame format is the simplest and most compact protocol. It can be described as simple, efficient, and easy to understand. Therefore, it is easy for users to use and simple for manufacturers to develop. Users and manufacturers can download sample programs, controls, and various Modbus tools in various languages ​​from www.Modbus-IDA.org and other websites to better utilize Modbus.

This article mainly describes a remote temperature sampling control system based on Modbus, which uses two Siemens S7-200 PLCs to display the PT100 temperature connected to the slave PLC on a temperature meter with a Modbus bus interface.

2. Overall Design of Modbus in Remote Temperature Sampling Control System

The overall system block diagram is shown in Figure 2.1. The S7-200 PLC slave station acquires the temperature signal (i.e., PT100), feeds the information back to the S7-200 PLC master station via Modbus, and then feeds it back to the temperature meter via the Modbus bus. The upper and lower limits of the temperature can be set and output on the indicator lights. This makes it easier to observe temperature changes, record data in real time, and is more user-friendly.

Figure 1 System Overall Block Diagram

(1) Modbus message transmission protocol

Modbus addresses are typically 5 or 6-character values ​​containing a data type and an offset. The first two characters determine the data type, and the last four characters are an appropriate value matching that data type. Modbus master commands can map the address to the corresponding function to send to the slave.

The correspondence between Modbus addresses and S7-200 addresses is shown in Table 1.

Table 1 Maps Modbus addresses to S7-200

000001

Q0.0

000002

Q0.1

000003

Q0.2

000127

Q15.6

000128

Q15.7

010001

I0.0

010002

I0.1

010003

I0.2

010127

I15.6

010128

I15.7

030001

AIW0

030002

AIW2

030003

AIW4

030032

AIW62

040001

HoldStart

040002

HoldStart+2

040003

HoldStart+4

04xxxx

HoldStart+2x(xxxx-1)

The Modbus communication protocol has two message transmission modes: ASCII and RTU (Remote Transmission Unit). All stations in a Modbus network must use the same transmission mode and serial port parameters. This system uses RTU mode, and its message format is shown in Table 2.

Table 2 Message Format in RTU Mode

address

function code

Data 1

Data n

CRC high byte

CRC low byte

Address: Modbus address, 1 byte.

Function code: Modbus function code, 1 byte; the Modbus protocol supports a total of 16 function codes (1-16).

(2) Modbus communication commands

Siemens has developed a dedicated instruction library for Modbus RTU communication, greatly simplifying its development and facilitating rapid application implementation. Through the Modbus RTU slave instruction library, the S7-200 can be integrated into the Modbus network as a slave device to enable communication with Modbus master devices.

The Siemens Modbus master protocol library includes two master protocol commands: MBUS_CTRL and MBUS_MSG. The MBUS_CTRL command is used to initialize master communication, and the MBUS_MSG command (or MBUS_MSG_P1 for port 1) is used to initiate requests to Modbus slaves and process responses.

1) The MBUS_CTRL command is shown in Figure 2.

Figure 2 shows the MBUS_CTRL command. Figure 3 shows the MBUS_MSG command.

The meanings of the main parameters are as follows:

Mode: The "Mode" parameter allows you to select the communication protocol. 1 assigns the CPU port to the Modbus protocol and enables it; 0 assigns the CPU port to the PPI system protocol and disables the Modbus protocol.

Baud: "Baud rate" parameter. The MBUS_CTRL instruction supports baud rates of 19200, 38400, 57600, or 115200 bit/s.

Parity: The "Parity" parameter. The "Parity" parameter is set to match the parity of the Modbus slave. All settings use one start bit and one stop bit. Acceptable values ​​are: 0 - no parity, 1 - odd parity, 2 - even parity.

2) The MBUS_MSG instruction is shown in Figure 3.

The meanings of the main parameters are as follows:

First: The "First" parameter. The "First" parameter should only be opened for a scan when a new request needs to be sent. The "First" input should be opened via an edge-detecting element (e.g., a rising edge), which will cause the request to be sent once.

Slave: The "Slave" parameter. The "Slave" parameter is the address of the Modbus slave, with an allowed range of 0-247. Address 0 is the broadcast address and can only be used for write requests; there is no response to a broadcast request at address 0. Not all slaves support broadcast addresses; the S7-200 Modbus slave protocol library does not support broadcast addresses.

RW: "Read/Write" parameter. The "Read/Write" parameter specifies whether to read or write the message. The "Read/Write" parameter allows the following two values: 0 - read, 1 - write.

Addr: The "address" parameter. The "address" parameter is the starting Modbus address.

Count: The "Count" parameter. The "Count" parameter specifies the number of data elements read or written in this request. The "Count" value is in bits (for bit data types) or words (for word data types).

The Siemens Modbus slave protocol library includes two slave commands: MBUS-INIT and MBUS-SLAVE (Figures 4 and 5).

Figure 4 shows the MBUS_INIT instruction. Figure 5 shows the MBUS_SLAVE instruction.

3. System hardware circuit design

The PLC hardware wiring diagram is shown in Figure 6. The PLC part is omitted, and the external components are mainly introduced.

Figure 6 PLC Hardware Wiring Diagram

(1) Thermometer

Since it is a bus-controlled temperature gauge, an RS485 digital display instrument that supports Modbus is generally selected (as shown in Figure 7).

Figure 7 Temperature gauge

(2) PT100

The Siemens S7-200 supports two types of temperature sensors: resistance temperature detectors (RTDs) and thermocouples. Their temperature modules also differ and must be configured appropriately. Figure 8 shows a commonly used PT100 RTD.

Figure 8 PT100 exterior

4. System software program design

Before programming using the instruction library, a memory area must first be allocated for the Modbus slave; otherwise, the Micro/Win software will report an error during compilation. Open the "Library Memory Area Allocation" dialog box via the Micro/Win software menu command "File" → "Library Memory Area". Enter the starting address of the library memory area in the "Library Memory Area Allocation" dialog box, taking care to avoid this address coinciding with other addresses already used or planned to be used in the program. Click the "Suggested Address" button, and the system will automatically calculate the ending address of the memory area.

For slave stations, the S7-200 uses the ModbusSlave library under the freeport communication mode for Modbus communication. It's important to note the following when using this library: the ModbusSlave library only supports Modbus PTU communication mode and not ASCII communication mode; currently, the ModbusSlave library only supports communication port Port0. When using the ModbusSlave library, careful memory allocation is also crucial; otherwise, numerous compilation errors will occur. (See Figure 9.)

Figure 9 shows that the library being called needs to allocate a system memory address range.

When programming, use SM0.1 to call the subroutine MBUS_INIT for initialization, and use SM0.0 to call MBUS_SLAVE, specifying the corresponding parameters. Detailed explanations of the parameters can be found in the local variable table of the subroutine.

The Modbus slave is initialized as shown in Figure 10.

Figure 10 shows the call to the Modbus PTU communication command library.

The parameters in the diagram have the following meanings:

a. Mode selection: Start/Stop Modbus, 1=Start; 0=Stop

b. Slave address: Modbus slave address, value 1-247

c. Baud rate: Optional 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200

d. Parity check: 0 = no parity; 1 = odd parity; 2 = even parity

e. Delay: Adds a delay between characters; the default value is 0.

f. Maximum I/O bits: The maximum number of I/O points involved in communication. The I/O map area of ​​S7-200 is 128/128, and the default value is 128.

g. Maximum AI word count: The maximum number of AI channels participating in communication, which can be 16 or 32.

h. Maximum Holding Register Area: The largest V memory word (VW) involved in communication.

i. Retain the starting address of the register area: specified by &VBx (indirect addressing mode)

j. Initialization completion flag: Set to 1 after successful initialization.

k. Initialization error code

l. Modbus execution: Set to 1 during communication, and to 0 when there is no Modbus communication activity.

m. Error code: 0 = No error

As can be seen from the program screenshot, the S7-200 acts as a Modbus slave with slave address 10 and the receive memory area starts at VB0.

Before calling Modbus master station commands for programming, a library storage area should also be allocated, similar to slave station programming. The master station main program is shown in Figure 11.

Figure 11 Main Program of the Main Station

5. Conclusion

Modbus is an open communication protocol with two serial transmission modes: ASCII and RTU. These define different ways of packing and decoding data. Both communicating parties must support one of these modes simultaneously; typically, devices supporting Modbus communication also support the RTU format. This article primarily introduces one of these RTU protocols, applied in remote temperature sampling and control. This system can be implemented in harsh working conditions requiring real-time monitoring and control of temperature.

References

[l] Liu Huabo. Selected Application Cases of Siemens S7-200 PLC Programming [M]. Machinery Industry Press, 2010

[2] Li Fangyuan. Learning Siemens Frequency Inverter Applications from Scratch [M]. Machinery Industry Press, 2011.

[3] Li Fangyuan. Learning Siemens S7-200 PLC from Scratch [M]. Machinery Industry Press, 2012.

[4] Li Fangyuan. Siemens S7-200 PLC: From Beginner to Practice [M]. Electronic Industry Press, 2010.

[5] Liao Changchu. S7-200 PLC Programming and Application [M]. Electronic Industry Press, 2008.

Read next

CATDOLL 42CM TPE Baby Doll

Height: 42cm Weight: 2.4kg Shoulder Width: 15cm Bust/Waist/Hip: 28/28/30cm Oral Depth: N/A Vaginal Depth: 5-8cm Anal De...

Articles 2026-02-22