方法一:直接使用例行程序名调用例行程序
太过简单,不加以描述
方法二:%调用
%“proc name”%调用例行程序
代码演示:
MODULE CommonMain PROC main() VAR num pathnum:=0; VAR num targetnum:=0; VAR num targettest:=10; %"MoveRail"% 0,0; !例行程序普通参数测试 %"MoveRail"% 0\exact,0; !例行程序带开关参数测试 %"MoveRail"% 0,0\target:=targettest; !例行程序带可选参数测试 %"Rob1_Side"+NumToStr(pathnum,0)+"_"+NumToStr(targetnum,0)%; !常见路径样式调用测试 ENDPROC PROC MoveRail(num movedistance\switch exact,num transdis\switch Rhome\var num target) IF Present(exact) THEN TPWrite"2,exact"; ELSE IF Present(target) THEN TPWrite"3,target:="\Num:=target; ELSE TPWrite"1,no exact"; ENDIF ENDIF ENDPROC PROC Rob1_Side0_0() TPWrite"Rob1_Side0_0"; ENDPROC ENDMODULE
错误处理,可能存在加载错误
ERROR TEST ERRNO case ERR_LOADED; !报错处理 default: !正常
方法三:CallByVar指令
代码演示:
PROC CallPath(num TrackDistance, string PathName\switch home) VAR num NumLen:=0; VAR string ProcName; VAR string NumName; VAR num CGrdSpd:=0; VAR bool Check:=FALSE; VAR num MinTrack:=0; IF StrMatch(PathName,1,"Up")<(StrLen(PathName)+1) THEN MinTrack:=MinTrack_up; ELSEIF StrMatch(PathName,1,"Mid")<(StrLen(PathName)+1) THEN MinTrack:=MinTrack_mid; ELSEIF StrMatch(PathName,1,"Down")<(StrLen(PathName)+1) THEN MinTrack:=MinTrack_down; ENDIF NumLen:=StrLen(PathName)-DivideLen; ProcName:=StrPart(PathName, 1, DivideLen); NumName:=StrPart(PathName,DivideLen+1,NumLen); Check:=StrToVal(NumName, ProcNumber); IF TrackDistance+wobj_x_displace<MinTrack THEN rHome; ELSE IF Present(home)=TRUE THEN MoveRail TrackDistance, RailSpeed, wobj_x_displace\Rhome; ELSE MoveRail TrackDistance, RailSpeed, wobj_x_displace; ENDIF bladeWobj.uframe.trans.x:=(CarriagePositionActualCom/100-wobj_x_displace); CallByVar ProcName, ProcNumber; ENDIF ENDPROC
原文地址:https://www.cnblogs.com/xyb617/p/12106235.html
时间: 2024-10-21 21:15:26