Eric Wetjen, MathWorks
The Modbus Explorer App lets you read and write data to any Modbus® device without writing MATLAB® code. With this
We'll demonstrate how to use the app to set up Modbus communication with a Click Koyo Programmable Logic Controller (PLC). The controller is programmed with two holding registers and 3 coils/switches. The holding registers are set up as counters. We'll show how to use the app to change the switch values, which will turn the counters on and off. The effect of our changes can be easily viewed in the live plots, which display the values stored in the counter registers.
At the end of the demonstration, we'll show how to automatically generate a MATLAB live script, which can be used as
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:
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .Select web site
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.