Hello Guest it is March 29, 2024, 08:44:17 AM

Author Topic: Mach4 debugging Macros  (Read 397 times)

0 Members and 1 Guest are viewing this topic.

Mach4 debugging Macros
« on: May 24, 2023, 09:38:43 PM »
Hi,
I understand that, in theory, it's possible to remotely debug Mach4 Macros.  I have no problem setting up the debugging server for the UI - instructions at the end of the Mach4 Screen Editor manual, worked for me.  However, I'd like to be able to do the same with Macros.  Is this feasible? If it is, then what do I need to do?

I know that LUA does not have an intrinsic Error Handler, as it relies on the host API/OS to provide that service.  However, unless I'm missing a detail in a manual somewhere, Mach4 doesn't provide it either, so any error will typically result in the code halting, and usually without any helpful explanations or hints - which makes it hard to debug.  If the Macro is a relatively straightforward, and self contained in a single file, there doesn't seem to be a problem with error handling/reporting.  However it appears that, once you start requiring external modules from within the Macro - it stops giving tracebacks. I've overcome that by writing a very basic handler that wraps a function in a pcall (which does native Lua error capture, and doesn't ripple through to the main routine).

In case you're interested here's the code:

Code: [Select]
errorHandler = function(func)
local wrapper = function(...)
args ={...}
errorState, msg  = pcall(func, args)
if not errorState then
mc.mcCntlLog(inst, "Error: "..msg, "", -1)
-- add more handling code here
end
end
return wrapper
end

So if you have a Macro, say m900, this code snippet is used like this:

Code: [Select]
in file "m900.mcs"

function m900()
-- function body stuff goes here
end

-- add this at the end:
errorHandler = function.... --as above

m900 = errorHandler(m900)

Peter
Re: Mach4 debugging Macros
« Reply #1 on: May 25, 2023, 12:14:55 AM »
Hi,
is this an excerise in software development or is it to control a CNC machine?

Whatever Lua's strengths are, a software development language is not one of them.

Craig
'I enjoy sex at 73.....I live at 71 so its not too far to walk.'
Re: Mach4 debugging Macros
« Reply #2 on: May 25, 2023, 05:43:54 AM »
Hi Craig,

Believe me, I really, really don’t want this to be a development exercise, but because Mach4 is lacking in some fundamental debugging and error handling capabilities, it makes a simple job really hard.

My big issue is the macro editor/debug environment is fundamentally different to the live controller environment.  So, you can’t step through, even the simplest macro code and see and monitor what’s happening to the controller. You could do that in Mach3.

I believe that’s why you remotely debug the UI code - it allows you to step through your code in the real environment.  You can’t step through in the editor, even though it alludes to that capability, because things like the PLC and signal loops aren’t active.  I would like the same capability for Macros.

Peter