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]"

    But after it does...

    M409 K"sensors.filamentMonitors[0]"

    Before the print starts the key returns null...

    M409 K"sensors.filamentMonitors[0].calibrated"

    But if I make a macro to test for null...

    if sensors.filamentMonitors[0].calibrated = null
    	echo true
    	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?

  • administrators

    Which firmware version are you running? My latest build gives this:

    10/03/2020, 18:46:58 	echo sensors.filamentMonitors[0].calibrated = null

  • @dc42

    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

  • administrators

    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

  • administrators

    You can try the internal build at 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!

Log in to reply