This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

MODBUS Communication

Communication using the MODBUS interface

Instrument Control Toolbox™ supports the MODBUS interface over TCP/IP or Serial RTU. You can use it to communicate with MODBUS servers, such as controlling a PLC, communicating with a temperature controller, controlling a stepper motor, sending data to a DSP, reading bulk memory from a PAC controller, or monitoring temperature and humidity on a MODBUS probe.

Create the interface object using the modbus function, and use the read, write, writeRead, and maskWrite functions for communication.

For an example that shows the entire workflow of reading a register from a PLC, see Read Temperature from a Remote Temperature Sensor.

You can also read and write to coils and registers using the Modbus Explorer, which offers a graphical user interface to easily set up reads and writes, and a live plot to see the values. For information, see Use the Modbus Explorer App. For an example that shows the entire workflow of reading and writing to a PLC using the app, see Control a PLC Using the Modbus Explorer.

Functions

modbusCreate MODBUS object
readRead data from a MODBUS server
writePerform a write operation to the connected MODBUS server
writeReadPerform a write then read operation on groups of holding registers in a single MODBUS transaction
maskWritePerform mask write operation on a holding register
instrhwinfoInformation about available hardware
clearRemove instrument objects from MATLAB workspace

Apps

Modbus ExplorerRead and write to Modbus coils and registers

Topics

Modbus Communication Using Programmatic Workflow

MODBUS Interface Supported Features

Instrument Control Toolbox MODBUS support lets you communicate with MODBUS servers and applications over TCP/IP or Serial RTU.

Create a MODBUS Connection

To communicate over the MODBUS interface, you first create a MODBUS object using the modbus function. Creating the object also makes the connection.

Configure Properties for MODBUS Communication

You can use properties to set up the MODBUS communication during object creation or any time.

Read Data from a MODBUS Server

You can read data from the MODBUS server connected to the modbus object. You can read coils, inputs, input registers, and holding registers.

Read Temperature from a Remote Temperature Sensor

This example shows how to read temperature and humidity measurements from a remote sensor on a PLC connected via TCP/IP.

Write Data to a MODBUS Server

You can write data to the MODBUS server connected to the modbus object. You can write to coils and holding registers.

Write and Read Multiple Holding Registers

You can perform a combination of one write operation and one read operation on groups of holding registers in a single MODBUS transaction.

Modify the Contents of a Holding Register Using a Mask Write

You can modify the contents of a holding register using a combination of an AND mask, an OR mask, and the register's current contents.

Modbus Communication Using the Modbus Explorer

Use the Modbus Explorer App

You can read and write to coils and registers in the Modbus Explorer app.

Configure a Connection in the Modbus Explorer

The first step in using the Modbus Explorer to communicate with a PLC or other Modbus device is to configure the communication with the device, either over TCP/IP or Serial RTU.

Read Coils, Inputs, and Registers in the Modbus Explorer

You can read coils, inputs, input registers, and holding registers in the Modbus Explorer. This is the functionality of the Modbus read function.

Write to Coils and Holding Registers in the Modbus Explorer

You can write to coils and holding registers in the Modbus Explorer. This is the functionality of the Modbus write function.

Control a PLC Using the Modbus Explorer

This example shows how to perform reads and writes to a PLC using the Modbus Explorer.

Generate a Script from Your Modbus Explorer Session

You can generate a MATLAB script from your Modbus Explorer session, and then run it at the command line using the Instrument Control Toolbox Modbus functionality.

Troubleshooting

Troubleshooting MODBUS Interface

Try these tips if you have problems using the toolbox with the MODBUS interface. Includes information about MODBUS supported platforms, configuration and connection, and other interface-specific tips.