Clear Filters
Clear Filters

Cannot register Custom Add-on Library

57 views (last 30 days)
Jana
Jana on 3 Jul 2024 at 10:22
Commented: Jana on 6 Jul 2024 at 8:02
I've written a custom add-on library to controll a stepper motor, however I'm having trouble registering it. I've both added the path via Set Path and tried running >>addpath('C:\Users\...'), but when I type in >>listArduinoLibraries, the add-on doesn't show up.
The Current Folder browser looks excactly as shown here (https://de.mathworks.com/help/matlab/supportpkg/register-add-on-library.html), with only the src folder and its content appearing faded.
This is my C++ Header File:
# include "LibraryBase.h"
# include "Stepper.h"
// Command IDs
# define ROTATE_STEPPER 0x01
# define STEPPER_SPEED 0x02
class Stepper_L298N : public LibraryBase
{
private:
Stepper stepper;
public:
Stepper_L298N(MWArduinoClass& a, int stepsPerRevolution, int pin1, int pin2, int pin3, int pin4)
: stepper (stepsPerRevolution, pin1, pin2, pin3, pin4)
{
libName = "Stepper_L298N";
a.registerLibrary(this);
}
public:
void commandHandler(byte cmdID, byte* dataIn, unsigned int payloadSize)
{
switch (cmdID){
case ROTATE_STEPPER:{
int steps;
memcpy(&steps, dataIn, sizeof(int));
stepper.step(steps);
sendResponseMsg(cmdID, 0, 0);
break;
}
case STEPPER_SPEED:{
int speed;
memcpy(&speed, dataIn, sizeof(int));
stepper.setSpeed(speed);
sendResponseMsg(cmdID, 0, 0);
break;
}
default:{
}
}
}
};
The first part of my Add-On Class looks like this:
classdef Stepper_L298N < matlabshared.addon.LibraryBase
properties (Access = protected)
Pins
end
properties (Access = private, Constant = true)
ROTATE_STEPPER = hex2dec('01')
STEPPER_SPEED = hex2dec('02')
end
properties (Access = protected, Constant = true)
LibraryName = 'Stepper_L298N'
DependentLibraries = {}
LibraryHeaderFiles = 'Stepper.h'
CppHeaderFile = fullfile(arduinoio.FilePath(mfilename('fullpath')), 'src', 'Stepper_L298N.h')
CppClassName = 'Stepper_L298N'
end
I've checked for typos in the file names, but I can't find any. Any advice what else could be wrong?
  1 Comment
Jana
Jana on 6 Jul 2024 at 8:02
Okay, so I've contacted tech support about this, and what ended up solving it for me was changing the folder stucture, so that the src folder is now a subfolder of the +arduinoioaddons folder, and not the +ExampleAddon folder anymore. No idea why, but I can register my library now :)

Sign in to comment.

Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!