en:software:mdurosettacncsoftwaregcode:macro_programming:advanced_tips

Advanced Tips

G-code syntax does not provide subroutine forward declarations, therefore when the interpreter finds a subroutine call, it should check if the subroutine is defined in the file, and if it is not it looks for an external subprogram with the appropriate name.
This approach can take time if the file where the subroutine call is placed is long, but there are some tips to write a more efficient G-code:

  • When you call a subroutine by name, and you know that the subroutine is defined in an external subprogram add the extension/suffix to the call.
    This way the interpreter can skip looking for a subroutine with the same name defined inside the file.
    Example: G65 P“my_sub.ngc” instead of G65 P“my_sub”.
    Note that you can write G65 P“my_sub.ngc” even if you want to call an encrypted file like my_sub.ngx
  • When you call a subroutine by id, consider using a custom G code or M code instead.
    Indeed custom G and M codes cannot be defined inside the file where the call is placed and this way the interpreter can skip looking for a subroutine with the same id defined inside the file.
    Example: G200 instead of G65 P200 and name the external file G200.ngc instead of O200.ngc.
  • The interpreter stores in a sort of cache the position of subroutines after the first call until the file is closed. This should guarantee that the definition of a subroutine is searched only once per file.
  • Last modified: 2023/03/22 09:07
  • by 127.0.0.1