Well that was not as simple as I thought it was going to be, but still not bad.
Doing the code above will disable it, however if you hit the enable button it will start working again regardless of the VFD error input condition.
This will not allow allow the machine to be enabled as long as the VFD Alarm relay is open and gives a message so you know why.
SigLib = {
[mc.OSIG_MACHINE_ENABLED] = function (state)
-- Check to make sure there is not a VFD error occurring
if (state == 1) then
VFDErrCheck()
end
machEnabled = state;
ButtonEnable()
end,
-- Add VFD Alarm Input
[mc.ISIG_INPUT0] = function (state) -- VFD ALarm N.C. Relay Contacts
VFDErrCheck() --runs this if Input 0 state ever changes (no "if")
end,
-- Check if VFD Error is occurring before allowing Enable
function VFDErrCheck()
local hSig, rc = mc.mcSignalGetHandle(inst, mc.ISIG_INPUT0)
local sigState, rc = mc.mcSignalGetState(hSig)
if (sigState == 1) then
rc = mc.mcCntlEStop(inst)
rc = mc.mcCntlSetLastError(inst, "VFD Error - Machine Disabled")
end
end