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 件のコメント

Walter Roberson
Walter Roberson 2020 年 1 月 23 日
coder.ceval
https://www.mathworks.com/help/simulink/slref/coder.ceval.html
Jonas Walter
Jonas Walter 2020 年 1 月 23 日
Thank you for your answer, Walter!
Ryan Livingston
Ryan Livingston 2020 年 1 月 23 日

サインインしてコメントする。

 採用された回答

Jonas Walter
Jonas Walter 2020 年 1 月 23 日

0 投票

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeC Shared Library Integration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by