Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Segmentation fault when accessing function in a DLL
Replies: 5   Last Post: Apr 4, 2014 9:54 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Erik Benkler

Posts: 3
Registered: 4/16/09
Segmentation fault when accessing function in a DLL
Posted: Apr 16, 2009 10:27 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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 7.0.4.365 (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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.