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

    Not able to write a global variable to an file with echo command

    Scheduled Pinned Locked Moved Solved
    Gcode meta commands
    2
    6
    362
    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.
    • Exerqtorundefined
      Exerqtor
      last edited by

      I'm trying to get an current global value writen to an .g file for restore purposes with an echo command.

      But either i'm getting the construct wrong, or SOMETHING, because it won't write the actual varriable.

      The macro is as following:

      ; /macros/Toggle Chamber Lights  v2.0
      ; Used to toggle build camber LEDs on / off
      
      ; Save the current sb_leds status
      if exists(global.sb_leds)
        if global.sb_leds = "n-off"
          ; do nothing
        elif global.sb_leds = "n-on"
          ; do nothing
        else
          echo >"/sys/lib/led/sb_leds-restore.g" "; sb_leds status value to restore"          ; create/overwrite file
          echo >>"/sys/lib/led/sb_leds-restore.g" "set global.sb_leds = {global.sb_leds}"      ; save the current sb_leds status
      
      ; Check if the LEDs are on or off, and act accordingly
      if global.sb_leds = "n-off"
        M98 P"/sys/lib/led/sb_leds-restore.g"                                        ; restore the sb_leds status from before they got manually turned off
      
      elif global.sb_leds = "n-on"
        set global.sb_leds = "n-off"
        set global.sb_nozzle = "off"
      
      else
        set global.sb_leds    = "n-on"
        set global.sb_nozzle = "on"
      

      When i run that macro without global.sb_leds being either "n-off" or "n-on" it does create or rewrite /sys/lib/led/sb_leds-restore.g as expected, BUT it dosn't input the current global.sb_leds value. It just returns the exact line as stated in the echo command:

      ; sb_leds status value to restore
      set global.sb_leds = {global.sb_leds}
      
      

      Is this the intended behaviour, or have i stumbled upon a bug?

      RRF / DWC 3.4.2rc1

      Exerqtorundefined 1 Reply Last reply Reply Quote 0
      • Exerqtorundefined
        Exerqtor @Exerqtor
        last edited by Exerqtor

        @exerqtor

        Ok, i've gotten somewhat closer to the result i want. But still not there.

        For instance if global.sb_leds = "ready" when i run the command, i want the line written to /sys/lib/led/sb_leds-status.g to be: set global.sb_leds = "ready".

        What i've achived so far is to get ready, but it leaves out the quotation marks and it writes set global.sb_leds = ready.

        The code i run to yield the results mentioned above:

        ; /macros/Toggle Chamber Lights  v2.0
        ; Used to toggle build camber LEDs on / off
        
        ; Save the current sb_leds status
        if exists(global.sb_leds)
          if global.sb_leds = "n-off"
            ; do nothing
          elif global.sb_leds = "n-on"
            ; do nothing
          else
            echo >"/sys/lib/led/sb_leds-restore.g" "; sb_leds status value to restore"           ; create/overwrite file
            echo >>"/sys/lib/led/sb_leds-restore.g" "set global.sb_leds = "^global.sb_leds^""    ; save the current sb_leds status
        
        ; Check if the LEDs are on or off, and act accordingly
        if global.sb_leds = "n-off"
          M98 P"/sys/lib/led/sb_leds-restore.g"                                        ; restore the sb_leds status from before they got manually turned off
        
        elif global.sb_leds = "n-on"
          set global.sb_leds = "n-off"
          set global.sb_nozzle = "off"
        
        else
          set global.sb_leds    = "n-on"
          set global.sb_nozzle = "on"
        
        OwenDundefined 1 Reply Last reply Reply Quote 0
        • OwenDundefined
          OwenD @Exerqtor
          last edited by

          @exerqtor

          You have to quote the quotes 😀
          The best way to check is with echo in the console
          Try this

          echo "test " ^  """"^{global.myGlobal}^""""
          

          Then extend to

          echo >> "filename" "test " ^  """"^{global.MyGlobal}^""""
          
          Exerqtorundefined 1 Reply Last reply Reply Quote 1
          • Exerqtorundefined
            Exerqtor @OwenD
            last edited by

            @owend said in Not able to write a global variable to an file with echo command:

            @exerqtor

            You have to quote the quotes 😀
            The best way to check is with echo in the console
            Try this

            echo "test " ^  """"^{global.myGlobal}^""""
            

            Then extend to

            echo >> "filename" "test " ^  """"^{global.MyGlobal}^""""
            

            I feel like i've tried every possible variant of that too. It throws an error about expecting an expression each time! If you have an idea on exactly how that codeline should look please enligthen me!

            OwenDundefined 1 Reply Last reply Reply Quote 0
            • OwenDundefined
              OwenD @Exerqtor
              last edited by

              @exerqtor

              echo >>"/sys/lib/led/sb_leds-restore.g" "set global.sb_leds ="^ """"^{global.sb_leds}^""""
              
              Exerqtorundefined 1 Reply Last reply Reply Quote 1
              • Exerqtorundefined
                Exerqtor @OwenD
                last edited by

                @owend
                Yeah that sure worked! Looks corny with all those quotation marks. But what, ever it worked😁

                1 Reply Last reply Reply Quote 0
                • Exerqtorundefined Exerqtor marked this topic as a question
                • Exerqtorundefined Exerqtor has marked this topic as solved
                • First post
                  Last post
                Unless otherwise noted, all forum content is licensed under CC-BY-SA