Re: Segmentation fault when accessing function in a DLL
- From: "Philip Borghesani" <philip_borghesani@xxxxxxxxxxxxxx>
- Date: Mon, 20 Apr 2009 10:22:12 -0400
Erik
You are passing a NULL pointer to the function 'USMC_Init' is that what the function expects or does it expect a pointer to a valid
location? To pass a valid pointer initialize at least one field of the structure before passing it to USMC_Init.
Phil
"Erik Benkler" <erik.benkler@xxxxxx> wrote in message news:gs7f7m$8k9$1@xxxxxxxxxxxxxxxxxxxxx
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
.
- Follow-Ups:
- Re: Segmentation fault when accessing function in a DLL
- From: Erik Benkler
- Re: Segmentation fault when accessing function in a DLL
- References:
- Segmentation fault when accessing function in a DLL
- From: Erik Benkler
- Segmentation fault when accessing function in a DLL
- Prev by Date: Re: How to compute the autocorrelation matrix of a random vector in
- Next by Date: Re: color plot
- Previous by thread: Segmentation fault when accessing function in a DLL
- Next by thread: Re: Segmentation fault when accessing function in a DLL
- Index(es):
Relevant Pages
|
Loading