Modify a global variable value
-
Hello DSF experts,
I want to modify the value of a global variable using CommandConnection as follows:
pConn = CommandConnection() pConn.connect() pConn.lock_object_model() pConn.set_object_model("global.a_MachPos", "123") pConn.unlock_object_model()
However, the code doesn't change the value of the global variable a_MachPos. The code was based on the comments in
base_command_connectioon.py
fileIn the future, I want to be able to change the values of variables used inside jobs.
Thanks for you help.
-
@Falcounet can you provide some assistance?
-
@DDD I talked about it with @chrishamm and it turns out LockObjectModel / SetObjectModel / UnlockObjectModel as well as PatchObjectModel methods are reserved for use in non-SPI mode (which is not a common use of DSF).
I don't see a solution to alter a global variable from dsf_python for now. -
@DDD Actually, you can use
pConn.perform_simple_code("set global.var_name=value")
-
@Falcounet thanks for the help, will test it on Monday
-
@Falcounet said in Modify a global variable value:
@DDD Actually, you can use pConn.perform_simple_code("set global.var_name=value")
Is there a way to modify the variable value without using a gcode command?
I'm assuming that this command gets into the buffer to be executed. I'm looking for the fastest way to make this change.
-
-
@DDD You could also send a full code object with the IsPrioritized flag set. That flag ensures that the received code is executed as quickly as possible using an empty G-code input. The same mechanism is used for critical codes like M112 and M999.
The
async
flag may be interesting if you want to send updates as quickly as possible using a single command connection and if your app is not interested in the return value of the operation. -
@chrishamm @Falcounet Will OP's original ask be implemented in DSF-Python? We are not only interested in updated global variables directly, but other values within the ObjectModel as well. While a bit dangerous, allowing a way to directly interact with the ObjectModel could be extremely powerful.