keeping variables (global) after reset
-
Is there a way to keep variables even after reseting or turning off the board?
I don't want to re-set them in config.g or alike as I'd need them to be editable via G-Code.
I had something in mind like storing them in config override with M500 or alike.Using a Duet 3 mini with RRF 3.3
-
You might be able to use M28, M29 and M32.
M28 and M29 allow writing commands to a file on the SD card.
M32 allows executing that file.
It would be easy to test.
Frederick
-
But it might be nice to have some news commands to save/load variables.
Would being able to do all of them at once work for you?
Frederick
-
@fcwilt I'll try tomorrow!
And I suppose yes, if I don't need the variables they don't need to be in there.
-
Just tried
It works, but I suppose it does not make much sense as I (the user) would need to write them all sequentially. This is very likely to cause mistakes.
I guess it would make sense to have a M*** command that writes all currently set globals to a file variables.g (or alike) in sys, which could then be called while startup. This way you could simply change the value of one variable, and write them all back to the variables file if needed.
While writing I might try creating a file for every variable, but it's still a lot more complicated.
-
@benecito said in keeping variables (global) after reset:
Just tried
It works, but I suppose it does not make much sense as I (the user) would need to write them all sequentially. This is very likely to cause mistakes.
I guess it would make sense to have a M*** command that writes all currently set globals to a file variables.g (or alike) in sys, which could then be called while startup. This way you could simply change the value of one variable, and write them all back to the variables file if needed.
While writing I might try creating a file for every variable, but it's still a lot more complicated.
Glad to hear it works.
Why don't you post to the firmware wish list a suggestion to have the needed commands to save/load all global variables to file.
Frederick
-
@benecito Put your code setting the globals in a macro and call it from config.g. Then you can edit the file using GCode without messing with config.g itself. In config.g:
M98 P"/macros/setglobals"
Then, to change the globals, you'd have to rewrite the entire setglobals file, unless you had it, in turn, do calls to other files:
M28 "/macros/setglobals"
global var1=1
global var2=2
...
M29