Skip to main content
Logo
Back to Blog List

How to assign values ​​to multiple register indexes when connecting a PLC controller on the Codesys platform to a Modbus-RTU device?

LMS_LiRui2025-09-2542 views

I. Function and Precautions

(1) Functional Description: This document briefly explains how to assign values ​​to multiple register indexes when the PLC controller of the Codesys platform is connected to the Modbus-RTU device.

 

(2) Precautions: When mapping variables, be sure to give the correct data type and data range, otherwise the Modbus slave communication will report an error.

 

II. Operation Steps

(1) Open the Codesys software and connect to the PLC controller.

Figure 2.1

 

(2) Right-click Application, click Add Object, and click DUT.

Figure 2.2

 

(3) Add a union

Figure 2.3

 

(4) Enter DUT and create a uWord data type.

Figure 2.4

 

(5) Enter the Modbus slave, select the Modbus slave channel, add a channel, select Write Multiple Registers as the access type, and then fill in the Modbus register address 0x043B, which is an index that occupies 2 registers. The value type corresponding to the index is an unsigned integer.

Figure 2.5

 

(6) Enter the main program PLC_RPG, create two variables, a DUT type variable DUT_vel, and a variable vel that we use to assign values, as shown in Figure 2.6. Split the value of vel into two according to the high and low bytes and assign them to DUT_vel.uWord[1] and DUT_vel.uWord[0].

Figure 2.6

 

(7) Enter the Modbus slave station, select the I/0 mapping interface, as shown in Figure 2.7, map the two created variables to Channel0[0] and Channel0[1]. And switch the "Always update variable" below to Enable 2.

Figure 2.7

 

(8) After compilation is complete, log in and run the program.

Figure 2.8

 

(9) Enter the main function interface, as shown in Figure 2.9, write the value 300000 to vel.

Figure 2.9

 

(10) As shown in Figure 2.10, we can see that the value is successfully written to the index that occupies 2 registers.

Figure 2.10

Share to:

Related Articles

Related Solutions

Related News

Need help with product selection?

Download the selection guide or consult our engineers to quickly find the right motion control product.