利用matlab调用动态链接库无法连续


#1

clc
clear

if ~libisloaded(‘DobotDll’)
[notfound, warnings]=loadlibrary(‘DobotDll.dll’,‘DobotDll.h’);
end

%for i=1:2
ch=blanks(128);
str1= libpointer(‘cstring’,ch);
[res1,res2]=calllib(‘DobotDll’,‘SearchDobot’,str1,128);
str2= libpointer(‘cstring’,res2);
[res3,res4]=calllib(‘DobotDll’,‘ConnectDobot’,str2, 115200);

queue_index=0;
ptp.ptpMode=0;
ptp.x=250.0;
ptp.y=80.0;
ptp.z=0.0;
ptp.r=0.0;
ptpstruct=libstruct(‘tagPTPCmd’,ptp);
ptpstructptr=libpointer(‘tagPTPCmdPtr’,ptpstruct);
queue_index_ptr=libpointer(‘uint64Ptr’,queue_index);

calllib(‘DobotDll’,‘SetQueuedCmdStartExec’);
calllib(‘DobotDll’,‘SetEndEffectorSuctionCup’,1,1,true,queue_index_ptr);
pause(0.2)
calllib(‘DobotDll’,‘SetPTPCmd’,ptpstructptr,true,queue_index_ptr);
pause(0.2)

queue_index=1;
ptp.ptpMode=0;
ptp.x=200.0;
ptp.y=80.0;
ptp.z=20.0;
ptp.r=0.0;
ptpstruct=libstruct(‘tagPTPCmd’,ptp);
ptpstructptr=libpointer(‘tagPTPCmdPtr’,ptpstruct);
queue_index_ptr=libpointer(‘uint64Ptr’,queue_index);
calllib(‘DobotDll’,‘SetPTPCmd’,ptpstructptr,true,queue_index_ptr);
pause(0.2)

queue_index=2;
ptp.ptpMode=0;
ptp.x=250.0;
ptp.y=0.0;
ptp.z=0.0;
ptp.r=0.0;
ptpstruct=libstruct(‘tagPTPCmd’,ptp);
ptpstructptr=libpointer(‘tagPTPCmdPtr’,ptpstruct);
queue_index_ptr=libpointer(‘uint64Ptr’,queue_index);
calllib(‘DobotDll’,‘SetPTPCmd’,ptpstructptr,true,queue_index_ptr);
pause(1.5)
calllib(‘DobotDll’,‘SetEndEffectorSuctionCup’,1,0,true,queue_index_ptr);
%end
calllib(‘DobotDll’,‘SetQueuedCmdStopExec’);
pause(0.2)
calllib(‘DobotDll’,‘SetQueuedCmdClear’);
pause(0.2)
calllib(‘DobotDll’,‘DisconnectDobot’);

clear

将注释掉的for循环解开后,有时可以连续运行,但是调用归零时,添加循环也无法成功