How can I communicate through Modbus protocol in Simulink?

How can I communicate through Modbus protocol in Simulink?

 Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 14 de Feb. de 2025
Editada: MathWorks Support Team el 17 de Feb. de 2025
As of R2024b, you can use the built-in blocks: 
For releases prior to R2024b, please consider the following:
Modbus communication over TCP/IP or Serial RTU is available in MATLAB as part of Industrial Communication Toolbox (in R2017a through R2021b, as part of Instrument Control Toolbox).
There are two workarounds for supporting Modbus communication in Simulink:
1) Write your own custom block to implement the Modbus functionality. This approach is the most flexible, and can support code generation. It is often done using S-functions. More information on S-functions can be found here: https://www.mathworks.com/help/simulink/blockset-authoring.html
The following guide on writing device drivers for Simulink may be a useful reference as well:https://www.mathworks.com/matlabcentral/fileexchange/39354-device-drivers
2) Use the Industrial Communication Toolbox 'modbus' object in Simulink using a MATLAB Function block. Note that this approach is limited in some ways, and does not support code generation.
There is an attached example model which shows how this approach might be implemented. Since MATLAB function blocks generate code, it is necessary to use "coder.extrinsic" on the MODBUS functions to instruct the code generator to skip these functions. More information on "coder.extrinsic" can be found here: https://www.mathworks.com/help/simulink/slref/coder.extrinsic.html
Also, note that we only create the Modbus object once by declaring it as a persistent variable. Because of this, you cannot use multiple of the Modbus read blocks within your model. It would be necessary to add extra logic to use multiple read blocks, so only one Modbus object is created for use by all blocks.

Más respuestas (0)

Categorías

Productos

Versión

R2017a

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by