MATLAB Answers

defining libpointer for boolean ouput using calllib() functions.

5 views (last 30 days)
Hi
I am programming some hardware to work with MATLAB in our laboratory. I have a stepper motor driver which comes with .dll and .h files.
Everything works fine except for the "isMotorReady" function which has two outputs (Error, which is an integer for error handles and the other (Bool) is a boolean which should return false until the motor stopsmoving). The call looks like this;
[error,Bool] = callllib('UraganLib','isMotorReady',1); % where 1 refers to the device index
The problem is that MATLAB does not have a boolean pointer like "boolPtr" for example. How do I define a boolean pointer?
I tried to define it as an int8Ptr but then I kept getting an error saying that it is not a valid signature.
I've coppied the header file below;
#ifndef _URAGANLIB_H #define _URAGANLIB_H
#define ERROR_NONE 0 #define ERROR_DEVICE_INDEX_OUT_OF_RANGE 1 #define ERROR_DEVICE_ALREADY_IN_USE 2 #define ERROR_DEVICE_OPEN_FAILURE 3 #define ERROR_GET_MOTOR_CONFIG 4 #define ERROR_SET_MOTOR_CONFIG 5 #define ERROR_GET_MOTION_CONFIG 6 #define ERROR_SET_MOTION_CONFIG 7 #define ERROR_MOVE 8 #define ERROR_MOTOR_ON 9 #define ERROR_MOTOR_OFF 10 #define ERROR_MOTOR_STOP 11 #define ERROR_GET_MOTOR_INFO 12 #define ERROR_SET_PWM 13 #define ERROR_SET_RELAY 14
#define ERROR_MOTOR_UNITIALISED 15 #define ERROR_MOTOR_NOT_ON 16 #define ERROR_MOTOR_NOT_OFF 17 #define ERROR_MOTOR_INVALID_VOLTAGE 18 #define ERROR_MOTOR_ERROR 19 #define ERROR_MOTOR_BUSY 20
#define ERROR_PARAM_OUT_OF_RANGE 21 #define ERROR_SET_LIMITS 22 #define ERROR_SET_BACKLASH_COMPENSATION 23 #define ERROR_SET_HOME_SETTINGS 24
#define ERROR_ZERO_MOTOR_POSITION 25
#define ERROR_INITIALISING 26 #define ERROR_NOT_INITIALISED 27
#define ERROR_DEVICE_BUSY_OR_NOT_FOUND 28 #define ERROR_RETRIEVING_DEVICE_SIGNATURE 29 #define ERROR_DEVICE_SIGNATURE 30 #define ERROR_UNSUPPORTED_FIRMWARE_VERSION 31 #define ERROR_UNSUPPORTED_FEATURE 32
#define ERROR_SET_PWM_MODE 33
#define MICROSTEP_NONE 0 #define MICROSTEP_DIV2 1 #define MICROSTEP_DIV4 2 #define MICROSTEP_DIV8 3 #define MICROSTEP_DIV16 4
#define CHANNEL_MODE_OFF 0 #define CHANNEL_MODE_HIGHZ_RISING 1 #define CHANNEL_MODE_HIGHZ_FALLING 2 #define CHANNEL_MODE_PULLDOWN_RISING 3 #define CHANNEL_MODE_PULLDOWN_FALLING 4 #define CHANNEL_MODE_PULLUP_RISING 5 #define CHANNEL_MODE_PULLUP_FALLING 6
#define DIRECTION_FORWARD 0 #define DIRECTION_BACKWARD 1
#define POSITION_START 0 #define POSITION_END 1
#define PWM_MODE_PWM_OUT 0 #define PWM_MODE_STEP_OUT 1
#ifdef __cplusplus extern "C" { #endif __declspec(dllexport) int __cdecl initialise();
__declspec(dllexport) int __cdecl getDeviceCount(int* pCount);
__declspec(dllexport) int __cdecl getDeviceIndex(const char* serialNumber, int *deviceIndex);
__declspec(dllexport) int __cdecl getAbsolutePosition(int deviceIndex, int* pPos);
__declspec(dllexport) int __cdecl setLimitSwitches(int deviceIndex, int startChannel, int startChannelMode, int endChannel, int endChannelMode);
__declspec(dllexport) int __cdecl setHomeSettings(int deviceIndex, int position, bool homeIsAbsoluteZero, bool accurateHomeSearch, int fastSpeed, int slowSpeed);
__declspec(dllexport) int __cdecl setBacklashCompensation(int deviceIndex, bool enable, int direction, int backlashStepCount);
__declspec(dllexport) int __cdecl setMotorCurrent(int deviceIndex, int mA, bool enableReducedHoldCurrent);
__declspec(dllexport) int __cdecl setMotorSpeed(int deviceIndex, int fullStepsPerSecond, int microStepping);
__declspec(dllexport) int __cdecl setMotorAcceleration(int deviceIndex, int fullStepsPerSecondSquared);
__declspec(dllexport) int __cdecl motorOn(int deviceIndex);
__declspec(dllexport) int __cdecl motorOff(int deviceIndex);
__declspec(dllexport) int __cdecl moveMotorHome(int deviceIndex);
__declspec(dllexport) int __cdecl moveMotorRelative(int deviceIndex, int steps);
__declspec(dllexport) int __cdecl moveMotorAbsolute(int deviceIndex, int steps);
__declspec(dllexport) int __cdecl stopMotor(int deviceIndex);
__declspec(dllexport) int __cdecl zeroMotorPosition(int deviceIndex);
__declspec(dllexport) int __cdecl isMotorReady(int deviceIndex, bool* isReady);
__declspec(dllexport) int __cdecl setPWM(int deviceIndex, int percent);
__declspec(dllexport) int __cdecl setPWMStepMode(int deviceIndex);
__declspec(dllexport) int __cdecl setRelay(int deviceIndex, bool on);
#ifdef __cplusplus } #endif #endif // _URAGANLIB_H

  0 Comments

Sign in to comment.

Accepted Answer

Philip Borghesani
Philip Borghesani on 17 Oct 2017
If you look at libfunctions -full UraganLib for isMotorReady it will require two inputs. All pointer arguments are passed both directions because calllib has no way of knowing what is an input and what is an output. Try:
dontcare=false;
[error,ready] = callllib('UraganLib','isMotorReady',1,dontcare);

  0 Comments

Sign in to comment.

More Answers (0)