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 (Programmable Logic Controller), 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 humidly on a MODBUS probe.
Using the MODBUS interface, you can do the following tasks:
Read coils, inputs, input registers, and holding registers
Write to coils and 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 operation
Instrument Control Toolbox supports the MODBUS interface over TCP/IP or Serial RTU. It is supported on the following platforms.
Microsoft® Windows® 64-bit
The Instrument Control Toolbox MODBUS support works on the MATLAB® command line only. It is not available in the Test & Measurement Tool.
Make sure your device is supported in Instrument Control Toolbox. See Is My Hardware Supported?.
If you are connecting to a local or remote device over MODBUS, make sure that the device is powered on and available.
Instrument Control Toolbox can communicate over MODBUS using TCP/IP or Serial RTU. If you are connecting via TCP/IP, you need to know the IP address or host name of the MODBUS server. If you are connecting via Serial RTU, you need to specify the Serial port the MODBUS server is connected to.
You can use the
modbus interface name to see what Serial
ports are available to use.
instrhwinfo('modbus') ans = HardwareInfo with properties: SupportedProtocols: ["serialrtu" "tcpip"] LocalHost: [1×6 string] AvailableSerialPorts: ["COM1" "COM3"]
In this case,
Make sure you can create the
You must provide arguments to create the object, whether you use
For examples of creating the object and information about the required
arguments, see Create a MODBUS Connection.
When you create the
modbus object, it connects
you to the server or device. There is no separate connection function
When you have connected, you can communicate with your device. See Read Temperature from a Remote Temperature Sensor for an example of communicating with a device. See Other Troubleshooting Tips for MODBUS for tips about communication issues after initial connection.
These tips may be relevant to your use of the MODBUS interface.
When specifying read and write addresses, the addresses must be in the following range: 0–65535.
You may encounter connection problems that are due to the underlying TCP/IP or Serial Port connections, rather than being specific to the MODBUS interface. The troubleshooting sections on Troubleshooting TCP/IP Interface and Troubleshooting Serial Port Interface might provide tips that will help.
If you have trouble figuring out a MODBUS address, see the vendor documentation of the device. For example, you may need to map a PLC register to the MODBUS address for the register. The vendor documentation may help.
Some vendors include an extra digit in addresses that gets dropped. For example 43233 is really address 3233. Devices are usually represented by a four-digit address, and some vendors use a 5th digit to represent the type of target, for example, coils. So you may need to adjust an address to account for this if your device vendor does that.
The Instrument Control Toolbox MODBUS functions use 1-based addressing, like the PLC shows addresses, not 0-based addressing, like MODBUS uses. The toolbox subtracts 1 from any addresses that are passed in via the address parameters in the read and write functions.