27
« on: November 14, 2020, 11:21:32 PM »
Sketch for MPG (2nd half)
---------------------------------------------------------------
-- The Pendant's Axis switch changed... Reconfigure appropriate settings in Mach4 and turn the Pendant LED ON/OFF
--This will process the Pendant's Axis Selection Switch
---------------------------------------------------------------
function PendantAxisChange()
--Variable prep first for handles
local hAxis_X --Position X on Pendant Switch
local hAxis_Y --Position Y on Pendant Switch
local hAxis_Z --Position Z on Pendant Switch
-- Chose one of these for position 4 ( and another for 5 and 6 if applicable)
local hAxis_UA --Use this with a 4, 5 or 6 axis pendant
local hAxis_VB --Use this with a 4, 5 or 6 axis pendant
local hAxis_WC --Use this with a 4, 5 or 6 axis pendant
local hAxis_OB0 --Use this with a 4, 5 or 6 axis pendant
local hAxis_OB1 --Use this with a 4, 5 or 6 axis pendant
local hAxis_OB2 --Use this with a 4, 5 or 6 axis pendant
local hAxis_OB3 --Use this with a 4, 5 or 6 axis pendant
local hAxis_OB4 --Use this with a 4, 5 or 6 axis pendant
local hAxis_OB5 --Use this with a 4, 5 or 6 axis pendant
--Variable prep for signal values, MAKE SURE YOU MATCH THE ONES IN HERE WITH THE ONES JUST ABOVE
local SelectAxis_X
local SelectAxis_Y
local SelectAxis_Z
-- Chose one of these for position 4 ( and another for 5 and 6 if applicable)
local SelectAxis_UA --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_VB --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_WC --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_OB0 --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_OB1 --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_OB2 --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_OB3 --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_OB4 --Use this with a 4, 5 or 6 axis pendant
local SelectAxis_OB5 --Use this with a 4, 5 or 6 axis pendant
hAxis_X, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0) --If you are not using INPUT0 for the Axis Selection Switch X, change the INPUT#!!!!
SelectAxis_X, rc = mc.mcSignalGetState(hAxis_X)
hAxis_Y, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT1) --If you are not using INPUT1 for the Axis Selection Switch Y, change the INPUT#!!!!
SelectAxis_Y, rc = mc.mcSignalGetState(hAxis_Y)
hAxis_Z, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT2) --If you are not using INPUT2 for the Axis Selection Switch Z, change the INPUT#!!!!
SelectAxis_Z, rc = mc.mcSignalGetState(hAxis_Z)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_UA, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3) --If you are not using INPUT3 for the Axis Selection Switch 4, change the INPUT#!!!!
-- SelectAxis_UA, rc = mc.mcSignalGetState(hAxis_UA)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_VB, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT4) --If you are not using INPUT4 for the Axis Selection Switch 5, change the INPUT#!!!!
-- SelectAxis_VB, rc = mc.mcSignalGetState(hAxis_VB)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_WC, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5) --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
-- SelectAxis_WC, rc = mc.mcSignalGetState(hAxis_WC)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_OB0, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5) --If you are not using INPUT5 for the Selection Switch 6, change the INPUT#!!!!
-- SelectAxis_OB0, rc = mc.mcSignalGetState(hAxis_OB0)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_OB1, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5) --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
-- SelectAxis_OB1, rc = mc.mcSignalGetState(hAxis_OB1)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_OB2, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5) --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
-- SelectAxis_OB2, rc = mc.mcSignalGetState(hAxis_OB2)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_OB3, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5) --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
-- SelectAxis_OB3, rc = mc.mcSignalGetState(hAxis_OB3)
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
-- hAxis_OB4, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT5) --If you are not using INPUT5 for the Axis Selection Switch 6, change the INPUT#!!!!
-- SelectAxis_OB4, rc = mc.mcSignalGetState(hAxis_OB4)
--I AM USING THIS ONE with Axis Selection Switch 4 to move axis OB5
-- Use this with a 4, 5 or 6 axis pendant RESERVED - NOT CURRENTLY IN USE
hAxis_OB5, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT3) --If you are not using INPUT3 for the Axis Selection Switch 4, change the INPUT#!!!!
SelectAxis_OB5, rc = mc.mcSignalGetState(hAxis_OB5)
--This is the Pendant's LED, and it will be ON when an axis is active on the Pendant's switch
local hLedForActivePendantAxis
hLedForActivePendantAxis, rc = mc.mcSignalGetHandle(inst, mc.OSIG_OUTPUT1)-- Pendant LED Port 3 Pin 1
--Now actual axis Selection Switch processing code
if (SelectAxis_X == 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_X) --Map the MPG to control the X Axis
mc.mcCntlSetLastError(inst, "Pendant Axis X Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_Y== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_Y) --Map the MPG to control the Y Axis
mc.mcCntlSetLastError(inst, "Pendant Axis Y Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_Z== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_Z) --Map the MPG to control the Z Axis
mc.mcCntlSetLastError(inst, "Pendant Axis Z Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
--Not all of these remaining elseif's will be used in your setup, but it is okay to leave them active.
elseif (SelectAxis_UA== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_UA) --Map the MPG to control the U/A Axis
mc.mcCntlSetLastError(inst, "Pendant Axis U/A Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_VB== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_VB) --Map the MPG to control the V/B Axis
mc.mcCntlSetLastError(inst, "Pendant Axis V/B Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_WC== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_WC) --Map the MPG to control the W/C Axis
mc.mcCntlSetLastError(inst, "Pendant Axis W/C Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_OB0== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB0) --Map the MPG to control the OB0 Axis
mc.mcCntlSetLastError(inst, "Pendant Axis OB0 Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_OB1== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB1) --Map the MPG to control the OB1 Axis
mc.mcCntlSetLastError(inst, "Pendant Axis OB1 Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_OB2== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB2) --Map the MPG to control the OB2 Axis
mc.mcCntlSetLastError(inst, "Pendant Axis OB2 Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_OB3== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB3) --Map the MPG to control the OB3 Axis
mc.mcCntlSetLastError(inst, "Pendant Axis OB3 Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_OB4== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB4) --Map the MPG to control the OB4 Axis
mc.mcCntlSetLastError(inst, "Pendant Axis OB4 Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
elseif (SelectAxis_OB5== 1) then
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, AxisNumber_OB5) --Map the MPG to control the OB5 Axis
mc.mcCntlSetLastError(inst, "Pendant Axis OB5 Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 1) --Turn the Pendant's LED ON to show an axis is active
else
--None of the Axis Switch inputs are active, so unmap the MPG from all axes (by assigning an invalid axis -1)
mc.mcMpgSetAxis(inst, MachMpgNumberForPendant, UnmapMPG ) --Unmap the MPG, so it won't control any axes
mc.mcCntlSetLastError(inst, "NO Pendant Axis Selected") --Show a message in the Screen Set
mc.mcSignalSetState(hLedForActivePendantAxis, 0) --Turn the Pendant's LED OFF to show no axis is active
end
end
--We will now call the three functions we made
--This is so the functions will be initalized to the current pendant values
--When the Screen is loaded by Mach4
PendantEStopChange()
PendantSpeedChange()
PendantAxisChange()