This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Generate a Script from Your Modbus Explorer Session

You can generate a MATLAB script from your Modbus Explorer session, and then run it at the command line using the Instrument Control Toolbox™ Modbus functionality. The generated script contains your device configuration, all the read operations that you perform, the last write operation that you perform for each register type, and cleanup tasks.

Note that generating a script is not the same as saving the contents of the Read Register table. To do that, use Export as described in Read Coils, Inputs, and Registers in the Modbus Explorer.

To generate a script from your Modbus Explorer session, click Generate Script in the toolstrip. The script appears in the MATLAB Editor as a live script. To keep the generated script, save it in the editor. An example of a script is shown here.

Create Modbus Connection - This section of the generated script creates the modbus object using the configuration properties specified.

Perform Modbus Reads - This section of the script performs all the Modbus reads that were done in your session. In this example, five reads were performed.

Perform Modbus Writes - This section of the script shows the last Modbus write operation that was done in the session for each register type. It is presented as a comment so that you must intentionally uncomment it to do the write, to prevent unexpected actions on your device.

Clean Up - This section of the script clears the modbus object and releases the Server ID.

Related Topics