topic_solved Global variables not updated if macro running
As part of my filament change macros I have a loop which displays am M291 panel showing the current and target temperatures.
This was done purely so that the operator knew that they had to wait.
However, there are no non blocking M291 options that contain a cancel button, which meant that the only way out was to E stop it.
On one occasion while testing, I had a syntax error which required me to E stop it and this corrupted the partition record my SD card. (not a total disaster as I have backups)
In an effort to come up with a cancel option I tried sending M99 from the console, but this doesn't break the loop although the command is shown in the console.
Then I created a macro to run a loop and created a global variable which I check inside the loop.
However once the loop starts, the global isn't updated until the macro ends.
Here is a test macro
;loops for number of times passed as S parameter var count=0 ; initialise variable if !exists(param.S) set var.count = 20 else set var.count = param.S while iterations < var.count G4 P100 if global.Cancelled = true echo "should be cancelled" break G4 P500 echo "loop number : " ^ iterations + 1 ^ " : " ^ global.Cancelled G4 P500 if global.Cancelled = true abort "Macro/print cancelled"
Here is the output.
You can see the set global command is processed, but not updated between iterations 5 & 6
Sindarius last edited by
The only solution I have found for this was to write something like
set global.Cancelled = true
to the daemon.g file on a button press. but it requires you to clear out the daemon.g before executing another loop.
@sindarius please confirm that you are running RRF 3.3 stable. Are you running in standalone or SBC mode?
In my case
Board: Duet 2 WiFi (2WiFi)
Firmware: RepRapFirmware for Duet 2 WiFi/Ethernet 3.3 (2021-06-15)
Duet WiFi Server Version: 1.26
gloomyandy last edited by
@owend I may have misinterpreted the output but it looks like you started the macro from the console and then in the same console entered the set global command is that correct? If that is the case then I suspect that the input processor for the console will be sat waiting for the macro to complete before it reads your set global command (which is why the macro does not see the global change).
What you say sounds pretty much what's happening.
I'm only vaguely aware of the different inputs.
If I run the same macro as a print job, will it see a change in the global sent from the console.
In my original print job, it called a macro using M98
Does that then become a call from the console?
gloomyandy last edited by
@owend I think that if you run the macro as a print job then yes it should see a global variable changed in the console. In this case they will be using different input processors.
Yes, I have just tested it and you are correct. Thanks for your input
If I run it as a print job it sees the updated global and cancels.
Even if I have a print job that does nothing more than call my original macro it still works.
For good measure I called a macro from a print job where the macro changed the variable mid way through the loop and that also worked.
Marking this as solved, though perhaps some reference should be made in the documentation.