Returning error number as string when only Int32Ptr is accepted in Matlab
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm new to using dll files in Matlab and am having some trouble returning the errorNumber and the value of xMotor. The documentation for the dll is specific to C and suggests using the following to achieve what I want to:
#include “PiUsb.h”
void * pUsb1;
int ErrorNumber;
int MotorSerialNumber = 10; // Serial number from Motor
pUsb1 = piConnectMotor(&ErrorNumber,MotorSerialNum);
if (ErrorNumber == PI_DEVICE_NOT_FOUND)
AfxMessageBox( "Unable to find Motor..." );
else
AfxMessageBox( "Motor Connected." );
However, I want to be able to do this in Matlab.
I've succesffully loaded the dll into Matlab with:
fullpathToPiUSBHeader = [pwd filesep 'picardStage' filesep 'PiUsb.h']
fullpathToPiUSBDll = [pwd filesep 'picardStage' filesep 'PiUsb.dll']
fullpathToPiUSBHeader = [pwd filesep 'picardStage' filesep 'PiUsb.h']
if not(libisloaded(fullpathToPiUSBHeader))
loadlibrary(fullpathToPiUSBDll,fullpathToPiUSBHeader)
end
libfunctions('PiUsb','-full')
And I'm returned the full list of functions, in particular this function:
[lib.pointer, int32Ptr] = piConnectMotor(int32Ptr, int32)
This is what I've got so far:
errorNumber = libpointer('int32Ptr',0);
xMotor = libpointer('voidPtr');
xMotor = calllib('PiUsb','piConnectMotor',errorNumber,xMotorSerialNumber)
I want to be able to get the errorNumber result back as well as the value for xMotor, however their values are just returned as "libpointer". Any ideas on how I can access the values/results?
Any help would be greatly appreciated!
댓글 수: 0
답변 (1개)
Philip Borghesani
2016년 6월 24일
Remember that MATLAB creates everything(*) on the left of an equals sign and don't bother initializing xMotor and errorNumber then call:
[xMotor,errNumber] = calllib('PiUsb','piConnectMotor',0,xMotorSerialNumber);
errNumber should contain an integer value and xMotor will contain an unreadable handle (void*) that can be passed to other functions.
In your code errorNumber should have had a value what is
errorNumber.value
*Provided no indexing is done on the LHS
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!