RobotStudio event

How to unload a module sharing variables and routines with other modules

Luxrobotic
Luxrobotic ✭✭
edited July 2022 in Robot Controller
Hi everybody,

I'm facing a problem ! I need to update a module which contain varaibles and routines shared with other modules.
So I want to use UnLoad and Load instructions, but of course, if the module isn't present in the system, I have semantic errors. So I can't execute the Load instruction.

Is there a possibility to Reload the module ?

Any idea ?

Thanks
Regards

Cornet Raymond
Manager
LUXROBOTIC programming Sàrl
+352 621 354 570
raymond.cornet@luxrobotic.com
http://www.luxrobotic.com

PC HP ZBook 17 G3
intel Core i7 6700HQ 2.59 GHz
RAM 16GB
HDD 1TB
NVIDIA Quadro M1000M
Post edited by Luxrobotic on

Best Answer

  • Forge_Engineering
    Answer ✓
    Hi Cornet, 

    You should be able to use Load and UnLoad or StartLoad and WaitLoad, but the module you are unloading needs to have been loaded with a load instruction from within RAPID.
    The following code only works because the module to be unloaded was loaded in RAPID to begin with:

    There are 3 modules, and it looks like persistents are maintained throughout, although I think variables will be initialised again.
    MODULE MainModule
    	
    	VAR loadsession tempLoad;
    	
    	PROC Main()
    		TPErase;
    		! Module must have been initially loaded with load instruction
    		Load \Dynamic, "HOME:/RemoveModule.MOD";	
    		
    		! execute routine 1
    		%"Routine1"%;
    		
    		! load replacement module
    		StartLoad \Dynamic, "HOME:/TempModule.MOD", tempLoad;
    		! Unload existing module
    		WaitLoad \UnloadPath:="HOME:/RemoveModule.MOD", tempLoad \CheckRef;
    	
    		! execute routine 1
    		%"Routine1"%;
    		
    	ERROR
    		TpWrite "Err";
    		TRYNEXT;
    	ENDPROC
    
    ENDMODULE
     
    MODULE RemoveModule
    	
    	PERS num nVar1;
    	VAR string sVar2 := "asd";
    	
    	PROC Routine1()
    		! Do Stuff
    		nVar1 := 1;
    		TpWrite "set nVar1 to " \num:=nVar1;
    	ENDPROC
    	
    ENDMODULE

    MODULE TempModule
    	
    	PERS num nVar1;
    	VAR string sVar2;
    	
    	PROC Routine1()
    		! Do Stuff
    		TpWrite " ";
    		TPWrite "Value of nVar1 is " \Num:=nVar1;
    		nVar1 := 2;
    		TPWrite "Set Value of nVar1 to " \Num:= nVar1;
    	ENDPROC
    	
    ENDMODULE

    Execute the unload from your main task ideally while there is no other execution to be safe,

    Good Luck,

    Harry

Answers

  • You can disable "Check unresolved references" then you won't get any syntax error for missing variables och procs. But the program will stop if trying to read / write any missing data.
    Systemintegrator - Web / C# / Rapid / Robotstudio

    If I helped, please press Vote Up  :smile:
  • Hi Cornet, 

    You should be able to use Load and UnLoad or StartLoad and WaitLoad, but the module you are unloading needs to have been loaded with a load instruction from within RAPID.
    The following code only works because the module to be unloaded was loaded in RAPID to begin with:

    There are 3 modules, and it looks like persistents are maintained throughout, although I think variables will be initialised again.
    MODULE MainModule
    	
    	VAR loadsession tempLoad;
    	
    	PROC Main()
    		TPErase;
    		! Module must have been initially loaded with load instruction
    		Load \Dynamic, "HOME:/RemoveModule.MOD";	
    		
    		! execute routine 1
    		%"Routine1"%;
    		
    		! load replacement module
    		StartLoad \Dynamic, "HOME:/TempModule.MOD", tempLoad;
    		! Unload existing module
    		WaitLoad \UnloadPath:="HOME:/RemoveModule.MOD", tempLoad \CheckRef;
    	
    		! execute routine 1
    		%"Routine1"%;
    		
    	ERROR
    		TpWrite "Err";
    		TRYNEXT;
    	ENDPROC
    
    ENDMODULE
     
    MODULE RemoveModule
    	
    	PERS num nVar1;
    	VAR string sVar2 := "asd";
    	
    	PROC Routine1()
    		! Do Stuff
    		nVar1 := 1;
    		TpWrite "set nVar1 to " \num:=nVar1;
    	ENDPROC
    	
    ENDMODULE

    MODULE TempModule
    	
    	PERS num nVar1;
    	VAR string sVar2;
    	
    	PROC Routine1()
    		! Do Stuff
    		TpWrite " ";
    		TPWrite "Value of nVar1 is " \Num:=nVar1;
    		nVar1 := 2;
    		TPWrite "Set Value of nVar1 to " \Num:= nVar1;
    	ENDPROC
    	
    ENDMODULE

    Execute the unload from your main task ideally while there is no other execution to be safe,

    Good Luck,

    Harry

    Hi,

    with some litte customization it works fine.

    hanks a lot

    Regards

    Cornet Raymond
    Manager
    LUXROBOTIC programming Sàrl
    +352 621 354 570
    raymond.cornet@luxrobotic.com
    http://www.luxrobotic.com

    PC HP ZBook 17 G3
    intel Core i7 6700HQ 2.59 GHz
    RAM 16GB
    HDD 1TB
    NVIDIA Quadro M1000M