Create JSON object as C-API

4 vues (au cours des 30 derniers jours)
Benedikt Ingold
Benedikt Ingold le 20 Juil 2022
Hi all,
I'm programming a dSpace vehicle computer (MABX III) with a Simulink Model based on Matlab functions.
I need to pack some data into a JSON file to send it out over a Ethernet port. Matlab is giving for this the jdataencode() function that looks like following:
s.inverter.m_temp.Date = SystemDate;
s.inverter.m_temp.Value = m_temp;
s.inverter.inv_tmp.Date = SystemDate;
s.inverter.inv_tmp.Value = inv_tmp;
json = jdataencode(s);
Sadly, the jdataencode function is not supported for embedded C conversion which makes it unusable for my usecase. Does anyone know some kind of C-API to create a JSON object which is build able on embedded C computing? Thanks in advance!

Réponses (1)

Githin George
Githin George le 9 Nov 2023
Hello,
My understanding is that you are trying to use the jdataencoder” function from JSONLab and you are not able to generate code for this function. In fact, code generation functionality is not provided for the inbuilt MATLAB function “jsonencode as well.
A possible workaround for the issue would be to use a C Function block in Simulink to convert your structure into a JSON string with the help of any custom code or C libraries. Please refer to the following MathWorks video link to learn more about using C Function block.
I hope this helps.

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by