Prev: seeking help on logic expression
Next: Reading a large mixed CSV file of unknown types and size
From: kees de Kapper on 21 Jun 2010 11:27 Hi all, I've got the following problem. Running the following matlab code, the first calllib results in nRet = 0, which means OK the second calllib let Matlab crash instantaniously. This has something to do with the declaration of the phAcqDesc pointer, which should behave like a windows HANDLE. But what do I do wrong? ====== Matlab code, library call to the c++ code ===============\/ loadlibrary('xisl','Acq.h'); phAcqDesc = libpointer('voidPtr'); % HACQDESC *phAcqDesc dwChannelType = uint32(1); % DWORD dwChannelType nChannelNr = int32(0); % int nChannelNr, bEnableIRQ = int32(0); % BOOL bEnableIRQ Rows = uint32(256); % UINT Rows Columns = uint32(256); % UINT Columns, dwSortFlags = uint32(2); % UINT dwSortFlags bSelfInit = int32(1); % BOOL bSelfInit bAlwaysOpen = int32(1); % BOOL bAlwaysOpen nRet = calllib('xisl','Acquisition_Init', phAcqDesc, ... dwChannelType, nChannelNr, ... bEnableIRQ, ... Rows, Columns, ... dwSortFlags, ... bSelfInit, bAlwaysOpen); nRet = calllib('xisl','Acquisition_SetCameraMode', phAcqDesc, uint32(0)); ====== Original C++ code in DLL library ======================\/ typedef HANDLE HACQDESC; typedef UINT ACQDESCPOS; _DLL_DECL UINT WINAPI Acquisition_Init(HACQDESC *phAcqDesc, DWORD dwChannelType, int nChannelNr, BOOL bEnableIRQ, UINT Rows, UINT Columns, UINT dwSortFlags, BOOL bSelfInit, BOOL bAlwaysOpen); _DLL_DECL UINT WINAPI Acquisition_SetCameraMode(HACQDESC hAcqDesc, UINT dwMode);
From: Philip Borghesani on 21 Jun 2010 12:57 A c calling example would have been helpful. Try this: phAcqDesc = libpointer('voidPtr',uint32(0)); % HACQDESC *phAcqDesc It is possible that the function needs memory to put the handle into. In 64 bit MATLAB a uint64 will be needed. Phil "kees de Kapper" <kees_de_kapper(a)hotmail.com> wrote in message news:hvo0d8$23a$1(a)fred.mathworks.com... > Hi all, > > I've got the following problem. > > Running the following matlab code, the first calllib results in nRet = 0, which means OK > the second calllib let Matlab crash instantaniously. > > This has something to do with the declaration of the phAcqDesc pointer, which should behave like a windows HANDLE. > > But what do I do wrong? > ====== Matlab code, library call to the c++ code ===============\/ > > loadlibrary('xisl','Acq.h'); > > phAcqDesc = libpointer('voidPtr'); % HACQDESC *phAcqDesc > dwChannelType = uint32(1); % DWORD dwChannelType > nChannelNr = int32(0); % int nChannelNr, > bEnableIRQ = int32(0); % BOOL bEnableIRQ Rows = uint32(256); % UINT Rows > Columns = uint32(256); % UINT Columns, dwSortFlags = uint32(2); % UINT dwSortFlags > bSelfInit = int32(1); % BOOL bSelfInit > bAlwaysOpen = int32(1); % BOOL bAlwaysOpen > > nRet = calllib('xisl','Acquisition_Init', phAcqDesc, ... > dwChannelType, nChannelNr, ... > bEnableIRQ, ... > Rows, Columns, ... > dwSortFlags, ... > bSelfInit, bAlwaysOpen); > > > nRet = calllib('xisl','Acquisition_SetCameraMode', phAcqDesc, uint32(0)); > > ====== Original C++ code in DLL library ======================\/ > > typedef HANDLE HACQDESC; > typedef UINT ACQDESCPOS; > > _DLL_DECL UINT WINAPI Acquisition_Init(HACQDESC *phAcqDesc, > DWORD dwChannelType, int nChannelNr, > BOOL bEnableIRQ, UINT Rows, UINT Columns, UINT dwSortFlags, > BOOL bSelfInit, BOOL bAlwaysOpen); > > _DLL_DECL UINT WINAPI Acquisition_SetCameraMode(HACQDESC hAcqDesc, UINT dwMode); >
From: kees de Kapper on 22 Jun 2010 05:46 Thank you for replying. It is an 32bit DLL as well as an 32 bit Matlab version. This is the call in windows: ==============================================\/ HACQDESC hAcqDesc=NULL; DWORD dwChannelType, dwRows, dwColumns, dwSortFlags; int nChannelNr; BOOL bEnableIRQ, bSelfInit, bAlwaysOpen; Acquisition_Init(&hAcqDesc, dwChannelType, nChannelNr, bEnableIRQ, Rows, Columns, dwSortFlags, bSelfInit, bAlwaysOpen); Acquisition_SetCameraMode(hAcqDesc,0); ==============================================/\ Could you give me a clue, how to call these functions properly in Matlab including the pointers. thanx, Kees "Philip Borghesani" <philip_borghesani(a)mathworks.spam> wrote in message <hvo5ll$d03$1(a)fred.mathworks.com>... > A c calling example would have been helpful. Try this: > > phAcqDesc = libpointer('voidPtr',uint32(0)); % HACQDESC *phAcqDesc > > It is possible that the function needs memory to put the handle into. In 64 bit MATLAB a uint64 will be needed. > > Phil >
From: kees de Kapper on 22 Jun 2010 06:42 I think I got the first part of the clue. Indeed the addition of uint32(0) helped a lot. I tried it before but another issue caused the problem and I did not notice it. Namely, I forgot to put the return-variables in the left-hand-side of the call function. It should have been: [nRet,phAcqDesc] =calllib('xisl','Acquisition_Init',phAcqDesc, dwChannelType, nChannelNr, bEnableIRQ, Rows, Columns, dwSortFlags, bSelfInit, bAlwaysOpen); However, there is still a problem. Now, I can get a pointer back. But this iis a pointer to a datatype called HANDLE (a know windows datatype). This datatype is not know in Matlab. The error message I got using get(phAcqDesc, 'value') is therefore 'The datatype and size of the value must be defined before the value can be retrieved.'. I need this 'value', since the other functions needs the handle and not the pointer: C++ code: Acquisition_SetCameraMode(hAcqDesc,0); (c++header declaration:_DLL_DECL UINT WINAPI Acquisition_SetCameraMode(HACQDESC hAcqDesc, UINT dwMode);) What is the solution for this problem? How can I call this function properly? thanx!
From: kees de Kapper on 22 Jun 2010 08:45 I've made some progress but stuck now. To clarify my question, I re-post the c++ code and my Matlab implementation. The Matlab program crashes during the last function call (Acquisition_SetCameraMode). What could be the cause, and what would be a solution? many thanks in advance, Kees ==================================================== ====== Original C++ code: Header.h ===========================\/ typedef HANDLE HACQDESC; typedef UINT ACQDESCPOS; _DLL_DECL UINT WINAPI Acquisition_Init(HACQDESC *phAcqDesc, DWORD dwChannelType, int nChannelNr, BOOL bEnableIRQ, UINT Rows, UINT Columns, UINT dwSortFlags, BOOL bSelfInit, BOOL bAlwaysOpen); _DLL_DECL UINT WINAPI Acquisition_SetCameraMode(HACQDESC hAcqDesc, UINT dwMode); ====== Original C++ code: main.c ============================\/ HACQDESC hAcqDesc=NULL; DWORD dwChannelType, dwRows, dwColumns, dwSortFlags; int nChannelNr; BOOL bEnableIRQ, bSelfInit, bAlwaysOpen; Acquisition_Init(&hAcqDesc, dwChannelType, nChannelNr, bEnableIRQ, Rows, Columns, dwSortFlags, bSelfInit, bAlwaysOpen); Acquisition_SetCameraMode(hAcqDesc,0); ==================================================== ==================================================== ==================================================== ====== Matlab code, library call to the c++ code ===================\/ loadlibrary('xisl','Acq.h'); % phAcqDesc is a pointer to a handle (hAcqDesc) phAcqDesc = libpointer('voidPtr', uint32(0)); % HACQDESC *phAcqDesc dwChannelType = uint32(1); % DWORD dwChannelType nChannelNr = int32(0); % int nChannelNr, bEnableIRQ = int32(0); % BOOL bEnableIRQ Rows = uint32(256); % UINT Rows Columns = uint32(256); % UINT Columns, dwSortFlags = uint32(2); % UINT dwSortFlags bSelfInit = int32(1); % BOOL bSelfInit bAlwaysOpen = int32(1); % BOOL bAlwaysOpen [nRet, phAcqDesc] = calllib('xisl','Acquisition_Init', phAcqDesc, ... dwChannelType, nChannelNr, ... bEnableIRQ, ... Rows, Columns, ... dwSortFlags, ... bSelfInit, bAlwaysOpen); % Then (re)set the data type since it appeared to be unknown setdatatype(phAcqDesc, 'voidPtr', 1, 1); % get the value (the handle 'hAcqDesc') from the pointer hAcqDesc = get(phAcqDesc, 'Value'); [nRet, hAcqDesc] = calllib('xisl','Acquisition_SetCameraMode', hAcqDesc, uint32(0)); ====================================================
|
Next
|
Last
Pages: 1 2 3 Prev: seeking help on logic expression Next: Reading a large mixed CSV file of unknown types and size |