Global variabel
I have declared a couple of global variables in my main program and can access these values from another module which I load with the load command. However I cannot set these variables from the loaded module. How do I do that? I have the following code:
Module mod1
PERS bool red := FALSE;
PERS bool black := FALSE;
PERS bool green := FALSE;
PROC main()
LOAD "C:/folder/file.prg";
%"paintprg:callMe"%;
UNLOAD "C:/folder/file.prg";
ENDPROC
ENDMODULE
MODULE mod2
PROC callMe()
red := TRUE; ! This doesn't work
ENDPROC
ENDMODULE
Why won't that work and how should I do to solve it?
0
Comments
-
Hi
I recommend you to use .MOD files for your modules.
In your example, file.prg should be Mod2.mod
I usually use a module containing only the PERS variables, such as:
MODULE Globals
PERS bool red := FALSE;
PERS bool black := FALSE;
PERS bool green := FALSE;
ENDMODULE
Then a small module that loads the most of the code, such as:
MODULE StdTask
PROC Main()
LOAD "C:/folder/modmain.mod";
red:=FALSE;
TPWrite "Now red is FALSE";
%"MainEntry"%;
IF red THEN
TPWrite "Now red is TRUE";
ENDIF
ENDPROC
ENDMODULE
And the main module
MODULE ModMain
PROC MainEntry()
red := TRUE; & nbsp; ! This will work
Save "GLOBALS.MOD"; ! Not recommended, but legal
ENDPROC
ENDMODULE
Saving Globals.mod will save new PERS values in the file, that can help if you P-Start the controller very often. But do not write to often on the flash-disk or you can damage it (so I've been told, even if it has never happend to me).
claudio2007-3-29 9:27:291 -
Can I load a module without an absolute path? Does it understand relative paths or environment variables?Actually full path gives meSystem1/RAPID/T_ROB1/Module1(280,14): String too long(141): The string LOAD is too long. 12/07/2019 2:51:29 PM General
Post edited by kschmid on0 -
I believe that the real problem lies in the parentheses.Lee Justice0
-
Would you recommend adding parentheses?
0 -
I am using windows syntax with backslashes (path has spaces as well) ... Not sure it matters?
RemoveDirWithContent("HOME:/Test");
Where does HOME point to or how do i set HOME ?This is interpreted as the path to the home directory of the current system.
0 -
Ah, folder below your system (in controller tab) ...Loading more than once is bad, can I check loaded?0
-
Yes, use ModExist.Lee Justice1
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 800 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings