Modbus Explorer App Overview

In this video, we will demonstrate how to use the Modbus Explorer App. The Modbus Explorer App, included with Instrument Control Toolbox, lets you read and write data to any Modbus device without writing MATLAB code. With this app, you can configure Modbus communication, read and write to Modbus registers, view live plots of register data, and automatically generate a MATLAB live script.

To get started, we go to the Apps tab on the MATLAB toolstrip and we click on the Modbus Explorer icon.

The next step is to configure the app. Before we do that, we need to decide what we are going to connect to. 

On my desk, I have Click Koyo programmable Logic Controller (PLC) which I can communicate with using Modbus. This PLC and the Modbus Explorer App support communication over Modbus TCP/IP and Modbus Serial (RTU). For this demo, we are using the serial port, so we will connect using Modbus serial.  

To establish the connection, we need to add a Modbus device and choose Modbus Serial from the Devices tab. My PLC is on COM3, the baud rate is 38400, and the parity is odd. I can change the default settings for baud rate and parity to match my device using this setup window. Before saving the configuration, the app asks you to read data from one of the registers on the device. I know that my PLC device has a coil at address 16385. If I click read, I can see that the value is set to 1. Now, I just click Confirm Parameters to finish the setup of the device.

I can add additional coils and holding registers by clicking insert. My PLC has two additional coils at addresses 16386 and 16387. I also have two holding registers at address 45058 and 45057. Let’s add them all now. Now if we hit resume reads, we can see the dats is read in from those registers. Now we can export this register table so that we don’t have to set up the registers the next time we run MATLAB. If we close MATLAB, all we have to do is import this register table using import and we are ready to go. You can see here that I have also renamed the registers for convenience in this version of the register table

Now, how can we interactively communicate with the device? Clearly, we can read the values at the defined memory locations as can be seen here and in the plot at the bottom.. We can also use the Write registers pane to change the values. Before we change the value of the write register, let me explain a little bit about the program that is running on the PLC. 

The PLC has been previously programmed using the PLC vendor’s software. We have downloaded a simple program that associates three coil switches with two holding registers. The holding registers are configured as counters. Holding Register 1 will start counting when Coil 1 (16385) and Coil 3 (16387) are high. The Holding Register 2 at address 45058 is set to start counting five seconds after holding register 1. Let’s test it out. I will set Coil 3 to high by writing a “1” and we’ll see what happens.  You can see in the graph here that Counter 1 has started (the purple line) and now 5 seconds later, you can see the green line (Counter 2) has started.  You can also see the same information in the table with the read values that are now incrementing with time. 

As a final step, we can generate a MATLAB script that can help get us started if we are building a larger program. If we click Generate Script, a MATLAB live script is automatically generated. Here we can see how to read and write from registers on the PLC using MATLAB code.

So, to summarize, with the Modbus Explorer App, you can:

  • Connect to Modbus devices such as PLCs without writing code,
  • Configure the Modbus communication,
  • Read and write to coils, input registers and holding registers,
  • View live visualizations of register data, and
  • Automatically generate MATLAB code from your interactions in the app.