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

    File exists check

    Scheduled Pinned Locked Moved
    Firmware wishlist
    5
    13
    637
    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

      It would be good if we could get the result of whether a file exists in G Code.
      For example could M36 be changed to return an error code 1 or 2 if the file isn't found?
      At present it returns the error state as part of the JSON response but returns and error state of zero even if the file isn't found.

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

        I've added this to the work list.

        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

        DonStaufferundefined mherundefined 2 Replies Last reply Reply Quote 0
        • DonStaufferundefined
          DonStauffer @dc42
          last edited by

          @dc42 Has it been decided what firmware version this will be in? Thanks!

          Phaedruxundefined 1 Reply Last reply Reply Quote 0
          • Phaedruxundefined
            Phaedrux Moderator @DonStauffer
            last edited by

            @donstauffer I believe it will be in 3.3

            exists name -> bool Yields true if 'name' is a valid variable or object model element name and is not null (available in RRF 3.3beta3 and later). Especially useful for testing whether a particular parameter has been provided when a file macro was called.

            https://duet3d.dozuki.com/Wiki/GCode_Meta_Commands#Section_Functions

            Z-Bot CoreXY Build | Thingiverse Profile

            DonStaufferundefined 1 Reply Last reply Reply Quote 0
            • DonStaufferundefined
              DonStauffer @Phaedrux
              last edited by

              @phaedrux This is about files, not variables.

              Phaedruxundefined 1 Reply Last reply Reply Quote 0
              • Phaedruxundefined
                Phaedrux Moderator @DonStauffer
                last edited by

                @donstauffer ah, my mistake.

                Z-Bot CoreXY Build | Thingiverse Profile

                DonStaufferundefined 1 Reply Last reply Reply Quote 0
                • DonStaufferundefined
                  DonStauffer @Phaedrux
                  last edited by DonStauffer

                  @phaedrux I found a very awkward workaround: M471 is the only code I know of which returns a result that tells you something about the existence of a file. Unfortunately, it does that when potentially deleting the file in question. I didn't want that, so I had to set up a system of dummy "semaphor" files created in parallel with the file I was interested in, which fortunately my macros created, so it could keep the semaphors consistent with the actual file status.

                  But all that turned what would have been about a half page of code with a file exists capability into about 2 pages.

                  1 Reply Last reply Reply Quote 1
                  • Phaedruxundefined
                    Phaedrux Moderator
                    last edited by

                    @dc42 would have to comment on whether it's been implemented yet for sure.

                    Z-Bot CoreXY Build | Thingiverse Profile

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

                      As a work around you can use M38.

                      M38: Compute SHA1 hash of target file

                      Example:

                      M38 gcodes/myfile.g
                      

                      Used to compute a hash of a file on the SD card and returns a hexadecimal string which is the SHA1 of the file. If the file cannot be found, then the string "Cannot find file" is returned instead.

                      DonStaufferundefined 1 Reply Last reply Reply Quote 1
                      • DonStaufferundefined
                        DonStauffer @OwenD
                        last edited by DonStauffer

                        @owend How can my GCode use the string returned by M38? For example, how could I use it in a conditional? How do I suppress the spurious error message which displays in the console and as a pop-up in the web interface?

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

                          @donstauffer
                          You can't suppress the error message.
                          You don't exactly use the string. It's more a case of checking the result.
                          A result code of zero means I it's found and RRF was able to create a hash.
                          A result of 2 means the files wasn't found.
                          A result of 1 means the call to M38 returned a warning but I'm not sure of what conditions might return that result.

                          It's not very elegant but it's the best we have for now.

                          M38 "gcodes/my file.g"
                          if result = 2
                                echo "file not found"
                          elif result  = 1
                              echo "M38 call failed"
                          elif result = 0
                              echo "file exists"
                          
                          1 Reply Last reply Reply Quote 0
                          • mherundefined
                            mher @dc42
                            last edited by

                            @dc42 Is there any news about this. It would be really nice to check if a file exists or not.

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

                              @mher a new function fileexists(name) is already implemented in the RRF 3.5 source code.

                              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

                              1 Reply Last reply Reply Quote 2
                              • First post
                                Last post
                              Unless otherwise noted, all forum content is licensed under CC-BY-SA