Info
此问题已关闭。 请重新打开它进行编辑或回答。
matlab::engine::connectMATLAB with current session stalling in Matlab
1 次查看(过去 30 天)
显示 更早的评论
Problem:
Matlab stalled in a "Busy" state when calling a C dll.
Background:
I want to create a dll and call it from matlab to interact with my current workspace. The matlab::engine tool has the necessary features to enable what is desired, so I compiled a c dll function with the following:
__declspec(dllexport) void
C_VLInit() {
using namespace matlab::engine;
std::unique_ptr<MATLABEngine> matlabPtr = connectMATLAB(u"currentSession");
matlab::data::Array aRes = matlabPtr->getVariable(u"a");
double a = aRes[0];
matlabPtr->eval(u"y = 1");
matlab::data::Array yRes = matlabPtr->getVariable(u"y");
double y = yRes[0];
std::cout << "current val of a : " << a << "\n" << std::endl; /* not supported in matlab; used for python */
std::cout << "current val of y : " << y << "\n" << std::endl; /* not supported in matlab; used for python */
return;
}
In Matlab, I ran the following to create a shared session and called the dll above:
>> matlab.engine.shareEngine('currentSession');
>> a = 93423;
>> toHeader = 'path\to\vLink.h';
>> toDll = 'path\to\vLink.dll';
>> loadlibrary(toDll, toHeader)
>> calllib('vLink', 'C_VLInit');
The issue is my matlab stays in a "busy" state inside the calllib function.
Minimal example showing the DLL works outside of Matlab
I was curious if there was an issue with the dll, so I created this python workflow to test if the dll can latch onto my matlab "currentSession". I ran python from the windows command line. It seems to work with my currect dll, with this as the output:
>>> from ctypes import *
>>> _lib = cdll.LoadLibrary(r'path\to\vLink.dll')
>>> _lib.C_VLInit()
y =
1
current val of a : 93423
current val of y : 1
Question:
- Any ideas why matlab could stall and stagnate in a "busy" state after/in the calllib function?
- Am I applying any incorrect steps above in how to connect to the matlab "currentSession" in the dll?
- Will matlab::engine work within a dll called from matlab itself?
- Are there any obvious signs of errors?
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!