Hello Guest it is December 03, 2022, 08:05:12 PM

Author Topic: Getting tool info into tool table  (Read 767 times)

0 Members and 1 Guest are viewing this topic.

Offline Calum

*
  •  45 45
    • View Profile
Getting tool info into tool table
« 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
Re: Getting tool info into tool table
« Reply #1 on: May 07, 2021, 11:35:22 AM »
Maybe this will help get you started:

Code: [Select]
--[[
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

Offline Calum

*
  •  45 45
    • View Profile
Re: Getting tool info into tool table
« Reply #2 on: May 07, 2021, 05:13:58 PM »
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.
Re: Getting tool info into tool table
« Reply #3 on: May 07, 2021, 05:55:26 PM »
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

Offline Calum

*
  •  45 45
    • View Profile
Re: Getting tool info into tool table
« Reply #4 on: May 07, 2021, 06:12:45 PM »
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.