Hello Guest it is April 25, 2024, 08:33:46 AM

Author Topic: lua in Mach 4  (Read 2022 times)

0 Members and 1 Guest are viewing this topic.

Re: lua in Mach 4
« Reply #20 on: August 19, 2022, 07:45:12 AM »
Did a bit more searching and I think these guys are going to do what I need once I get the usage through my thick skull. Me smart like tractor.

These next two functions are very helpful inside lua macros (scripts) since they will stop the machine if an error condition occurs (provided you check for and handle that error condition). Either of these functions will stop the execution of the GCode after the macro ends, but will not halt the execution of the macro itself. You will need to put "return" statements in after the calling of these functions, in order to halt the macro itself.
mcCntlMacroAlarm(...)
number: rc = mc.mcCntlMacroAlarm(number: inst, number: error_number, string: error_message)

mcCntlMacroStop(...)
    number: rc = mc.mcCntlMacroStop(number: inst, number: error_number, string: error_message)

I used mcCntlMacroStop in the example I gave you. It sounds like you were trying to use another API call where I put "some gcode string". In the script you posted, you created a gcode string using the string.format and assigned it to the variable Gcode and then use used it in this API call - mc.mcCntlGcodeExecuteWait(inst, GCode). It is here where you would check the return code as I showed in my example.
Re: lua in Mach 4
« Reply #21 on: August 22, 2022, 09:21:53 AM »
hey you know what would have been really handy is a link to this topic. pretty much what I have been struggling with so anyone following this for a solution try the one below. looks like it will do the trick. I learn best from examples.

https://www.machsupport.com/forum/index.php?topic=36577.msg251136#msg251136
Re: lua in Mach 4
« Reply #22 on: August 22, 2022, 01:47:00 PM »
That is just the same as the example I posted earlier in this thread, in fact the link you posted is sort of out of date now as there are better ways.  Oh well..