%%%
	VERSION:1
	LANGUAGE:ENGLISH
%%%

MODULE ADVFUN (SYSMODULE,NOVIEW)

	LOCAL CONST num NoOfMoveSync := 10;
	! Init at PP to main
	LOCAL VAR intnum MoveSyncIntnum{NoOfMoveSync};
	LOCAL VAR string MoveSyncCurRout{NoOfMoveSync};
	LOCAL VAR num MoveSyncIndex;
	LOCAL VAR num MoveSyncOldRun;
  
	PROC MoveCSync (
		robtarget CirPoint,
		robtarget ToPoint,        
		speeddata Speed
		\num T,
		zonedata Zone,
		PERS tooldata Tool
		\PERS wobjdata WObj,
		string ProcName)
    
		VAR triggdata my_triggdata;

		! Actions acc. running mode
		TEST RunMode()
			CASE RUN_CONT_CYCLE:				
				MoveSyncOldRun := RUN_CONT_CYCLE;
				MoveSyncSetup ProcName;	
				TriggInt my_triggdata, 0, MoveSyncIntnum{MoveSyncIndex}; 
				TriggC CirPoint, ToPoint, Speed \T?T, my_triggdata, Zone, Tool \WObj?WObj;
				IF (RunMode() <> RUN_CONT_CYCLE) THEN
					MoveSyncErr;
				   MoveSyncOldRun := RunMode();
					MoveSyncReset;       
					% ProcName %;
				ENDIF
			CASE RUN_INSTR_FWD,RUN_STEP_MOVE:
				MoveSyncOldRun := RunMode();
				MoveSyncReset;
				MoveC CirPoint, ToPoint, Speed \T?T, Zone, Tool \WObj?WObj;
				% ProcName %;
			CASE RUN_SIM:
				MoveSyncOldRun := RUN_SIM;
			DEFAULT:
				MoveSyncOldRun := RUN_UNDEF;
		ENDTEST 
    
		BACKWARD
			MoveSyncOldRun := RUN_INSTR_BWD;
			MoveSyncReset;
			MoveC CirPoint, ToPoint, Speed \T?T, Zone, Tool \WObj?WObj;
	ENDPROC       
  
	PROC MoveJSync (
		robtarget ToPoint,
		speeddata Speed
		\num T,
		zonedata Zone,
		PERS tooldata Tool
		\PERS wobjdata WObj,
		string ProcName)
    
		VAR triggdata my_triggdata;
    
		! Actions acc. running mode
		TEST RunMode()
			CASE RUN_CONT_CYCLE:
				MoveSyncOldRun := RUN_CONT_CYCLE;
				MoveSyncSetup ProcName;
				TriggInt my_triggdata, 0, MoveSyncIntnum{MoveSyncIndex}; 
				TriggJ ToPoint, Speed \T?T, my_triggdata, Zone, Tool \WObj?WObj;
				IF (RunMode() <> RUN_CONT_CYCLE) THEN
					MoveSyncErr;
				   MoveSyncOldRun := RunMode();
					MoveSyncReset;       
					% ProcName %;
				ENDIF
			CASE RUN_INSTR_FWD,RUN_STEP_MOVE:
				MoveSyncOldRun := RunMode();
				MoveSyncReset;
				MoveJ ToPoint, Speed \T?T, Zone, Tool \WObj?WObj;
				% ProcName %;
			CASE RUN_SIM:
				MoveSyncOldRun := RUN_SIM;	
			DEFAULT:
				MoveSyncOldRun := RUN_UNDEF;
		ENDTEST
    
		BACKWARD
			MoveSyncOldRun := RUN_INSTR_BWD;
			MoveSyncReset;
			MoveJ ToPoint, Speed \T?T, Zone, Tool \WObj?WObj; 
	ENDPROC  
  
  
   PROC MoveLSync (
		robtarget ToPoint,
		speeddata Speed
		\num T,
		zonedata Zone,
		PERS tooldata Tool
		\PERS wobjdata WObj,
		string ProcName)
    
		VAR triggdata my_triggdata;
    
		! Actions acc. running mode
		TEST RunMode()   
			CASE RUN_CONT_CYCLE:
				MoveSyncOldRun := RUN_CONT_CYCLE;
				MoveSyncSetup ProcName;
				TriggInt my_triggdata, 0, MoveSyncIntnum{MoveSyncIndex}; 
				TriggL ToPoint, Speed \T?T, my_triggdata, Zone, Tool \WObj?WObj;
				IF (RunMode() <> RUN_CONT_CYCLE) THEN
					MoveSyncErr;
				   MoveSyncOldRun := RunMode();
					MoveSyncReset;       
					% ProcName %;
				ENDIF
			CASE RUN_INSTR_FWD,RUN_STEP_MOVE:
				MoveSyncOldRun := RunMode();
				MoveSyncReset;
				MoveL ToPoint, Speed \T?T, Zone, Tool \WObj?WObj;
				% ProcName %;
			CASE RUN_SIM:
				MoveSyncOldRun := RUN_SIM;
			DEFAULT:
				MoveSyncOldRun := RUN_UNDEF;
		ENDTEST
    
		BACKWARD
			MoveSyncOldRun := RUN_INSTR_BWD;
			MoveSyncReset;
			MoveL ToPoint, Speed \T?T, Zone, Tool \WObj?WObj;
	ENDPROC
  
	LOCAL PROC MoveSyncReset ()
		FOR i FROM 1 TO  NoOfMoveSync DO
			IDelete MoveSyncIntnum{i};
		ENDFOR 
	ENDPROC
  
	LOCAL PROC MoveSyncErr ()
		IF MoveSyncOldRun = RUN_CONT_CYCLE THEN
			ErrWrite "MoveXSync warning 1.",
				"Some sync. procedure on the path"
				\RL2:= "may not have been executed, "
				\RL3:= "because of run mode switch from"
				\RL4:= "CONT/CYCLE to FWD/BWD step.";
			ErrWrite "MoveXSync warning 2.",
				"Use StopInst in stead of normal"
				\RL2:= "Stop to avoid above problem."
				\RL3:= "To continue, press FWD or BWD.";
			Stop;   
		ENDIF
	ENDPROC  
  

	LOCAL PROC MoveSyncSetup (string ProcName)
		IF MoveSyncIndex = NoOfMoveSync THEN
			MoveSyncIndex:=1;
		ELSE
			MoveSyncIndex:=MoveSyncIndex+1;
		ENDIF
	        
		TEST MoveSyncIndex
			CASE 1:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap1;	   
			CASE 2:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap2;	   
			CASE 3:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap3;
			CASE 4:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap4;	 	
			CASE 5:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap5;
			CASE 6:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap6;	   
			CASE 7:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap7;	   
			CASE 8:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap8;
			CASE 9:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap9;	 	
			CASE 10:
				CONNECT MoveSyncIntnum{MoveSyncIndex} WITH MoveSyncTrap10;	    
		ENDTEST
      MoveSyncCurRout{MoveSyncIndex}:= ProcName;
		ERROR
			IF ERRNO = ERR_ALRDYCNT THEN
				IDelete  MoveSyncIntnum{MoveSyncIndex};
				RETRY;
			ENDIF
	ENDPROC
        
	LOCAL TRAP MoveSyncTrap1
		IDelete  MoveSyncIntnum{1};
		%MoveSyncCurRout{1}%;     
	ENDTRAP
  
	LOCAL TRAP MoveSyncTrap2
		IDelete  MoveSyncIntnum{2};
		%MoveSyncCurRout{2}%;
	ENDTRAP  
  
	LOCAL TRAP MoveSyncTrap3
		IDelete  MoveSyncIntnum{3};
		%MoveSyncCurRout{3}%;
	ENDTRAP  
  
	LOCAL TRAP MoveSyncTrap4
		IDelete  MoveSyncIntnum{4};
		%MoveSyncCurRout{4}%;
	ENDTRAP  
  
	LOCAL TRAP MoveSyncTrap5
		IDelete  MoveSyncIntnum{5};
		%MoveSyncCurRout{5}%;
	ENDTRAP
  
	LOCAL TRAP MoveSyncTrap6
		IDelete  MoveSyncIntnum{6};
		%MoveSyncCurRout{6}%;     
	ENDTRAP
  
	LOCAL TRAP MoveSyncTrap7
		IDelete  MoveSyncIntnum{7};
		%MoveSyncCurRout{7}%;
	ENDTRAP  
  
	LOCAL TRAP MoveSyncTrap8
		IDelete  MoveSyncIntnum{8};
		%MoveSyncCurRout{8}%;
	ENDTRAP  
  
	LOCAL TRAP MoveSyncTrap9
		IDelete  MoveSyncIntnum{9};
		%MoveSyncCurRout{9}%;
	ENDTRAP  
  
	LOCAL TRAP MoveSyncTrap10
		IDelete  MoveSyncIntnum{10};
		%MoveSyncCurRout{10}%;
	ENDTRAP
    
ENDMODULE

