【问题标题】:Trouble loading C library in MATLAB在 MATLAB 中加载 C 库时遇到问题
【发布时间】:2015-07-20 17:58:35
【问题描述】:

我正在尝试使用 MATLAB 来控制使用 Phidg​​et 1063_1 控制器的步进电机。 Phidg​​ets 为他们的设备提供库和示例程序,我正在尝试运行他们的示例步进电机程序。该程序加载一个 C 库(我在 MATLAB 中没有经验)。这是我要运行的程序:

function stepper

loadphidget21;

stepperHandle = libpointer('int32Ptr');
calllib('phidget21', 'CPhidgetStepper_create', stepperHandle);
calllib('phidget21', 'CPhidget_open', stepperHandle, -1);

valPtr = libpointer('int64Ptr', 0);

if calllib('phidget21', 'CPhidget_waitForAttachment', stepperHandle, 2500) == 0
    disp('Opened Stepper');

    t = timer('TimerFcn','disp(''waiting...'')', 'StartDelay', 1.0);

    %set parameters for stepper motor in index 0 (velocity, acceleration, current)
    %these values were set basd on some testing based on a 1063 and a stepper motor I had here to test with
    %might need to modify these values for your particular case
    calllib('phidget21', 'CPhidgetStepper_setVelocityLimit', stepperHandle, 0, 6200);
    calllib('phidget21', 'CPhidgetStepper_setAcceleration', stepperHandle, 0, 87543);
    calllib('phidget21', 'CPhidgetStepper_setCurrentLimit', stepperHandle, 0, 0.26);

    %IMPORTANT: If you are using a 1062, delete this line.  This command is only for the 1063 Bipolar stepper controller
    calllib('phidget21', 'CPhidgetStepper_setCurrentPosition', stepperHandle, 0, 0);

    start(t);
    wait(t);

    disp('Engage Motor 0');

    %engage the stepper motor in index 0
    calllib('phidget21', 'CPhidgetStepper_setEngaged', stepperHandle, 0, 1);
    start(t);
    wait(t);

    currPosition=0;
    calllib('phidget21', 'CPhidgetStepper_getCurrentPosition', stepperHandle, 0, valPtr);
    currPosition = get(valPtr, 'Value');

    disp('Move to 20000');

    %set motor to position 1 (20000)
    calllib('phidget21', 'CPhidgetStepper_setTargetPosition', stepperHandle, 0, 20000);

    %wait for motor to arrive
    while currPosition < 20000
        calllib('phidget21', 'CPhidgetStepper_getCurrentPosition', stepperHandle, 0, valPtr);
        currPosition = get(valPtr, 'Value');
    end
    disp('Motor reached target');

    start(t);
    wait(t);

    disp('Move to 0');

    %set motor to position 2 (0)
    calllib('phidget21', 'CPhidgetStepper_setTargetPosition', stepperHandle, 0, 0);

    %wait for motor to arrive
    while currPosition > 0
        calllib('phidget21', 'CPhidgetStepper_getCurrentPosition', stepperHandle, 0, valPtr);
        currPosition = get(valPtr, 'Value');
    end
    disp('Motor reached target');

    disp('Disengage Motor 0');

    %disengage the stepper motor in index 0
    calllib('phidget21', 'CPhidgetStepper_setEngaged', stepperHandle, 0, 0);
    start(t);
    wait(t);
else
    disp('Could Not Open Stepper');
end

disp('Closing Stepper');
% clean up
calllib('phidget21', 'CPhidget_close', stepperHandle);
calllib('phidget21', 'CPhidget_delete', stepperHandle);

disp('Closed Stepper');

当我运行它时,我得到以下错误:

>> stepper
Index exceeds matrix dimensions.

Error in loadlibrary>getLoadlibraryCompilerConfiguration (line 527)



Error in loadlibrary (line 263)



Error in loadphidget21 (line 12)
            [notfound,warnings]=loadlibrary('phidget21', 'phidget21Matlab_Windows_x64.h');

Error in stepper (line 3)
loadphidget21;

在其他一些线程中,人们说当没有为 MATLAB 配置 C 编译器时会发生这种情况,而为 mex 配置编译器应该可以解决这个问题。我也遇到了这个问题:

>> mex -setup
Error using mex
No supported compiler or SDK was found. For options, visit  http://www.mathworks.com/support/compilers/R2015a/win64.html.

【问题讨论】:

    标签: matlab mex loadlibrary


    【解决方案1】:

    阅读错误消息的最后一行:

    未找到支持的编译器或 SDK。如需选项,请访问http://www.mathworks.com/support/compilers/R2015a/win64.html

    您的系统上目前没有安装与 R2015 兼容的编译器。访问该链接以获取您的选项。您需要获得兼容的编译器才能使您的代码正常工作。

    此外,当您访问 MathWorks 页面时,系统会针对您的平台显示免责声明:

    对于 64 位 Windows 平台,MATLAB 不提供 C 编译器。适合大多数用户的免费下载:

    http://www.microsoft.com/en-us/download/details.aspx?id=8279

    您正在尝试编译 C 代码,而 MATLAB 未附带 C 编译器。下载带有 NET Framework 4 的 Microsoft SDK 版本 7.1 是让您的代码编译的最简单的解决方案。因此,请从 Microsoft 的上述链接下载 SDK,重新设置 mex 并再次尝试您的代码。

    【讨论】:

    • 谢谢。我已经完成了 Windows SDK 和 NET framework 4 的安装过程,但我没有密切关注它。 win SDK 安装实际上失败了,但我只是单击“完成”并继续前进。对于在安装 win SDK 时遇到问题的任何人,请尝试卸载所有 Visual C++ 2010 Resdistributables 并重新安装。
    • @Hadi - 哎呀!很高兴你想出来了。祝你好运!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多