Hello Guest it is October 04, 2023, 11:44:41 PM

Author Topic: how to use screen "CycleStop" in macro script  (Read 926 times)

0 Members and 1 Guest are viewing this topic.

how to use screen "CycleStop" in macro script
« on: October 12, 2019, 08:08:22 AM »
I have been running a dual table 5 axis router now for a few years on Mach4.  I have a macro that looks for an input signal from a PLC telling Mach if that table is ready to run.  the problem I am dealing with is the macro is a simple loop, looking at the Mach input controlled by the PLC and looping if it isn't on.  I need another way to get it out of the loop.  I wanted to use the screen button "Cycle Stop" but can't figure out how to "see" when it is pressed.  I built and coded the machine years ago, and am not a programmer, so sorry if this one is a simple solution.  My logic skills are good, my scripting/syntax skills need work!

Here is the working script:

local Yready = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT5);

         local ytable = mc.mcSignalGetState(Yready);         
   until ytable==1

here is what I want to add in red:

local Yready = mc.mcSignalGetHandle (inst, mc.ISIG_INPUT5);
local CycleStopScreen = not sure what goes here
         local ytable = mc.mcSignalGetState(Yready);
         local cyclestop = not sure what goes here         
   until ytable==1 or cyclestop==1

I am just not sure how to tag the screen button, or the function.  I have tried a couple ways but it hasn't been working.  Maybe I am approaching it all wrong as well.
I am sure I can add an output signal to the Cycle Stop function that I could then look at, but figure I have to be able to see that screen button being pushed since Mach recognizes it, so there must be something there to directly tag

Thanks in advance for any help.
Re: how to use screen "CycleStop" in macro script
« Reply #1 on: October 27, 2019, 12:34:24 AM »
One simple way is to create a global register.

To create a global register navigate to Configure>Plugins...>RegFile and select the global registers tab of the window that opened.

You can view all the current registers in your system by navigating to Diagnostic>RegFile

Then in the correct cycle start/stop button script, change the state of the register whenever the button is pressed. If the cycle start/stop button is a toggle button then set the register to 1 in down script and 0 in up script. The register will be global and can be accessed by the mScripts.

You can read or write registers like this:
Code: [Select]
local inst = mc.mcGetInstance()

local xG54 = mc.mcCntlGetPoundVar(inst, 5221)

local initialXG54Reg = mc.mcRegGetHandle(inst, "gRegs0/InitialXG54")
local priorXG54 = mc.mcRegGetValue(initialXG54Reg)

if xG54 ~= priorXG54 then
    mc.mcRegSetValue(initialXG54Reg, xG54)