Is possible to access to a MAT-file during the HIL simulation?

Hi, I'm developing a target for a especific hardware. I generate a dll I need to acces to a MAT-file located in the same hardware to change some variables during the simulation. I have seen the files 'matdgns.c' and 'matcreat.c'. But I don't know how can I run this code in my hardware. Thanks in advance

7 comentarios

I try to include 'mat.h' and 'matrix.h' in my generated code to acces to the functions (matOpen, matClose, MATFile, matGetVariable, ...) but I have this error:
...\matrix.h(300) : error C2371: 'mxArray' : redefinition; different basic types
...\simstruc.h(466) : see declaration of 'mxArray'
...\matrix.h(320) : error C2061: syntax error : identifier 'mxChar'
...\matrix.h(320) : error C2059: syntax error : ';'
...\matrix.h(633) : error C2143: syntax error : missing '{' before '*'
How is the MAT-file generated on the target? Also, please see if this previous discussion helps.
I want that the dll generated with the target can read a MAT-file. Because I want that who has generated the dll can send to hardware the separated MAT-file to run differents behaviours without 'external mode'.
I have problems because Simulink Coder includes 'simstruc.h' that defines mxArray. And if I include 'matrix.h' to use the the Matlab API to Read and Write MATLAB MAT-Files in C/C++ and Fortran, I have problems of redefinition for mxArray
Could you explain more about how you are incorporating the MAT-file reading C-code into your model. Is it an S-function? What happens if you exclude matrix.h, but include mat.h?
I can't exclude matrix.h because mat.h includes it (line 33: #include "matrix.h" /* for mxArray */)
My purpose is to generate a dll capable of receiving a MAT-file during execution (via FTP). In order to change their behavior updating its parameters without Matlab . To do that, I thought to make a .c (compiled with the dll) which expect to receive a MAT-file and then it reads and updates the values of the dll.
Perhaps there are another manner to do this, but I dont know how.
Carlos: If you're writing a DLL independent of MATLAB to access the MAT-file, I don't understand why you have included simstruc.h - which is why I was asking if your DLL is an S-function.
My dll is not independent of Matlab. I generate it with Simulink Coder and Embedded Coder, and during the dll compilation the file 'simstruc.h' is included by 'rt_sim.c' in the line 32

Iniciar sesión para comentar.

 Respuesta aceptada

Kaustubha Govind
Kaustubha Govind el 11 de Sept. de 2013
It appears that you are integrating MAT-file reading/creation code into code generated from Simulink Coder. Would it be possible to put the MAT-file related code in a separate C-file, so you don't see clashes between simstruc.h, and mat.h and matrix.h? I think you can "extern" the MAT-file function from the other C-file and call it from the file generated using Simulink Coder.

6 comentarios

I had thought that option. But yesterday I was thinking that I can not do it because the file calls a .lib. And I guess the .lib is compiled for windows and my hardware have another OS (embedded windows CE). I think that the only solution is to read very well the MAT-file format document and to make a C-file to read directly from the MAT-file. You think so?
Is there a reason you can't use something like a text-file instead? I'm not sure how easy/stable it would be to read a MAT-file without using MATLAB libraries.
I have to use the MAT-file because it is a requirement that I have not chosen
I go to try to read MAT-file directly and if it's so complicated I will generate a text file.
Once I have read the values of the variables I don´t know how put the value on the dll. I have put the question there: 'How change variable during HIL simulation ?'
Do you have any advice?
I don't really know much about HIL, but I found this page that you might find helpful: Data Interchange Using the C API.
I have read this document. But when I try to implement it I have this error:
Error: Simulink Coder does not support both External Mode and the C API at the same time.
And I can't clear the external mode due to my requeriments
Carlos: Sorry, this is beyond my expertise. You could try posting a new question or contact MathWorks Tech Support.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink Coder en Centro de ayuda y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by