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:

    ☑️2024 - RobotStudio® User Group
  • 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
  • Daper
    Daper
    edited August 12
    Hello,
    I am struggling at using a sequence of Unload + StartLoad in my program and I feel it looks quite like the problem described in this thread by @Forge_Engineering :

    Situation: I want to execute a program after the module is loaded into the task. This loading comes up after the .mod file has been put in the HOME folder of the robot. The robot is sometimes turned off between two executions on purpose (over night for example). This the reason why at program start, I check if the module of the day is newer than the one of the day before, and load it in the task in latter case.

    Problem: The robot is turned on and there is already the module in the task.  When I try to unload the module and replace it by the new one, I have an error "Module must first be loaded using StartLoad".
    Thus I try to remove the Unload instruction and only use Startload. Now it says "the module already exists and cannot be loaded in task"

    So long story short I can't unload the old one because from the robot perspective, "it has not been loaded yet", but I can't load the new one because there's already one in the Task...

    Is there anyone who knows how I am supposed to do ?
  • Hi

    You will have to use the EraseModule command.
  • Thank you so much