Hi Hakan,
I've been doing some testing and the code I've posted has lots of faults.
The first was my inclination to set up two global variables AtSpeed and IsStopped. They don't pass into the m3,m4 and m5 macros...don't quite understand why
at the moment. What I've done as a working alternative is in each macro get the signal handle and signal state and use that to control the wait loop.
Second issue is that if for whatever reason the spindle doesn't respond, in my case I'm using my laptop so clearly the signal will never go active, then the machine
hangs and will eventually crash.
What I did was set up a timeout variable in each macro which means that if the spindle doesn't respond after ten seconds or so the macro will end, report
an error rather than hang and crash out.
For m3
function m3();
local inst=mc.mcGetInstance();
local timeout=0;
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_FWD);
mc.mcCntlSetLastError(inst,"m3 waiting");
local hsig= mc.mcSignalGetHandle(inst,mc.ISIG_SPINDLE_AT_SPEED);
local AtSpeed=mc.mcSignalGetState(hsig);
while (AtSpeed~=1) do;
mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
timeout=timeout+1;
if (timeout>=10) then;
wx.wxMessageBox("Spindle does not respond");
break;
end;
end;
if (AtSpeed==1) then;
mc.mcCntlSetLastError(inst,"m3 at speed");
else;
mc.mcCntlSetLastError(inst,"spindle does not respond");
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
end;
end
if (mc.mcInEditor() == 1) then
m3()
end
For m4
function m4();
local inst=mc.mcGetInstance();
local timeout=0;
mc.mcSpindleSetDirection(inst, mc.MC_SPINDLE_REV);
mc.mcCntlSetLastError(inst,"m4 waiting");
local hsig= mc.mcSignalGetHandle(inst,mc.ISIG_SPINDLE_AT_SPEED);
local AtSpeed=mc.mcSignalGetState(hsig);
while (AtSpeed~=1) do;
mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
timeout=timeout+1;
if (timeout>=5) then;
wx.wxMessageBox("Spindle does not respond");
break;
end;
end;
if (AtSpeed==1) then;
mc.mcCntlSetLastError(inst,"m4 at speed");
else;
mc.mcCntlSetLastError(inst,"spindle does not respond");
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
end;
end
if (mc.mcInEditor() == 1) then
m4()
end
For m5
function m5();
local inst=mc.mcGetInstance();
local timeout=0;
mc.mcSpindleSetDirection(inst,mc.MC_SPINDLE_OFF);
mc.mcCntlSetLastError(inst,"m5 stopping");
local hsig=mc.mcSignalGetHandle(inst,mc.ISIG_SPINDLE_AT_ZERO);
local IsStopped=mc.mcSignalGetState(hsig);
while (IsStopped~=1) do;
mc.mcCntlGcodeExecuteWait(inst,"g4 p1000");
timeout=timeout+1;
if (timeout>=10) then;
wx.wxMessageBox("Spindle does not respond");
break;
end;
end;
if (IsStopped==1) then;
mc.mcCntlSetLastError(inst,"m5 Is Stopped");
else;
mc.mcCntlSetLastError(inst,"spindle does not respond");
end;
end
if (mc.mcInEditor() == 1) then
m5()
end
You can ignore the code added to the SigLib in the signal load script, I don't think it will effect m3,m4 or m5 but I deleted the extra SigLib entries to
be sure.
Craig