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

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

Sandeep Mishra
Sandeep Mishra 2024 年 9 月 4 日
I was going through your problem and I think there might be some changes required to your .c and .h file, Can you please share your .c or .h file for better analysis?
Oliver Jaehrig
Oliver Jaehrig 2024 年 9 月 4 日
It sounds like MATLAB Coder or Simulink Coder was used to generate code. The easiest would be to use a 64 Bit release of MATLAB to regenerate the code.
Hamza Ahmed
Hamza Ahmed 2024 年 9 月 5 日
That is what I am thinking and trying to do, however, I am not sure how to do this. May be it is a simple task but since I am new to this I do not know the steps in doing so.
It will be very hepful if you can share any link or some information that can be of help.
Kind Regards,
Hamza
Hamza Ahmed
Hamza Ahmed 2024 年 9 月 5 日
Thank you for the response. As I mentioned before, the code works fine and it was used to generate the blocks that were later imported in Hypersim software. The issue is mainl of comapitibility. I am trying to find way to convert the 32-bit code to 64-bit code.
One way of doing this will be to load the code in a 64-bit MATLAB and then trying to compile it. However, I am not sure how to do so. Let me know if there are any ways in which this can be done.
Kind Regards,
Hamza
Andreas Goser
Andreas Goser 2024 年 9 月 6 日
Please share where exactly you are stuck. Do you have a recent (64 bit) release installed or do you need installation help?
Hamza Ahmed
Hamza Ahmed 2024 年 9 月 6 日
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 日
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 日
編集済み: Kautuk Raj 2024 年 9 月 11 日

0 投票

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.

カテゴリ

ヘルプ センター および File ExchangeSimulink Compiler についてさらに検索

製品

リリース

R2022a

質問済み:

2024 年 9 月 3 日

編集済み:

2024 年 9 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by