Main Content

Configure Modbus Client in Simulink

Configure a Modbus® client to read or write data from a Modbus Server using the Modbus Client Read or Modbus Client Write blocks in Simulink®.

In the Simulink toolstrip, click Model Settings in the Modeling tab to open the Configuration Parameters dialog box. In the dialog box, click the Modbus pane to configure the Modbus clients.

Simulink toolstrip

Alternately, click Configure clients in the Modbus Client Read or Modbus Client Write blocks to open the Modbus configuration pane.

Block mask - Configure clients

The Modbus pane lists all the Modbus clients that you configure in the current model. You can use the buttons in this window to add, delete, and configure the clients.

  • Add: Create a new Modbus client.

  • Delete: Delete the selected client.

  • Configure: Edit the selected client properties.

Modbus Configuration pane

Modbus Client Configuration

Complete these steps to configure a Modbus client for a Simulink model.

Note

The Modbus pane is enabled in the Configuration Parameters dialog box of the model only when you include a Modbus Client Read or Modbus Client Write block in the model.

Step 1: Create Modbus Client

  1. To create a new Modbus client, click Add. The Add Modbus Client dialog box lists the default Client Name, Transport Protocol, Device Address, and Port values as ModbusClient, TCP/IP, localhost, and 502, respectively. You can add any valid TCP/IP or serial server information in this window. When you select the Transport Protocol as Serial, the Serial Port parameter automatically selects the first available serial port. Click the drop-down list to view all the available serial ports.

    Add Modbus Client

  2. To edit or view the default transport settings for the client, expand the Transport Settings panel. Modify the required settings and click OK.

    Add Modbus Serial Server

  3. Simulink creates a new Modbus client for the selected Modbus server and adds the client to the Modbus clients table.

    Modbus Client table

Step 2 (Optional): Configure Transport Settings of Modbus Client

  1. Simulink configures every client with the default transport settings. To edit the transport settings, select the client, click Configure, and expand the Transport Settings panel. You can also edit the connection endpoint parameters such as Device Address, Port, and Serial Port using the Configure Modbus Client window. For more information, see Configure Properties for Modbus Communication.

    Configure Modbus TCP/IP Client

  2. In the Configure Modbus Client window, edit the transport settings and the connection endpoint, then click OK. The connection endpoint is updated in the Modbus clients table. You can restore the default transport settings for a client when you click Reset to Default in the window.

    Updated Modbus pane

Step 3: Update Client Information in Model

Click OK in the Configuration Parameters window to update the model with information about the new Modbus client.

Step 4: Select Client Connection for Modbus Block

  1. The Client parameter of the Modbus blocks lists all the client connections that you have added in the Modbus clients table. You must click Refresh to update the block with the latest client information.

    Modbus Block Masks

  2. Select the Client to associate the block to the corresponding Modbus server.

See Also

Blocks

Related Topics