Sending Parameters to Python
-
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? -
@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
-
-
-
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? -
@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. -
@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.
-
@pouryatorabi So what DSF version do you have? Please share the full macro, too.
-
@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.
-
@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
-
@chrishamm
Board: Duet 3 MB6HC (MB6HC)
DSF Version: 3.4.6
Firmware: RepRapFirmware for Duet 3 MB6HC 3.4.6 (2023-07-21) -
@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.