Main Content

Modbus TCP/IP Master Write

Master device writes data to slave device register(s) over TCP/IP network

  • Library:
  • Simulink Support Package for Raspberry Pi Hardware / Network

  • Raspberry Pi MODBUS TCP/IP Master Write icon

Description

In the Modbus TCP/IP Master Write block, the master device writes data to the register(s) of the slave device.

Simulink® Support Package for Raspberry Pi™ Hardware supports the MODBUS® communication protocol over the TCP/IP network. The master (client) and the slave (server) must be connected to the TCP/IP network for successful MODBUS communication.

The master can perform either a read, write, or a read and write operation on the slave register depending on the slave register(s) type.

Register TypeRegister SizeOperation Performed by Master
Coil1-bitRead and Write
Discrete Input1-bitRead
Holding Register16-bitRead and Write
Input Register16-bitRead

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

Ports

Input

expand all

The input to the block is the data that the master writes to the slave register(s). Specify the input data as a N-by-1 vector, where N represents the number of registers on the slave device.

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

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

Data Types: Boolean | uint16

Parameters

expand all

Enter the IP address of the slave device to identify the slave to which the master writes the data.

Select the type of write operation you want to perform on the slave 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 master to write data to a specific coil register, specify the coil register address in this parameter. For example, for the master to write data to the coil register with the address 10, enter 10.

  • To notify the master to write data to a group of coil registers, specify the address of the first coil register in the group. For example, for the master 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 master to write the data. For example, for the master 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 master to write data to a specific holding register, specify the holding register address in this parameter. For example, for the master to write data to the holding register with the address 37, enter 37.

  • To notify the master to write data to a group of holding registers, specify the address of the first holding register in the group. For example, for the master 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 master to write the data. For example, for the master 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.

Introduced in R2021a