2015-07-20 87 views
1

我正嘗試使用MATLAB來控制使用Phidg​​et 1063_1控制器的步進電機。 Phidg​​ets爲他們的設備提供圖書館和示例程序,我試圖運行他們的示例步進電機程序。該程序加載一個C庫(我在MATLAB中沒有經驗)。這是我想運行的程序:在MATLAB中加載C庫時遇到問題

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; 

在一些其他線程,人說,發生這種情況時,C編譯器尚未針對MATLAB進行配置,爲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. 

回答

3

閱讀你的錯誤消息的最後一行:

沒有支持的編譯器或SDK被發現。有關選項,請訪問http://www.mathworks.com/support/compilers/R2015a/win64.html

您目前沒有與您的系統上安裝的R2015兼容的編譯器。訪問該鏈接瞭解您的選擇。您需要獲得兼容的編譯器才能使代碼正常工作。

此外,當你訪問該頁面MathWorks的,免責聲明顯示您的平臺:

對於64位Windows平臺,C編譯器不與MATLAB提供。免費下載是可用的,適合大多數用戶:

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

您試圖編譯C代碼和MATLAB不來隨C編譯器。使用.NET Framework 4下載Microsoft SDK版本7.1是讓您的代碼編譯的最簡單的解決方案。因此,從Microsoft的上述鏈接下載SDK,重新設置mex並再次嘗試您的代碼。

+1

謝謝。我已經完成了Windows SDK和.NET Framework 4的安裝過程,但我沒有密切關注它。 win SDK安裝實際上已經失敗,但我只是點擊「完成」並繼續前進。 對於在安裝win SDK時遇到問題的人,請嘗試卸載所有Visual C++ 2010 Resdistributable並重新安裝。 – Hadi

+0

@Hadi - 哎呀!很高興你想出來了。祝你好運! – rayryeng