Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Troubleshooting 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 (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

Supported Platforms

Instrument Control Toolbox supports the MODBUS interface over TCP/IP or Serial RTU. It is supported on the following platforms.

  • Linux® 64-bit

  • macOS 64-bit

  • Microsoft® Windows® 64-bit

Note

The Instrument Control Toolbox MODBUS support works on the MATLAB® command line only. It is not available in the Test & Measurement Tool.

Configuration and Connection

  1. Make sure your device is supported in Instrument Control Toolbox. See Is My Hardware Supported?.

  2. If you are connecting to a local or remote device over MODBUS, make sure that the device is powered on and available.

  3. 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.

  4. You can use the instrhwinfo function with 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, COM1 and COM3 are available.

  5. Make sure you can create the modbus object. You must provide arguments to create the object, whether you use serialrtu or tcpip. 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 required.

  6. 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.

Other Troubleshooting Tips for MODBUS

These tips may be relevant to your use of the MODBUS interface.

Address Range

When specifying read and write addresses, the addresses must be in the following range: 0–65535.

Underlying Interface

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.

MODBUS Addresses

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.

Was this topic helpful?