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

[DSF Extension] Exec On MCode (was: Shutdown SBC)

Scheduled Pinned Locked Moved
DSF Development
22
117
9.5k
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.
  • undefined
    Greg_the_maker
    last edited by 19 Jan 2021, 11:44

    What is it i need to be looking for?

    1 Reply Last reply Reply Quote 0
    • undefined
      PCR @PCR
      last edited by 19 Jan 2021, 12:02

      @PCR said in [DSF Extension] Exec On MCode (was: Shutdown SBC):

      made a little videos how to install it. Mainly for my own reference later

      How to install and test

      How to make it as a systemservice

      Here you go

      1 Reply Last reply Reply Quote 0
      • undefined
        Greg_the_maker
        last edited by 19 Jan 2021, 12:12

        thank you 🙂

        1 Reply Last reply Reply Quote 0
        • undefined
          wilriker @Greg_the_maker
          last edited by 19 Jan 2021, 14:00

          @Greg_the_maker Thanks for pointing that out. I will point the download instructions towards the GitHub Releases page. For there it should be clear what is meant by renaming also.

          Manuel
          Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
          with probably always latest firmware/DWC (incl. betas or self-compiled)
          My Tool Collection

          1 Reply Last reply Reply Quote 1
          • undefined
            Greg_the_maker
            last edited by 21 Jan 2021, 10:42

            Is tehre a way to get terminal messages displayed in the console?

            For example I need to see a list of usb devices with lsusb, is it possible to have that list returned as an M117 message or similar?

            undefined 1 Reply Last reply 21 Jan 2021, 11:06 Reply Quote 0
            • undefined
              wilriker @Greg_the_maker
              last edited by 21 Jan 2021, 11:06

              @Greg_the_maker In theory this is possible. Right now successful execution will discard the application output and error in execution results in an error being sent to DCS what failed (e.g. file not found but still not the output of the application).

              I could add that but I am not sure how it will deal with line-breaks.

              Manuel
              Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
              with probably always latest firmware/DWC (incl. betas or self-compiled)
              My Tool Collection

              undefined 1 Reply Last reply 21 Jan 2021, 11:11 Reply Quote 0
              • undefined
                Greg_the_maker @wilriker
                last edited by 21 Jan 2021, 11:11

                @wilriker Ahh ok. was just a thought. would be a nice feature to have though 😉

                undefined 1 Reply Last reply 21 Jan 2021, 11:27 Reply Quote 0
                • undefined
                  wilriker @Greg_the_maker
                  last edited by wilriker 21 Jan 2021, 11:27

                  @Greg_the_maker I have to correct myself. In case of an error it will indeed return the output of stdout and stderr combined as an error message. But since we are in short-lived world things can be changed quickly and thus:

                  Release v5.1.2

                  This release adds a new flag -returnOutput to be able to send the collected output of a successful run back to DCS. Prior this was only the case if the execution of the command failed.
                  Note that this cannot be combined with -execAsync.

                  Download

                  As usual get it from GitHub Releases page.

                  Manuel
                  Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                  with probably always latest firmware/DWC (incl. betas or self-compiled)
                  My Tool Collection

                  undefined undefined 2 Replies Last reply 21 Jan 2021, 11:38 Reply Quote 4
                  • undefined
                    Greg_the_maker @wilriker
                    last edited by 21 Jan 2021, 11:38

                    @wilriker Fantastic! Works exactly as desired. Have my upvote!

                    1 Reply Last reply Reply Quote 0
                    • undefined
                      oozeBot @wilriker
                      last edited by 21 Jan 2021, 15:27

                      @wilriker Could you please provide a simple example of using the -returnOutput flag? Thanks

                      undefined 1 Reply Last reply 21 Jan 2021, 15:38 Reply Quote 0
                      • undefined
                        wilriker @oozeBot
                        last edited by wilriker 21 Jan 2021, 15:38

                        @oozeBot said in [DSF Extension] Exec On MCode (was: Shutdown SBC):

                        @wilriker Could you please provide a simple example of using the -returnOutput flag? Thanks

                        Simple example:

                        execonmode -mCode 7777 -command "whoami" -returnOutput
                        

                        will not just confirm successful completion of the command but as part of this return the output of whoami (that returns the user execonmcode is started as, so probably root) so you can see it e.g. in DWC.

                        Manuel
                        Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                        with probably always latest firmware/DWC (incl. betas or self-compiled)
                        My Tool Collection

                        undefined 2 Replies Last reply 21 Jan 2021, 15:54 Reply Quote 0
                        • undefined
                          oozeBot @wilriker
                          last edited by 21 Jan 2021, 15:54

                          @wilriker Thanks. So the return is echo'ed in DWC, correct? Could the return value be evaluated within conditional gCode?

                          undefined 1 Reply Last reply 21 Jan 2021, 23:25 Reply Quote 0
                          • undefined
                            garethky @oozeBot
                            last edited by garethky 21 Jan 2021, 23:25

                            @oozeBot said in [DSF Extension] Exec On MCode (was: Shutdown SBC):

                            @wilriker Thanks. So the return is echo'ed in DWC, correct? Could the return value be evaluated within conditional gCode?

                            I was thinking about this today. Currently there are no variables so there is nothing to write the result back to. (there is a result int from the last code but it can't contain other data types) I think we might have to wait for variables and then we could write the value back to a global.

                            When that happens... it should be possible to set up an MCode that stores and retrieves values from a file on the SD card. So we could do what M500 does but with key/value semantics of M409:

                            M7500 K"some.key" V"The value"
                            M7500 K"some.other.key" V0.05
                            

                            and then get them back in a global with:

                            M7500 K"some.key"
                            echo {global.M7500_value}    ; or whatever you want to name it!
                            

                            and stored on disk as JSON:

                            "some": {
                                "key": "The Value"
                                "other": {
                                    "key": 0.05
                                }
                            }
                            
                            1 Reply Last reply Reply Quote 1
                            • undefined
                              EMRosa
                              last edited by 31 Jan 2021, 16:58

                              Great work! This is incredibly useful and appreciated!

                              Is there a way to pass quotes through the -command argument?
                              For example:

                              execonmcode --command "sudo pkill -fx "blah, blah, blah"" -mCode 7720 -execAsync
                              

                              I've tried single quotes, escape characters, and changing it to an argument passed through the m-code command;

                              execonmcode --command "sudo pkill -fx %F" -mCode 7720 -execAsync
                              

                              and then tried from DWC:

                              M7720 F"python3 script.py"
                              

                              but the full argument gets lost. I foolishly tried double quotes and DSF crashed. haha.

                              Please, forgive my inexperience. There is probably a simple answer to this, but it seems to escape my googling ability.

                              undefined 2 Replies Last reply 31 Jan 2021, 18:35 Reply Quote 0
                              • undefined
                                wilriker @EMRosa
                                last edited by 31 Jan 2021, 18:35

                                @EMRosa Quick answer is: this is currently not implemented.
                                I'll think about adding it, though.

                                Manuel
                                Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                                with probably always latest firmware/DWC (incl. betas or self-compiled)
                                My Tool Collection

                                undefined 1 Reply Last reply 1 Feb 2021, 02:45 Reply Quote 0
                                • undefined
                                  ukwebb
                                  last edited by 31 Jan 2021, 23:07

                                  followed your video and got it installed and working in 5 minutes - superb work - thanks

                                  1 Reply Last reply Reply Quote 0
                                  • undefined
                                    EMRosa @wilriker
                                    last edited by 1 Feb 2021, 02:45

                                    @wilriker thanks for the quick reply! No worries; at least it wasn’t something related to my Linux-literacy (or lack thereof). Haha. Your work and efforts on this implementation are inspirational.

                                    1 Reply Last reply Reply Quote 0
                                    • undefined
                                      wilriker @EMRosa
                                      last edited by wilriker 2 Jan 2021, 15:28 1 Feb 2021, 15:26

                                      @EMRosa said in [DSF Extension] Exec On MCode (was: Shutdown SBC):

                                      I've tried single quotes, escape characters, and changing it to an argument passed through the m-code command;

                                      execonmcode --command "sudo pkill -fx %F" -mCode 7720 -execAsync
                                      

                                      I thought about this some more and actually the above should work. Though probably as you use -fx on pkill this has to match the full commandline, i.e. you also have to specify the path to python3, so you will probably need use the following command:

                                      M7720 F"/usr/bin/python3 script.py"
                                      

                                      EDIT: to find the full commandline while your script.py is running use

                                      $ pgrep -fa "python3 script.py"
                                      

                                      This should give you the PID as well as the full command-line of your process.

                                      Manuel
                                      Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                                      with probably always latest firmware/DWC (incl. betas or self-compiled)
                                      My Tool Collection

                                      1 Reply Last reply Reply Quote 0
                                      • undefined
                                        EMRosa
                                        last edited by 1 Feb 2021, 20:17

                                        Thanks so much for the assist! I’ll try that, but I was using the exact process as listed from

                                        ps -aux | grep python3

                                        This lists the process as “python3 location/to/script/script.py”.

                                        In my case, I was able to put the command line call in another python script and just call it that way. I just wasn’t sure if it would be helpful (or necessary) for execonmcode to be able to send quoted arguments. (Or more likely, if I was doing it wrong. Haha)

                                        I’ll let you know if adding the path to python helps.

                                        undefined 1 Reply Last reply 2 Feb 2021, 06:07 Reply Quote 0
                                        • undefined
                                          wilriker @EMRosa
                                          last edited by 2 Feb 2021, 06:07

                                          @EMRosa Since you are using pkill you need to use pgrep to find the required command line (it's the same binary that acts different based on which name it is called with but shares common features otherwise). ps is a different tool that uses (and prints) a different format usually dropping the path to the executable. I think there is a flag to ps to add it but I don't know that off-hand.

                                          Also quotes are not necessary for execonmcode. Quotes are a concept of shells (sh, bash, zsh, fish, etc.) to provide means to human users to provide command arguments containing spaces. If an application runs another application they usually can provide arguments containing spaces without the need for quotes.

                                          Manuel
                                          Duet 3 6HC (v0.6) with RPi 4B on a custom Cartesian
                                          with probably always latest firmware/DWC (incl. betas or self-compiled)
                                          My Tool Collection

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