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

    Modify a global variable value

    Scheduled Pinned Locked Moved
    DSF Development
    5
    9
    550
    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.
    • DDDundefined
      DDD
      last edited by

      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 file

      In the future, I want to be able to change the values of variables used inside jobs.

      Thanks for you help.

      T3P3Tonyundefined Falcounetundefined 3 Replies Last reply Reply Quote 1
      • T3P3Tonyundefined
        T3P3Tony administrators @DDD
        last edited by

        @Falcounet can you provide some assistance?

        www.duet3d.com

        1 Reply Last reply Reply Quote 2
        • Falcounetundefined
          Falcounet @DDD
          last edited by

          @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.

          1 Reply Last reply Reply Quote 0
          • Falcounetundefined
            Falcounet @DDD
            last edited by Falcounet

            @DDD Actually, you can use pConn.perform_simple_code("set global.var_name=value")

            DDDundefined 2 Replies Last reply Reply Quote 2
            • DDDundefined
              DDD @Falcounet
              last edited by

              @Falcounet thanks for the help, will test it on Monday

              1 Reply Last reply Reply Quote 0
              • DDDundefined
                DDD @Falcounet
                last edited by

                @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.

                Falcounetundefined chrishammundefined 2 Replies Last reply Reply Quote 0
                • Falcounetundefined
                  Falcounet @DDD
                  last edited by Falcounet

                  @DDD See here for the arguments perform_simple_code can take.
                  You can set async_exec to True for the command being executed asynchronously but it probably won't make the command executed faster if it gets buffered.
                  Maybe specifiyng another CodeChannel eg CodeChannel.HTTP can fix that.

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

                    @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.

                    Duet software engineer

                    oozeBotundefined 1 Reply Last reply Reply Quote 0
                    • oozeBotundefined
                      oozeBot @chrishamm
                      last edited by

                      @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.

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