Returning error number as string when only Int32Ptr is accepted in Matlab
4 次查看(过去 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!