Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: rhtuttle on December 09, 2017, 05:49:24 PM

Title: List of Mach4 error codes
Post by: rhtuttle on December 09, 2017, 05:49:24 PM
Can someone point me to a list of the error codes?  I'm getting a -2 as a return code and it doesn't match up with the api examples listed
Title: Re: List of Mach4 error codes
Post by: Chaoticone on December 09, 2017, 07:19:24 PM
Have a look at the mcErrorCheck.lua module in your modules directory.
Title: Re: List of Mach4 error codes
Post by: joeaverage on December 10, 2017, 02:42:31 AM
Hi,
kool, I never knew that was there.

I've made a Notepad document of them and put a copy in the Docs folder of Mach4 so that its ready to hand when coding.

Craig
Title: Re: List of Mach4 error codes
Post by: Chaoticone on December 10, 2017, 10:03:54 AM
Hey Craig, there is rarely a reason to need the list. The reason the module was added was to make it easier to check error codes. I did a post on that somewhere. Will see if I can find it.
Title: Re: List of Mach4 error codes
Post by: Chaoticone on December 10, 2017, 10:35:33 AM
I'm not 100% sure and can't check it right now but pretty sure I added the mcErrorCheck module to the hobby installer and also added the bit to load it to the default hobby screens screen load scripts as well as the default profiles load modules macro (so it can be used in mCodes) a while back. Anyway, the attached zip file has it all including an example macro of how it was meant to be used. Hope this helps.
Title: Re: List of Mach4 error codes
Post by: joeaverage on December 10, 2017, 11:14:59 AM
Hi,
sometimes when debugging if you hover over a return code it displays a number. Nice to be able to know what condition that number represents.

Craig
Title: Re: List of Mach4 error codes
Post by: Chaoticone on December 10, 2017, 02:13:22 PM
Yup, that would make the list handy.
Title: Re: List of Mach4 error codes
Post by: DazTheGas on December 10, 2017, 05:23:40 PM
The ErrorCheck Module is already loaded via the Screen Load Script so can be used globally during normal use, however from the debugger you dont have access to whats declared in the script so you will have to load the module perhaps by adding

if (mc.mcInEditor() == 1) then
-- load the package here
end

DazTheGas
Title: Re: List of Mach4 error codes
Post by: joeaverage on December 10, 2017, 05:33:45 PM
Hi Daz,
hadn't really considered using it in that manner, more as a reference so that if I get a return code from an API call
of -9 say, I can look it up to decide if remedial action is required.

Craig
Title: Re: List of Mach4 error codes
Post by: Chaoticone on December 10, 2017, 08:01:55 PM
The ErrorCheck Module is already loaded via the Screen Load Script so can be used globally during normal use

DazTheGas

Interesting Daz. I was definitely told different but never tested just loading in the screen load script or not that I remember testing at least. Do you know if it has always been this way? Was a while back when I was messing with it.
Title: Re: List of Mach4 error codes
Post by: DazTheGas on December 11, 2017, 03:47:55 AM
A little example, if you open up the screen editor and use the dummy button under the DRO`s and add the code

Code: [Select]
local rc = -3
wx.wxMessageBox(mcErrorCheck[rc])

This will give you the error of "attempt to index global 'mcErrorCheck' (a nil value)"
Now if you use

Code: [Select]
if (mc.mcInEditor() == 1) then
    dofile(mc.mcCntlGetMachDir(0).."\\Modules\\mcErrorCheck.lua") -- use F10 in the debugger for this line to step over it to save debugging the file.
end

local rc = -3
wx.wxMessageBox(mcErrorCheck[rc])

This will work fine, however it is advised you press F10 on the line indicated to save debugging the module too

DazTheGas
Title: Re: List of Mach4 error codes
Post by: Chaoticone on December 11, 2017, 05:56:14 AM
OK, I can see that. Thanks Daz.

What I was asking was this........

If your example code was in a macro (say m200) would it run if loading the error check module was only done once in the screen load script and not done in the load modules macro?

It was explained to me that adding the mcLoadModules macro to the macros folder would load the modules added by it into the chunk that all of the macros become, mcLua.mcc. making the contents of those loaded modules available to all macros in the macros folder. I took what you were saying to mean that if a module was loaded in the screen load script then loading it in the load modules macro would not be necessary because the contents of it would already be available to macros. If that is the case then something definitely changed.

I can test it (and I will) faster than ask about it once I'm back in the shop.
Title: Re: List of Mach4 error codes
Post by: DazTheGas on December 11, 2017, 06:08:41 AM
Simple answer no, when running macros`s they are using their own lua stack with bindings to the core api, the gui also has its own lua stack with bindings to the core api. This goes the same with the debugger, when opened it appears to also have its own lua stack connected to the core api. when loading modules, functions or tables etc they are loaded within the stack that called them and not accessible from another stack.

Does this make any sense, i`m losing myself  ;D ;D

DazTheGas
Title: Re: List of Mach4 error codes
Post by: Chaoticone on December 11, 2017, 07:04:37 AM
Ok, thanks Daz,

Yup, makes perfect sense and a very clear way of explaining it. It's that word "Global" that's a little misleading I think. Maybe we should call it Regionally Global.  ;D