MEX functions work fine on R2017a but not on R2021b even after successful recompilation on R2021b

3 views (last 30 days)
Hello, here is my problem: I upgraded from Matlab R2017a to 2021b based on the recommendation for compatibility with Windows 11 (I moved to a new PC). However, I am experiencing problems with the MEX functions I use to connect to hardware (open connexion, close connexion, update status, basic functions). I recompiled the MEX functions (for which I have all the source files) under MATLAB 2021b, using both the -R2017b and -R2018a options, and they recompiled successfully. Despite this, I cannot connect to the hardware. If I use the same MEX functions on the same computer (Windows 11) with MATLAB R2017a, it works fine (not if I compiled the MEX with -R2018a option which makes sense I believe). Additionally, I am using external software from the manufacturer to control the hardware, and it works fine too (driver correctly installed). The issue only occurs with MATLAB 2021b. I compared the verbose outputs of the MEX function compilations with the -R2017b and -R2018a options and found no significant differences. I am confused as to why the MEX functions work with MATLAB R2017a but not with R2021b on the same computer, especially since the functions recompiled with R2021b show no warnings or errors. Do you have any tips or ideas to solve this issue?
Additionnaly, the MEX functions works fine with R2017a, hardware controlled correctly, while with R2021b error code from MEX functions states "device not found". Matlab configuration between installation R2017a and R2021b is the same (paths, compiler, etc.). Thanks !

Answers (1)

Siraj
Siraj on 31 Jul 2024
Edited: Siraj on 31 Jul 2024
Hi!
I understand that you upgraded from MATLAB R2017a to R2021b for Windows 11 compatibility but are experiencing issues with MEX functions used to connect to hardware. The MEX functions compile successfully in R2021b but fail to connect to the hardware, returning a "device not found" error. The same MEX functions work fine in R2017a on the same computer, and you are also able to correctly control the hardware using external software from the manufacturer.
In order to resolve the issue please try the following steps:
1) Type the following commands in the MATLAB command window:
>> restoredefaultpath;
>> rehash toolboxcache;
2) Check if there are any environment variables that need to be set for the hardware or the MEX functions to work correctly. These might be different between MATLAB versions.
3) Ensure that all drivers and libraries used by the MEX functions are up-to-date and compatible with Windows 11 and MATLAB R2021b.
4) Type the following command before compiling the MEX function in order to lockdown the specific line of code causing the error:
>> dbstop if error
You can also try calling the MEX function that is built in an older MATLAB version. MEX functions are backward compatible. Even though it is recommended to re-build the MEX functions with every new MATLAB release, you can try calling the MEX function built in an older version and see if it works in the newer MATLAB version.
Additionally, if MATLAB is able to call the MEX function, then the issue might be with any third-party library you are using to connect to the hardware. Please check with the vendor to ensure that the library supports the new compiler used to compile the MEX function.
Hope this helps.

Categories

Find more on Troubleshooting in MATLAB Compiler SDK in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!