I use a rotary knob on my panel to set the jog increments. And use Mach API function mcJogSetInc(). To find the current jog increment, use mcJogGetInc(). It is by axis, so to make all of the coordinated axes have the same jog increment, you have to do it for all of them. The GUI does this for you in its' default configuration. But if you want something different, then you have to do the legwork that the GUI does.
So, how would one track this? In the PLC script. LEDs can be driven by signals. One could grab some output signals that are not mapped to hardware outputs and use them for the purpose of driving LEDs. In the PLC script, use mcJogGetInc() to determine which increment is in use and drive the appropriate output signal. Say you have 3 LEDs to represent 3 different increments of .001, .01, and .1. At this point, you may want to put this function in the screen load script and call it from the PLC script.
-- this is in the screen load script.
currentInc = 0 -- global var to track the current increment.
function SetIncrementLeds()
local inst = mc.GetInstance()
-- track using OSIG_OUTPUT61, OSIG_OUTPUT62, and OSIG_OUTPUT63 (for .001, .001, and .1, respectively)
local hSig61 -- signal handle
local hSig62 -- signal handle
local hSig63 -- signal handle
local inc, rc = mc.mcJogGetInc(inst, mc.X_AXIS)
if (currentInc ~= inc) then -- the increment has changed, so light up the appropriate LED
currentInc = inc;
hSig61, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT61)
if (rc ~= mc.MERROR_NOERROR) then
-- Error condition.
mc.mcCntlSetLastError(inst, "Failed to get signal handle in SetIncrementLeds()!"
return;
end
hSig62, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT62)
if (rc ~= mc.MERROR_NOERROR) then
-- Error condition.
mc.mcCntlSetLastError(inst, "Failed to get signal handle in SetIncrementLeds()!"
return;
end
hSig63, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT63)
if (rc ~= mc.MERROR_NOERROR) then
-- Error condition.
mc.mcCntlSetLastError(inst, "Failed to get signal handle in SetIncrementLeds()!"
return;
end
-- No errors at this point, set all output signals to off.
mc.mcSignalSetState(hSig61, 0) -- check the return code for production code! This is an example.
mc.mcSignalSetState(hSig62, 0)
mc.mcSignalSetState(hSig63, 0)
if (inc == .001) then
mc.mcSignalSetState(hSig61, 1) -- .001 is current, turn on its' output signal.
elseif (inc == .01) then
mc.mcSignalSetState(hSig62, 1) -- .01 is current, turn on its' output signal.
elseif (inc == .1) then
mc.mcSignalSetState(hSig63, 1) -- .1 is current, turn on its' output signal.
end
end
end
function SetIncrement(incr)
for axis=0,5,1 do
mc.mcJogSetInc(inst, axis, incr) -- probably want to check the rc as well...
end
end
Put a line in the PLC script to update the LEDs
SetIncrementLeds() -- call the function that is in the screen load script
Then map output signals 61 to 63 to some LEDs.
Then put something like the following in some button up event scripts
SetIncrement(.001) -- Call the SetIncrement() function in the screen load script. .01 and .1 in other buttons.
That is all done without scr.Get/SetProperty(). AND it has the added benefit of working along side a panel knob. But also do realize that you also have the PMC to do all of this stuff in ladder logic as well. Both of these should be considered preferable to using the screen API stuff.
Steve