Modbus Communication
Industrial Communication 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 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.
You can read or write data to a Modbus TCP/IP or Serial server using the Modbus client blocks in Simulink®. For an example, see Control Water pH Remotely Using Modbus Client Blocks in Simulink.
Blocks
Modbus Client Read | Read data from Modbus server (Since R2024b) |
Modbus Client Write | Write data to Modbus server (Since R2024b) |
Functions
Apps
Modbus Explorer | Read and write to Modbus coils and registers |
Topics
Modbus Communication Using Programmatic Workflow
- Modbus Interface Supported Features
Use Industrial Communication Toolbox Modbus support to communicate with Modbus servers and applications over TCP/IP or Serial RTU. - Create a Modbus Connection
Create a Modbus object with themodbus
function, to connect to a Modbus interface. - Configure Properties for Modbus Communication
Use properties to set up Modbus communication during or after object creation. - Read Data from a Modbus Server
Use themodbus
object to read coil, input, and register data from the Modbus server. - Read Temperature from a Remote Temperature Sensor
Read temperature and humidity measurements from a remote sensor on a PLC connected via TCP/IP. - Write Data to a Modbus Server
Use themodbus
object to write coil and holding register data to the Modbus server. - Write and Read Multiple Holding Registers
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
Apply AND and OR masks to the current contents of a holding register.
Modbus Communication Using Simulink
- Configure Modbus Client in Simulink
Configure Modbus clients for model.
Modbus Communication Using the Modbus Explorer
- Use the Modbus Explorer App
You can read and write to coils and registers using the Modbus Explorer app. - Configure a Connection in the Modbus Explorer
Configure communication with the device, either over TCP/IP or Serial RTU. - Read Coils, Inputs, and Registers in Modbus Explorer
Read coils, inputs, input registers, and holding registers, similar to the functionality of the Modbusread
function. - Write to Coils and Holding Registers in Modbus Explorer
Write to coils and holding registers, similar to the functionality of the Modbuswrite
function. - Control a PLC Using the Modbus Explorer
Perform reads and writes to a PLC using the Modbus Explorer. - Generate a Script from Your Modbus Explorer Session
Generate a MATLAB® script from your session to run at the command line.
Troubleshooting
Troubleshooting the Modbus Interface
Try these tips if you have problems using the toolbox Modbus interface. See information about Modbus supported platforms, configuration and connection, and other interface-specific tips.