Generating a 64-bit compatible .c and .h file using newer MATLAB version

126 次查看(过去 30 天)
Hi all,
I hope you are doing good.
I need help in one of the issue that I am stuck to. I am working with OPAL-RT Hypersim a real-time simulator software that allows to import simulink models. Back in 2017 my teachers at university developmed some Generator Excitor, Governor and Phasor Measurement circuit and then imported them back to Hypersim as at that time Hypersim did not had those blocks in its library. These .c and .h files were generated in MATLAB/SIMULINK 2015 version which was 32-bit. However, we recently had an upgrade of simulator and our new realtime simulator is 64 bit.
So now, as I am trying to run the model in Hypersim it gives me error of comapitibility. I am looking for a way to convert those .c and .h file using a 64-bit MATLAB (more recent version 2022/2023) version however, I am unaware how to do so.
Any help or assistance in this regard will be highly helpful to me.
Kind Regards,
Hamza
  7 个评论
Hamza Ahmed Ansari
Hamza Ahmed Ansari 2024-9-6,10:53
Thanks for the response. I already have a 64-bit MATLAB Installed (MATLBA 2023b and MATLAB 2022a).
I am using OPAL-RT Hypersim software that runs model in real-time on a 64-bit simultor. In my Hypersim model there are some blocks of (Phasor Measurement Unit, Governor, Excitor) that were created on a 32-bit MATLAB/Simulink 2014b as can be seen in screenshot 1 below:
There are some libraries such as "rtwtype.h" which are not compatible with the new 64 bit simulator that we have. So as I load the model, the lbraries are referenced to c-code which is no more compatible with 64 bit simulator.
I am looking a way, to convert these 32-bit .c (source code) and .h (header files) into 64-bit compaitable files, that I can load into my model in Hypersim software.
I found the following link https://de.mathworks.com/help/simulink/ug/incorporate-c-code-using-a-matlab-function-block.html, but I think this is more suitable when I already have a simulink model and then try to integrate the source and header files. However, in my case I only have the source and eader files but no simulink model.
Kind Regards,
Hamza
Oliver Jaehrig
Oliver Jaehrig 2024-9-9,11:15
The best would be to get the m-files and Simulink models which were used to generate the code from.
If this is not possible, I believe you manually need to review the code and rewrite it.

请先登录,再进行评论。

回答(1 个)

Kautuk Raj
Kautuk Raj 2024-9-11,3:54
编辑:Kautuk Raj 2024-9-11,6:39
To resolve the compatibility issue between 32-bit and 64-bit generated code, you can follow the steps below to recompile your existing 32-bit .c and .h files using a 64-bit version of MATLAB. By carrying out this recompilation, the conversion between 32-bit code and 64-bit code can be carried out.
1. Set Up Your Environment:
- You already have a 64-bit version of MATLAB installed.
- Install a compatible C/C++ compiler that works with your MATLAB version. Follow this documentation page for guidance: https://www.mathworks.com/help/releases/R2022a/matlab/matlab_external/choose-c-or-c-compilers.html
2. Prepare Your Files:
- Locate the original.c and.h files generated from the 32-bit MATLAB environment.
- Ensure that any dependencies or additional files needed by these.c and .h files are available.
3. Compile the Files:
- Use the mex command (https://www.mathworks.com/help/releases/R2022a/matlab/ref/mex.html) to compile the.c files. For example: mex your_file.c
4. Check for Compatibility Issues:
- If there are any errors during compilation, they might be due to deprecated functions or compatibility issues between 32-bit and 64-bit environments. Review the error messages carefully and make necessary code adjustments.
- You may need to update certain parts of the code to comply with the 64-bit architecture, such as pointer arithmetic or data type sizes.
After successful compilation and testing, import the newly compiled files into Hypersim (the real-time simulator software being used) and verify that the model runs without compatibility errors.
By following these steps, you should be able to compile and convert your existing code to work with a 64-bit environment.

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by