- Use a Supported Function: For example, you might use lower-level file I/O functions that are supported, although this may not be directly applicable for a TCP client.
- Use Interpreted Execution: If the writeline function is essential and there is no alternative that is compatible with code generation, you can configure the MATLAB Function block to execute as interpreted MATLAB code instead of generating C code. This means the code will run in MATLAB rather than being compiled to C/C++. Refer this: https://www.mathworks.com/help/simulink/ug/simulation-modes.html
- External Mode: If you are using the MATLAB Function block for real-time communication in external mode, you may need to create a custom S-Function or a System object that handles the TCP communication and is designed to support code generation. Refer this: https://www.mathworks.com/help/simulink/sfg/what-is-an-s-function.html
- Generate a MEX Function: If you are not trying to deploy the code but only want to accelerate simulation, you can generate a MEX function instead of standalone C/C++ code. MEX generation may support more functions than standalone code generation. Refer this: https://www.mathworks.com/help/matlab/call-mex-file-functions.html
how to use tcpclient in simulink matlab function block
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Chetan Thakur
el 9 de En. de 2024
Editada: Chetan Thakur
el 16 de En. de 2024
Hi
Trying to use tcpclient in simulink's matlab function block(function is attached). But I get stuck with following error.
I am aware that it is somehow linked to tcpclient function.
I am looking for alternative solution for this. Please suggest ideal solution for this.
The same code work when I use it as matlab script.
========================
Function writeline is not supported for code generation. Function 'CS9 Action Communication' (#24.196.237), line 8, column 1: "writeline(tcpClient,sprintf("%f",action))" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function readline is not supported for code generation. Function 'CS9 Action Communication' (#24.291.310), line 11, column 13: "readline(tcpClient)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Code generation does not support explicit calls to the 'delete' method. Function 'CS9 Action Communication' (#24.343.360), line 13, column 1: "delete(tcpClient)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'dReceived'. The first assignment to a local variable determines its class. Function 'CS9 Action Communication' (#24.387.396), line 15, column 25: "dReceived" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'dataReceived'. The first assignment to a local variable determines its class. Function 'CS9 Action Communication' (#24.556.568), line 21, column 9: "dataReceived" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'dataReceived'. The first assignment to a local variable determines its class. Function 'CS9 Action Communication' (#24.586.598), line 22, column 12: "dataReceived" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'dataReceived'. The first assignment to a local variable determines its class. Function 'CS9 Action Communication' (#24.611.623), line 23, column 7: "dataReceived" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'HIL_rlwork_v3/CS9 Action Communication'
Component:MATLAB Function | Category:Coder error
0 comentarios
Respuesta aceptada
Ayush
el 9 de En. de 2024
I understand that you are getting the error when using tcpclient in simulink matlab function block. Most of your errors are associated with Code generation aspect. MATLAB Function block within Simulink are designed to be compatible with code generation. Simulink uses the MATLAB Coder to automatically generate C/C++ code from the algorithms you write inside MATLAB Function blocks. You may fix these errors by following workarounds:
Thanks,
Ayush
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Modeling en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!