Duet3D Logo Duet3D
    • Tags
    • Documentation
    • Order
    • Register
    • Login

    M502 returns array index error

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    2
    3
    240
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • OwenDundefined
      OwenD
      last edited by OwenD

      Just noticed a curiosity.
      If I run
      M98 P"0:/sys/config.g"
      I get no errors.

      However if I run M502 I get n array index out of bounds error for this code
      Screenshot 2022-02-15 at 22-32-16 3Dprinter.jpg

      ;load config for filament
      if move.extruders[state.currentTool].filament=""
      	echo "No filament loaded.  Cold extrude & retract set to defaults"
      	M302 S190 R110 ; Allow extrusion starting from 190°C and retractions already from 110°C (defaults)
      	set global.LoadedFilament="No_Filament"
      else
      	set global.LoadedFilament=move.extruders[state.currentTool].filament ; set the variable to the currently loaded filament
      	echo "Loading config for " ^ global.LoadedFilament ^ " filament"
      	M703 ; if a filament is loaded, set all the heats and speeds for it by loading config.g
      G4 P10
      
      

      Attached is the complete config.g

      It's not really causing me a problem, but I can't figure out why the results differ.
      If I put an echo command it resolves correctly.

      config.g

      dc42undefined 1 Reply Last reply Reply Quote 0
      • dc42undefined
        dc42 administrators @OwenD
        last edited by

        @owend when M502 is run, T commands in config.g are not executed. I expect this causes state.currentTool to be -1 in the code you posted.

        Duet WiFi hardware designer and firmware engineer
        Please do not ask me for Duet support via PM or email, use the forum
        http://www.escher3d.com, https://miscsolutions.wordpress.com

        OwenDundefined 1 Reply Last reply Reply Quote 0
        • OwenDundefined
          OwenD @dc42
          last edited by OwenD

          @dc42
          That's what I initially thought, but if I put
          echo state.currentTool on the line above it returns 0
          Yet if I hard code the extruder object to zero it stops complaining, so it must be -1 somewhere in code/memory

          I'll mark as solved with a 🤷

          EDIT: 10 seconds after I posted it hit me.
          It's because the heater was turned off using M568 A0
          This has the effect of the tool index being -1 despite T0 being selected

          1 Reply Last reply Reply Quote 0
          • OwenDundefined OwenD has marked this topic as solved
          • First post
            Last post
          Unless otherwise noted, all forum content is licensed under CC-BY-SA