534
« on: January 18, 2019, 03:57:20 AM »
The m3 macro is the perfect place to put this type of code for plasma. Basically, you want the m3 macro to light the torch and check that it is ok before proceeding, right?
I have flushed out the code a bit more. Notice the comments I put in there about the instance and the error checking.
function m3()
local inst = mc.mcGetInstance('Custom M3 macro'); -- always get the instance first
mc.mcCntlSetLastError(inst, "Dry Run feature test");
--INITIALIZE OSIG_OUTPUT0 (INTERNAL SIGNAL FOR DRY RUN BUTTON)
local hsig
local rc
hsig, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT0);
-- It is important to check the API return codes (rc).
-- You can handle errors gracefully.
if (rc ~= MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Could not get signal handle!");
mc.mcCntlCycleStop(inst); --end program *****
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
return
end
--READ THE STATE OF OSIG_OUTPUT0, SET buttonstate VARIABLE
local buttonstate
buttonstate, rc = mc.mcSignalGetState(hsig);
if (rc ~= MERROR_NOERROR) then
mc.mcCntlSetLastError(inst, "Could not get signal state!");
mc.mcCntlCycleStop(inst); --end program *****
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_OFF);
return
end
--Begin modified M3 for ARC OK signal detection
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_FWD);
--DRY RUN LOGIC SECTION
if (buttonstate == 0) then
mc.mcCntlSetLastError(inst, "Dry Run feature not activated, cutting will commence");
mc.mcCntlSetLastError(inst, "m3 waiting for Arc");
local returncode = mc.mcSignalWait(inst, mc.ISIG_INPUT62, mc.WAIT_MODE_HIGH,2);
if (returncode == mc.MERROR_TIMED_OUT) then
mc.mcCntlSetLastError(inst, "Arc does not respond");
mc.mcCntlCycleStop(inst); --end program *****
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_OFF);
else
mc.mcCntlSetLastError(inst, "m3 Arc OK");
end
else
mc.mcCntlSetLastError(inst, "Dry Run feature activated, torch will not fire");
end
end
if (mc.mcInEditor() == 1) then
m3();
end
Steve