Using calllib inside MATLAB Function

Hello together,
previously, I included an external C libary via callib. As a result, I can call the external commands from there in usual MATLAB scripts.
Now, I want to call the external commands from the C libaray periodically with every time step of my Simulink model. So I have tried to call these commands within a MATLAB function. Unfortunately, I get the following error message:
Function 'calllib' not supported for code generation. Function 'write2ByteTxRx.m' (#70.1182.1264), line 35, column 1: "calllib(lib_name, 'write2ByteTxRx', port_num, protocol_version, id, address, dat" Launch diagnostic report.
From my perspective, the problem is the usage of calllib inside the external function I want to call from the C library:
function [] = write2ByteTxRx( port_num, protocol_version, id, address, data )
lib_name = '';
if strcmp(computer, 'PCWIN')
lib_name = 'dxl_x86_c';
elseif strcmp(computer, 'PCWIN64')
lib_name = 'dxl_x64_c';
elseif strcmp(computer, 'GLNX86')
lib_name = 'libdxl_x86_c';
elseif strcmp(computer, 'GLNXA64')
lib_name = 'libdxl_x64_c';
elseif strcmp(computer, 'MACI64')
lib_name = 'libdxl_mac_c';
end
calllib(lib_name, 'write2ByteTxRx', port_num, protocol_version, id, address, data);
end
Does anyone know how I could avoid this problem? Actually, I don't want to create code. Basically, I would like to use external C functions periodically inside a Simulink model. That's why I have tried to use a MATLAB Function. I already thougth about MATLAB Systems - but they also use functions inside which may cause the same problem I have right now.
Thank you very much in advance!

3 comentarios

Walter Roberson
Walter Roberson el 23 de En. de 2020
coder.ceval
https://www.mathworks.com/help/simulink/slref/coder.ceval.html
Jonas Walter
Jonas Walter el 23 de En. de 2020
Thank you for your answer, Walter!
Ryan Livingston
Ryan Livingston el 23 de En. de 2020

Iniciar sesión para comentar.

 Respuesta aceptada

Jonas Walter
Jonas Walter el 23 de En. de 2020
I solved the problem by using coder.entrinsic. According to my example above, I set:
coder.extrinsic('write2ByteTxRx');
Now, the Simulink model is compling.

Más respuestas (0)

Categorías

Más información sobre C Shared Library Integration en Centro de ayuda y File Exchange.

Productos

Preguntada:

el 23 de En. de 2020

Comentada:

el 23 de En. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by