Hi everybody, I am trying to use functions in a windows DLL for controlling stepper motor hardware. The stepper motor manual says that the DLL should work with Matlab. So, I read carefully the external interfacing section in Matlab help and related articles in several newsgroups. I think I am doing everything right, but Matlab always produces a segmentation fault when I make the calllib statement to the function USMC_Init in the DLL. Before the callib statement, the library seems to be loaded correctly and the correct data structures seem to be generated and initialized (see line 18 in the m-file). The files necessary to reproduce this behaviour are available at http://www.mediafire.com/file/juin0zzin2k/USMCDLLtest.zip. Before the USMCDLL.dll can be used, the MicroSMC driver must be installed on the system and using the DLL requires administrative rights. For more information see the comments in the USMCDLL_test.m file and in the Matlab error message in segmentation_errormessage.txt. Am I doing something wrong in the m-file or is there a problem in Matlab or in the DLL? For people who don't want to download the files, I post the contents of the m-file below. Thanks for any help in advance, Erik
% OS is Windows XP SP2, Matlab version is 22.214.171.1245 (R14) SP2 % ATTENTION: The user must be logged in with administrative rights, % otherwise the USMCDLL library does not work % Before the USMCDLL library can be used, it must be installed with % setup.exe in the MicroSMC folder. % Calls to the USMCDLL library first invoke MicroSMC.exe. Access to the % library functions without MicroSMC properly installed does not work and % produces an error message box, independet of Matlab). % The USMCDLL.h header file must be located on the current Matlab path.
clear all if not(libisloaded('USMCDLL')) loadlibrary('USMCDLL','USMCDLL.h') end %libfunctionsview('USMCDLL')
Devices=libpointer('USMC_Devices_stPtr'); %Devices.Value %this correctly shows %initialized values in the data structure USMC_Devices_st as %defined in USMCDLL.h header file calllib('USMCDLL', 'USMC_Init', Devices); % here, a reproducible %segmentation violation occurs