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

    Sending Parameters to Python

    Scheduled Pinned Locked Moved
    Gcode meta commands
    2
    10
    422
    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.
    • pouryatorabiundefined
      pouryatorabi
      last edited by

      Hi,
      It seems the M commands doesn't support adding a param like "M1563 {var.Param}", So how can I send a var to the python side?

      chrishammundefined 1 Reply Last reply Reply Quote 0
      • chrishammundefined
        chrishamm administrators @pouryatorabi
        last edited by

        @pouryatorabi Do you want to implement your own M-code using Python in SBC mode? If yes, check this out: https://github.com/Duet3D/dsf-python/blob/main/examples/custom_m_codes.py

        Duet software engineer

        1 Reply Last reply Reply Quote 0
        • pouryatorabiundefined pouryatorabi marked this topic as a question
        • pouryatorabiundefined pouryatorabi marked this topic as a regular topic
        • pouryatorabiundefined
          pouryatorabi
          last edited by

          Hi,
          I have a bunch of custom M commands that I send to python from my duet. I have created a separate macro for each one so I call that macro instead of sending the M command it self. For example in my g code, if I want to send M1570, I have a separate macro that is called Read sensor and in that macro I have written M1570, so I just call:
          M98 P"/macros/ReadSensor"
          So, in my gcode, if I want to use another M command, I have to make another macro for that M command, otherwise I get into a lot of trouble, because duet runs the macros and M commands at the same time.
          My problem is that, if I want to send a variable to python side, I have to first send that variable to a macro and within that macro receive that var and send it to python, but M command doesn't support for example M1570 L{var.Parameter}, how can I then send that var?

          chrishammundefined 1 Reply Last reply Reply Quote 0
          • chrishammundefined
            chrishamm administrators @pouryatorabi
            last edited by

            @pouryatorabi If you are using v3.5 with the defaults for a code intercepting connection, expressions are automatically evaluated. If you're still on v3.4, consider upgrading, else you need to check in your plugin if the given parameter is an expression and then evaluate that parameter yourself using the EvaluateExpression command.

            Duet software engineer

            pouryatorabiundefined 1 Reply Last reply Reply Quote 0
            • pouryatorabiundefined
              pouryatorabi @chrishamm
              last edited by pouryatorabi

              @chrishamm
              So I have a macro and inside that I have:

              var Test = 0
              if exists(param.L)
              	set var.Test = param.L
              M1560 P{var.Test}
              

              so I call that macro with: M98 P"/macros/ReadSensor" L6
              But on the python side I receive:

              M1560 P{var.Test}
              

              not

              M1560 P6.
              
              chrishammundefined 1 Reply Last reply Reply Quote 0
              • chrishammundefined
                chrishamm administrators @pouryatorabi
                last edited by

                @pouryatorabi So what DSF version do you have? Please share the full macro, too.

                Duet software engineer

                pouryatorabiundefined 1 Reply Last reply Reply Quote 0
                • pouryatorabiundefined
                  pouryatorabi @chrishamm
                  last edited by

                  @chrishamm Can you tell me how to find the DSF Version? Also the code I have sent is actually my full macro:

                  var LayerNo= 0
                  if exists(param.L)
                  	set var.LayerNo = param.L
                  M1560 P{var.LayerNo}
                  

                  I just send the M1560 command with my current layer number to python side, that is the full macro.

                  chrishammundefined 1 Reply Last reply Reply Quote 0
                  • chrishammundefined
                    chrishamm administrators @pouryatorabi
                    last edited by

                    @pouryatorabi It can be checked on DWC in Settings -> Machine-Specific. See also https://docs.duet3d.com/User_manual/Machine_configuration/SBC_setup#update-firmware

                    Duet software engineer

                    pouryatorabiundefined 1 Reply Last reply Reply Quote 0
                    • pouryatorabiundefined
                      pouryatorabi @chrishamm
                      last edited by

                      @chrishamm
                      Board: Duet 3 MB6HC (MB6HC)
                      DSF Version: 3.4.6
                      Firmware: RepRapFirmware for Duet 3 MB6HC 3.4.6 (2023-07-21)

                      chrishammundefined 1 Reply Last reply Reply Quote 0
                      • chrishammundefined
                        chrishamm administrators @pouryatorabi
                        last edited by

                        @pouryatorabi Auto-evaluation of code parameters is only supported in version 3.5 or newer. I suggest you upgrade your machine or change the programming of your plugin to check if the parmater is an expression and if yes, evaluate it using the EvalauteExpression function DSF provides, else use the passed value.

                        Duet software engineer

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