Main Content

Modbus RS485 Client Write

Client device writes data to server device register(s) over RS485 network

Since R2021b

  • MODBUS RS485 Client Write

Libraries:
Simulink Coder Support Package for STMicroelectronics Nucleo Boards / Common
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F746G-Discovery
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32F769I-Discovery
Embedded Coder Support Package for STMicroelectronics STM32 Processors / STM32L475VG-Discovery (B-L475E-IOT01A)

Description

In the Modbus RS485 Client Write block, the client device writes data to the register(s) of the server device.

Simulink® Coder™ Support Package for STMicroelectronics® Nucleo Boards and Embedded Coder® Support Package for STMicroelectronics Discovery Boards supports the Modbus® communication protocol over the RS485 network. The client and the server must be connected on the same RS485 network for successful Modbus communication. Each device on the RS485 network is referenced by a unique 8-bit address or identifier.

This table categories the server device registers referenced by the Modbus client device.

Register TypeRegister SizeAllowed Client Operation on Register
Coil1-bitRead and Write
Discrete Input1-bitRead
Holding Register16-bitRead and Write
Input Register16-bitRead

The client can perform either a read or a write operation (depending on the register type) on register(s) of a server device.

Ports

Input

expand all

The input to the block is the data to be written to the server register(s) by the client as a N-by-1 vector, where N represents the number of registers on the server device.

  • If you select the Coil or Discrete Input write operations, the client writes data to the server registers as a 1-bit write operation having the Boolean data type.

  • If you select the Holding Register or Input Register write operations, the client writes data to the server registers as a 16-bit write operation having the uint16 data type.

Data Types: Boolean | uint16

Output

expand all

The block outputs the status of the client write operation on the client device register.

  • 1: Indicates an unsuccessful write operation to the server registers or didn’t receive the response from the server within the timeout.

  • 0: Indicates a successful write operation to the server registers and received expected response within the timeout.

Dependencies

To enable this port, select the Output status parameter.

Data Types: uint8

Parameters

expand all

Enter the unique 8-bit Modbus server address or identifier to identify the server to which the client writes the data.

Select the type of write operation you want to perform on the server register(s). Specify any one of the following:

  • Write Coil: Write data to the coil register address specified in the Coil Address parameter

  • Write Holding register: Write data to the holding register address specified in the Holding Register Address parameter

  • Write Multiple Coils: Write data to multiple coil registers depending on the values specified in the Coil Address and Number of Coils parameters

  • Write Multiple Holding registers: Write data to multiple holding registers depending on the values specified in the Holding Register Address and Number of Holding registers parameters

  • To notify the client to write data to a specific coil register, specify the coil register address in this parameter. For example, for the client to write data to the coil register with the address 10, enter 10.

  • To notify the client to write data to a group of coil registers, specify the address of the first coil register in the group. For example, for the client to write data to the coil registers with addresses ranging from 10 to 14, enter 10.

Dependencies

To enable this parameter, set Function to Write Coil.

Enter the number of coil registers to which you want the client to write the data. For example, for the client to write data to the coil registers with addresses ranging from 10 to 14, enter 5.

Dependencies

To enable this parameter, set Function to Write Multiple Coils.

  • To notify the client to write data to a specific holding register, specify the holding register address in this parameter. For example, for the client to write data to the holding register with the address 37, enter 37.

  • To notify the client to write data to a group of holding registers, specify the address of the first holding register in the group. For example, for the client to write data to the holding registers with addresses ranging from 37 to 44, enter 37.

Dependencies

To enable this parameter, set Function to Write Holding register.

Enter the number of holding registers from which you want the client to write the data. For example, for the client to write data to the holding registers with addresses ranging from 37 to 44, enter 8.

Dependencies

To enable this parameter, set Function to Write Multiple Holding registers.

When you select the Output Status parameter, the block configures an output port, Status. The port outputs the status message.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2021b