How can I use Python in Matlab for dll usage?
I am using Python inside of MATLAB to load a DLL so I can use its functionality. I have tried almost every combination of inputs to try and make this MATLAB-Python combo work, but I have been unsuccessful. I know my DLL is good because I have used it using solely python and I have also gotten it working in MATLAB using a different set of commands, but I really want to use the MATLAB/Python combo.
Below is what I am trying to do
%% Using Python
ctypes = py.importlib.import_module(‘ctypes’);
vnx = ctypes.cdll.LoadLibrary(‘file path where dll and header files are stored vnx_fmsynth.dll’);
%% Calling these fx’s don’t work!
vnx.fnLMS_SetTestMode(0)
vnx.fnLMS_GetNumDevices()
I can assure fnLMS_SetTestMode and fnLMS_GetNumDevices, are methods within the DLL but python-matlab does not want to recognize them. I have tried over 100 combinations of trying to get the DLL to function, but I simply cannot figure out the correct syntax. When I run essentially the same lines in python however, it does work, so I am obviously doing something wrong inside of matlab.
Let me show you what does work in MATLAB with out using python.. (this does require you have a C-code compiler installed on your PC).
%% Load Libraries
cd(‘file path where dll and header files are stored’)
libName=’vnx_fmsynth’;
loadlibrary([libName,’.dll’],’vnx_LMS_api.h’)
libfunc= libfunctions(‘vnx_fmsynth’)
%% tab complete for the lazy
for i=1:length(libfunc)
libF.(libfunc{i})=libfunc{i}; % this way the auto complete from the structure’s field is the same as the library name
end
%% Calling these fx’s work!
calllib(libName, ‘fnLMS_SetTestMode’,0)
devNum=calllib(libName,libF.fnLMS_GetNumDevices)
I have included the files in .zip for you to try yourself.
the fnLMS_GetNumDevices function should response with ‘0’. the TestMode function doesn’t respond with anything, but it does functionally work. I have been told and have watched videos that running python inside of MATLAB works the same, but I am starting to question my presumptions. 🙁 Any and all help would be very much appreciated!!
I am using MATLAB 2022AI am using Python inside of MATLAB to load a DLL so I can use its functionality. I have tried almost every combination of inputs to try and make this MATLAB-Python combo work, but I have been unsuccessful. I know my DLL is good because I have used it using solely python and I have also gotten it working in MATLAB using a different set of commands, but I really want to use the MATLAB/Python combo.
Below is what I am trying to do
%% Using Python
ctypes = py.importlib.import_module(‘ctypes’);
vnx = ctypes.cdll.LoadLibrary(‘file path where dll and header files are stored vnx_fmsynth.dll’);
%% Calling these fx’s don’t work!
vnx.fnLMS_SetTestMode(0)
vnx.fnLMS_GetNumDevices()
I can assure fnLMS_SetTestMode and fnLMS_GetNumDevices, are methods within the DLL but python-matlab does not want to recognize them. I have tried over 100 combinations of trying to get the DLL to function, but I simply cannot figure out the correct syntax. When I run essentially the same lines in python however, it does work, so I am obviously doing something wrong inside of matlab.
Let me show you what does work in MATLAB with out using python.. (this does require you have a C-code compiler installed on your PC).
%% Load Libraries
cd(‘file path where dll and header files are stored’)
libName=’vnx_fmsynth’;
loadlibrary([libName,’.dll’],’vnx_LMS_api.h’)
libfunc= libfunctions(‘vnx_fmsynth’)
%% tab complete for the lazy
for i=1:length(libfunc)
libF.(libfunc{i})=libfunc{i}; % this way the auto complete from the structure’s field is the same as the library name
end
%% Calling these fx’s work!
calllib(libName, ‘fnLMS_SetTestMode’,0)
devNum=calllib(libName,libF.fnLMS_GetNumDevices)
I have included the files in .zip for you to try yourself.
the fnLMS_GetNumDevices function should response with ‘0’. the TestMode function doesn’t respond with anything, but it does functionally work. I have been told and have watched videos that running python inside of MATLAB works the same, but I am starting to question my presumptions. 🙁 Any and all help would be very much appreciated!!
I am using MATLAB 2022A I am using Python inside of MATLAB to load a DLL so I can use its functionality. I have tried almost every combination of inputs to try and make this MATLAB-Python combo work, but I have been unsuccessful. I know my DLL is good because I have used it using solely python and I have also gotten it working in MATLAB using a different set of commands, but I really want to use the MATLAB/Python combo.
Below is what I am trying to do
%% Using Python
ctypes = py.importlib.import_module(‘ctypes’);
vnx = ctypes.cdll.LoadLibrary(‘file path where dll and header files are stored vnx_fmsynth.dll’);
%% Calling these fx’s don’t work!
vnx.fnLMS_SetTestMode(0)
vnx.fnLMS_GetNumDevices()
I can assure fnLMS_SetTestMode and fnLMS_GetNumDevices, are methods within the DLL but python-matlab does not want to recognize them. I have tried over 100 combinations of trying to get the DLL to function, but I simply cannot figure out the correct syntax. When I run essentially the same lines in python however, it does work, so I am obviously doing something wrong inside of matlab.
Let me show you what does work in MATLAB with out using python.. (this does require you have a C-code compiler installed on your PC).
%% Load Libraries
cd(‘file path where dll and header files are stored’)
libName=’vnx_fmsynth’;
loadlibrary([libName,’.dll’],’vnx_LMS_api.h’)
libfunc= libfunctions(‘vnx_fmsynth’)
%% tab complete for the lazy
for i=1:length(libfunc)
libF.(libfunc{i})=libfunc{i}; % this way the auto complete from the structure’s field is the same as the library name
end
%% Calling these fx’s work!
calllib(libName, ‘fnLMS_SetTestMode’,0)
devNum=calllib(libName,libF.fnLMS_GetNumDevices)
I have included the files in .zip for you to try yourself.
the fnLMS_GetNumDevices function should response with ‘0’. the TestMode function doesn’t respond with anything, but it does functionally work. I have been told and have watched videos that running python inside of MATLAB works the same, but I am starting to question my presumptions. 🙁 Any and all help would be very much appreciated!!
I am using MATLAB 2022A ctype, dll, python, calllib, loadlibrary MATLAB Answers — New Questions