Problems running macros from the SD card

It appears the issue I am having relates to the Tools>SD card manager (v1.6.1) Whenever I do anything in the tool it throws the 60 error and shuts down the SLB. I find if I avoid the tool and only use the console it appears to read the card and shows all the contained macros. I have created a small macro to turn the rail leds on and off as follows

%TRIGGER=1
%TEMP=0
%TEMP=[global.RAIL] || 2
%VAR=([TEMP] <= [TRIGGER]) ? 2 : 0
%global.RAIL=[VAR]
M356 P0 Q[VAR]

Set to a macro button this codes works fine

M356 P0 Q2
[MSG:Info: Rail lights off]
ok

but if I save the same as “P105.macro” and save it to the SD card

it will not run.

[MSG:Warning: error 1 in macro P105.macro]
error:1 (G-code words consist of a letter and a value. Letter was not found.)

I have tried it with the M99 command and without, with the same result.

Does anyone spot what might be causing the error in the code?

@nifty I have moved your post to the gSender release thread for version 1.6.1. @KGN will be sure to see it here.

1 Like

You are conflating gSender macros with NGC macros, they share a name but are not the same thing.

Both share some similarities in that they are g-code with optional flow control and variables - how to express those variables are different.

For SD card macros (NGC expressions), I’d look at the following for a quick overview of how to add variables and flow control:

You’ve obviously found the gSender macro resources with the above snippet.

1 Like

Thanks Grant and Kevin. It has all been confusing for me, but it is starting to make sense now. I only did the gcode macro to test if the card was actually being read so not really an issue but nice to know it was my misunderstanding and not something with my setup. I ended up changing it to a single line of just gcode, moving X 10mm and that worked fine.

A NGC equivalent to your example would be as follows:

( P102.macro - grblHAL LED toggle macro)

(Initialize _led_state to 2 if it does not exist yet)
o100 if [EXISTS[#<_led_state>] EQ 0]
  #<_led_state> = 2
o100 endif

(Toggle: 2-state swap using arithmetic)
#<_led_state> = [2 - #<_led_state>]

M365 P0 Q[#<_led_state>]

This gives you the same result - if this was saved and uploaded as P102.macro, G65 P102 in the console would swap between the two states as in your original macro, with the benefit that it could be assigned to a e-stop macro button.

This obv. requires a grblHAL firmware version with NGC expressions compiled in and enabled.

1 Like

Thanks mate, I was about to challenge myself and try doing exactly that. I can think of a couple of things I would like to do along those lines with the EStop buttons.

Previously you taught me :-
If you’re running 5.0.5b you will not see .macro files with the default $F listing since that extension was added to the whitelist later. You should see .gcode files.

char const *const filetypes = {
“nc”,
“ncc”,
“ngc”,
“cnc”,
“gcode”,
“txt”,
“text”,
“tap”,
“”
};
Out of interest,
Does this mean these file types use NGC expressions also?
I assume they do not, but if not how are they utilised.
Is the purpose to generate a toolpath and run it directly from the sd sard.

I’d have to double check on the older version of the firmware but at least on the latest NGC expressions evaluate the same regardless of extension - I’d expect that to be consistent. Same snippet in a gcode file running using the regular SD card command over G65:

Again, it’s dependent on having a version of the firmware with the ability to evaluate expressions compiled in. For the SLB, this is is available (unsupported) on Github for 5.0.5B and we will be publicly releasing a more current firmware version for the SLB soon™

Running directly from the SD card is one use case - you could start a file, and entirely disconnect the host/computer and walk away and let the controller do its thing.

I think there’s also plenty of use cases for small, reusable chunks of code that require logic or looping. For example, you can pass arguments to the macro. Say you had a toolpath/macro that made a hole or w/e and wanted to array it - you could pass the number of times to repeat the toolpath to a macro and have it handle running it X times and moving the expected offset. It’s quite powerful.

A simpler example is our testing program for wear on the new 4x8 - we just setup a macro that moved the full length of a specific axis and had it loop X times.

A more complex example is our ATC system macros, which is 22 macros that call each other depending on configuration or action requested

1 Like

Thanks Kevin, I copied the code you gave me but it will not run for me. I haven’t had time to troubleshoot but I just did a straight copy and paste so I suspect the SLB firmware is too old and doesn’t support the expressions you used. From what I read in the link you provided, a lot has been added and dated after the version I have. I look forward to the new firmware.