Hello Guest it is March 28, 2024, 09:37:43 AM

Author Topic: Can someone check my code please?  (Read 734 times)

0 Members and 1 Guest are viewing this topic.

Can someone check my code please?
« on: January 12, 2021, 01:14:08 PM »
Apologies for this rather basic question, but I've just spent 3 days trying to get the Cycle START, Feed HOLD and Cycle STOP buttons working on my control panel, and only today realised that it needs some code written in the screen editor!
Thanks to a search on here I managed to get the buttons working (at least they seem to be) by adding the following:
Code: [Select]
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
    machEnabled = state;
    ButtonEnable()
end,

[mc.ISIG_INPUT0] = function (state)
   
end,

-- The following three blocks enable the buttons on the control panel to work
[mc.ISIG_INPUT0] = function (state)
    if (state == 1) then   
        CycleStart() --0 G Code executed when Cycle START button is pressed
    end

end,

[mc.ISIG_INPUT1] = function (state)
    if (state == 1) then   
        mc.mcCntlFeedHold(0) --Stepper motors stop when Feed HOLD button is pressed,
-- spindle remains running, code can be resumed from the same point
    end

end,

[mc.ISIG_INPUT2] = function (state)
    if (state == 1) then   
        CycleStop(0) -- Stepper motors and spindle are stopped, cycle is aborted
    end
end,
I'd be very grateful if someone could check that it is going to perform as it should, and in particular whether "then.. mc.mcCntlFeedHold(0)" and  "then.. CycleStop(0)" are the correct form to use for this. Many thanks. Steve.
Re: Can someone check my code please?
« Reply #1 on: January 13, 2021, 08:59:10 AM »
looks like it should work but the cycle stop is a bit risky. This is a legacy item from Mach3. Pressing feedhold then when the machine is stopped pressing reset is a much better way. The code looks okay, the only thing better you can do is to get the instance with mc.mcGetInstance() rather than passing a zero.
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com
Re: Can someone check my code please?
« Reply #2 on: January 13, 2021, 01:31:23 PM »
Thanks Brian. I'm afraid I'm very new to Mach4, and even newer to any sort of scripting or coding, so it has all been copied from others after a lot of reading and YouTube viewing!
When you say that a CycleStop is risky, is that because it is a bit of a shock to the machine/motors/ball screws? I can imagine in practice that if something goes wrong then the e-stop would be quicker and easier to go for with my setup.
I will have to read up on mc.mcGetInstance() as at the moment that means little to me. Time for some more forum searching I think.
Steve
Re: Can someone check my code please?
« Reply #3 on: January 13, 2021, 04:13:07 PM »
You don't need to do it it is just good practice...
If you have trouble post here. I am sure we can figure it out ;)
Fixing problems one post at a time ;)

www.newfangledsolutions.com
www.machsupport.com