Main Content

Modbus Client Read

Read data from Modbus server

Since R2024b

  • Modbus Client Read Block

Libraries:
Industrial Communication Toolbox / Modbus

Description

The Modbus Client Read block reads data from one or more registers on a Modbus® TCP/IP or serial server.

Each output port returns data from a corresponding register specified in the Registers parameter of the Modbus Client Read block. The ports have a size of 1xN, where N is the count value mentioned for the corresponding register entry.

Note

You need a license for Industrial Communication Toolbox™ and Simulink® to use this block.

Note

You must connect the Modbus Client Read block to a Modbus TCP/IP or serial server. You can create the client for connection to the Modbus TCP/IP or serial server using the Modbus pane in the Configuration Parameters dialog box of the model. You must add at least one Modbus Client Read or Modbus Client Write block in the model to enable this pane. For more information, see Configure Modbus Client in Simulink.

Other Supported Features

The Modbus Client Read block supports the use of Simulink accelerator and rapid accelerator modes. You can speed up the execution of Simulink models by using these modes. For more information on these simulation modes, see Acceleration (Simulink).

Examples

Ports

Output

expand all

Values read from Modbus TCP/IP or serial server. The number of output ports (x) corresponds to the number of rows you add in the Registers parameter. Each port has a size of 1xN, where N is the count value for the corresponding register entry. When the count is specified as N, the block reads the values from N consecutive registers starting with the register address mentioned in the Registers parameter.

Dependencies

To enable this port, specify one or more registers in the Registers parameter.

Data Types: double

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Select the Modbus client associated with the block. The block updates the Connection endpoint parameter once you select a client.

  • To add the clients using the Modbus pane, click Configure clients. For more information, see Configure Modbus Client in Simulink.

  • To update the client list and to show the latest Modbus clients, click Refresh.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: ClientList
Values: Modbus client name
Data Types: character vector | string

Server address to read from, specified as a nonnegative integer in the range [0, 255]. The default value is 1. The server address refers to the unit identifier for the Modbus TCP/IP server.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: ServerId
Values: 1 (default) | nonnegative integer in the range [0, 255]
Data Types: double

Add registers to read from the specified client.

  • To add a register, click Add. This action adds a row in the Registers table with the default values of Name, Register Type, Precision and Count specified as Reg_1, Holding Register, uint16 and 1, respectively. You must specify an address for the register to read from in the Address column. Each click adds a new row in the Registers table with the name incremented by 1.

    • Sl. no. : This field is non editable and specifies the serial number of the register. The serial number determines the order in which the block outputs the signals at the output ports.

    • Name: This is an editable text field that specifies a name for the register. This field also defines the names for the output ports.

    • Address: This is an editable text field that specifies a starting address for the Modbus read operation.

    • Register Type: This is a drop-down list that specifies the target area to read. You can perform a Modbus read operation on four types of targets: coils, inputs, input registers, and holding registers.

    • Precision: This is a drop-down list that specifies the data format of the read register. Note that the Precision field does not refer to the output port data type. It specifies how to interpret the register data. The output data type is always double.

      • For coils and inputs, set this field to bit.

      • For holding registers and input registers, set this field to int16, uint16, int32, uint32, single, double, int64 or uint64.

    • Count: This is an editable text field that specifies the number of registers to read starting from the address specified in the corresponding Address field.

  • To delete registers, select the registers and click Delete.

  • To import a register table saved as a MAT file, click Import. This action opens the Load register table dialog box for the current workspace. Using this browser, you can select the MAT file with the register information. The MAT file that you select must have a table named ModbusRegisterTable.

    Note

    The Modbus Explorer app exports the contents of the register table as a MAT file. You can import this MAT file into the Modbus Client Simulink blocks to reuse the register table. For more information, see Use the Modbus Explorer App.

  • To save the register table as a MAT file, click Export. This action opens the Save register table dialog box for the current workspace. Using this browser, you can save the register table as a MAT file in the location of your choice. The default filename is ModbusRegisterTable.mat.

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: RegisterTable
Values: register name and information
Data Types: character vector | string

Define the sample time of the block in seconds. The block reads the data from the server synchronously at the specified sample time. For more information, see Specify Sample Time (Simulink).

Programmatic Use

To set the block parameter value programmatically, use the set_param (Simulink) function.

To get the block parameter value programmatically, use the get_param (Simulink) function.

Parameter: SampleTime
Values: -1 (default) | numeric
Data Types: double

Extended Capabilities

Version History

Introduced in R2024b