Returning error number as string when only Int32Ptr is accepted in Matlab
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Philip Borghesani
le 24 Juin 2016
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 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!