Machsupport Forum
Mach Discussion => Mach4 General Discussion => Mach4 Toolbox => Topic started by: Calum on May 06, 2021, 11:58:39 PM
-
In Mach3 I use a macro to get tool diameter into the tool table before each T# M6. My post processor puts tool number and diameter into a line with the macro number and it looks like this M1000 P 01 R6.35. this has work well over the years but I'm moving to Mach4 and need to write a macro m1000 that will take the info and write it into the tool table but I haven't found how to read info from Gcode in Lua yet! can anyone help please?
Calum
-
Maybe this will help get you started:
--[[
Macro to set Z or X offset or tool description
example: m6061 z1.3333 d.250
--]]
function m6061(hParam)
if (hParam ~= nil) then
--mc.mcCntlSetLastError(inst, 'handle == ' .. tostring(hParam));
local inst = mc.mcGetInstance();
local zVal = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_Z)
local zFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_Z)
local xVal = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_X)
local xFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_X)
local dVal = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_D)
local dFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_D)
if(zFlag == 1)or(xFlag==1)or(dFlag==1) then
if zFlag==1 then
rc=mc.mcToolSetData(inst,mc.MTOOL_LATHE_Z,61,tonumber(zVal))
end
if xFlag==1 then
rc=mc.mcToolSetData(inst,mc.MTOOL_LATHE_X,61,tonumber(xVal))
end
if dFlag==1 then
rc=mc.mcToolSetDesc(inst,61,'Bit Diameter: '..tostring(dVal))
end
else if zFlag==1 then
mc.mcCntlSetLastError(inst, 'ERROR: Z, X or D value required with M6061');
mc.mcCntlEStop(inst);
end
end
else
mc.mcCntlSetLastError(inst, 'ERROR: handle == nil');
end
end
if (mc.mcInEditor() == 1) then
m6061()
e
-
Ok that looks promising, I’ll have a go on Monday when I’m back at the workshop. What is the mc.SV_?, I’m struggling to find anything that tells me all about Mach4 scripting and Lua.
-
The mc.SV_? correspond to the variables passed to the macro.
example: m6061 z1.3333 d.250
mc.SV_Z would contain 1.3333 and mc.SV_D would contain 0.250. Any labled character can contain a value and can be accessed within a macro by mc.SV_
Start with reading the scripting Manual.pdf in the docs directory and then examine the lua examples in the LuaExamples directory.
HTH
RT
-
Ok I think I’ve got that, mc.SV could be Mach core string variable or value and the letter is the identifier used to find the value in the string after the macro call.
Yes I do need to read those documents.
Thanks for your help.