Conditional Gcode: Test if key exists?
-
I am attempting to make a filament load macro that detects the movement of a Duet magnetic filament monitor. Running into an issue as the "calibrated" key does not exist in the object model until a print is started.
It does not exist before print starts...
M409 K"sensors.filamentMonitors[0]" {"key":"sensors.filamentMonitors[0]","flags":"","result":{"configured":{"mmPerRev":25.80,"percentMax":150,"percentMin":50,"sampleDistance":6.0},"enabled":true,"type":"rotatingMagnet"}}
But after it does...
M409 K"sensors.filamentMonitors[0]" {"key":"sensors.filamentMonitors[0]","flags":"","result":{"calibrated":{"mmPerRev":27.17,"percentMax":106,"percentMin":85,"totalDistance":577.4},"configured":{"mmPerRev":25.80,"percentMax":150,"percentMin":50,"sampleDistance":6.0},"enabled":true,"type":"rotatingMagnet"}}
Before the print starts the key returns null...
M409 K"sensors.filamentMonitors[0].calibrated" {"key":"sensors.filamentMonitors[0].calibrated","flags":"","result":null}
But if I make a macro to test for null...
if sensors.filamentMonitors[0].calibrated = null echo true else echo false
This is returned to the console...
M98 P"0:/macros/test" Error: in file macro line 1 column 49: M98: cannot convert operands to same type
Should I not be comparing to null? Is there a different type?
-
Which firmware version are you running? My latest build gives this:
10/03/2020, 18:46:58 echo sensors.filamentMonitors[0].calibrated = null true
-
FIRMWARE_NAME: RepRapFirmware for Duet 2 WiFi/Ethernet FIRMWARE_VERSION: 3.01-RC3 ELECTRONICS: Duet Ethernet 1.02 or later FIRMWARE_DATE: 2020-02-29b4
-
If that same echo command doesn't work for you, then I guess it's fixed in the internal build ready for 3.01-RC4.
-
Confirmed does not work on RC3. Will postpone this project until RC4.
3/10/2020, 2:08:10 PM echo sensors.filamentMonitors[0].calibrated = null Error: cannot convert operands to same type
-
You can try the internal build at https://www.dropbox.com/sh/3azy1njy3ayjsbp/AACquxr2m00eV568RZg5QG5wa?dl=0 if you wish - at your own risk.
-
@mwolter said in Conditional Gcode: Test if key exists?:
echo sensors.filamentMonitors[0].calibrated = null
That works, thanks!