Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: joeaverage on January 28, 2017, 11:32:55 PM

Title: Stop/Reset scripts with and without Gcode
Post by: joeaverage on January 28, 2017, 11:32:55 PM
Hi All,
I've got myself tied up in knots. Over the last few days I've been helping Zuxztah to write code sufficient to control a VFD
over Modbus. Has been coming on pretty well but find myself out of my depth and the end.

Have got the Modbus link to work, have the scripts necessary for the CW and CCW buttons and associated spindle override to work.

The problem is how to stop the spindle under different conditions. From Gcode or MDI m5 works fine.

For the 'Stop' button I have the following:
Code: [Select]
Shutdown();
CycleStop();

For the 'Reset' button I have:
Code: [Select]
Shutdown();
local inst = mc.mcGetInstance()
mc.mcCntlReset(inst)
--mc.mcSpindleSetDirection(inst, 0)
mc.mcCntlSetLastError(inst, 'diagReset')

And the two functions in the screen load script:
Code: [Select]
---------------------------------------------------------------
--  Spindle Shutdown
---------------------------------------------------------------
function Shutdown();
    local inst=mc.mcGetInstance();
    mc.mcCntlGcodeExecuteWait(inst,"m5");
end;
---------------------------------------------------------------
-- Cycle Stop function.
---------------------------------------------------------------
function CycleStop()
    mc.mcSpindleSetDirection(inst, 0);
    mc.mcCntlSetLastError("Cycle Stopped");
    mc.mcCntlCycleStop(inst);
end

---------------------------------------------------------------

When I click the Reset button it appears to work, namely it calls m5 and therefore stops the spindle executes the mc.mcCntlReset(inst) statement
and as a diagnostic feature displays mc.mcCntlSetLastError(inst, 'diagReset').

When I click the Stop button it executes m5 and stops the spindle and appears to execute mc.mcCntlCycleStop but never displays
mc.mcCntlSetLastError("Cycle Stopped");.

Worse however if I have a Gcode program running and either Stop or Reset buttons are clicked the spindle does not stop and Mach4 crashes.

What am I misunderstanding?

What does mc.mcCntlCycleStop actually do?

Craig
Title: Re: Stop/Reset scripts with and without Gcode
Post by: DazTheGas on January 29, 2017, 03:40:02 AM
mc.mcCntlSetLastError("Cycle Stopped")

Is there anything missing from this line that may cause it to not work ;-)

DazTheGas
Title: Re: Stop/Reset scripts with and without Gcode
Post by: dude1 on January 29, 2017, 04:07:52 AM
syntax is a pita
Title: Re: Stop/Reset scripts with and without Gcode
Post by: joeaverage on January 29, 2017, 04:50:37 AM
Hi Guys,
you're right, mc.mcCntlSetLastError() requires 'inst' as argument.

Other thing I found was:
mcScriptExecute() rather than mcCntrlGodeExecutWait() means that the m5 script does not have to compete with a running Gcode job.

Thanks again
Craig