241
Mach4 General Discussion / Re: add condition on Gcode
« on: January 05, 2021, 08:30:39 PM »
You can do it with an Mcode in hobby or use macro B in industrial .
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
function m8(hParam) --The param is a P value called from Gcode. M8P50 for example would be 50%, No value will be 100%.
local inst = mc.mcGetInstance()
local varP = 100.00 -- default is 100%
if (hParam ~= nil) then
local flagP, rc = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_P)
if (flagP == 1) then --Check that the flag has been set so we do not get an unexpected value for mc.SV_P
varP = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_P)
end
end
mc.mcCntlSetLastError(inst, string.format("P val == %.0f",varP))
local handle = 0;
handle = mc.mcRegGetHandle(inst,"0Regs0/test")-- TODO !!!!!!!!!!!!!!! Set Modbus register value here
if (handle ~= 0)then
local MaxVFDSpeed = 7000
local val = MaxVFDSpeed*varP/100
val = string.format("%.0f",tonumber(val))-- Get Val as an int
mc.mcRegSetValue(regH ,tonumber(val))-- Set the speed of the pump
end
handle = 0;
handle = mc.mcSignalGetHandle(inst, mc.OSIG_COOLANTON)
if (handle ~= 0)then
mc.mcSignalSetState(handle, 1)
end
end
if (mc.mcInEditor() == 1) then
m8()
end