10
« on: November 17, 2016, 11:59:58 AM »
I did add the code to reference the input but then it toggled continuously as I held the key down. Besides that, I haven't change the PLC script any. I can't find anything in the PLC script that references any IO signals. I was under the impression that when the input changed states, this triggered the signal script to run, and then because the input changed states, the signal script called the signal library inside of the screen load script. I guess I'm just not understanding why I need code in the PLC and what code that is.
local inst = mc.mcGetInstance()
local rc = 0;
testcount = testcount + 1
machState, rc = mc.mcCntlGetState(inst);
local inCycle = mc.mcCntlIsInCycle(inst);
-------------------------------------------------------
-- Coroutine resume
-------------------------------------------------------
if (wait ~= nil) and (machState == 0) then --wait exist and state == idle
local state = coroutine.status(wait)
if state == "suspended" then --wait is suspended
coroutine.resume(wait)
end
end
-------------------------------------------------------
-- Cycle time label update
-------------------------------------------------------
--Requires a static text box named "CycleTime" on the screen
if (machEnabled == 1) then
local cycletime = mc.mcCntlGetRunTime(inst, time)
scr.SetProperty("CycleTime", "Label", SecondsToTime(cycletime))
end
-------------------------------------------------------
-- Set Height Offset Led
-------------------------------------------------------
local HOState = mc.mcCntlGetPoundVar(inst, 4008)
if (HOState == 49) then
scr.SetProperty("ledHOffset", "Value", "0")
else
scr.SetProperty("ledHOffset", "Value", "1")
end
-------------------------------------------------------
-- Set Spindle Ratio DRO
-------------------------------------------------------
local spinmotormax = scr.GetProperty('droSpinMotorMax', 'Value');
local rangemax = scr.GetProperty('droRangeMax', 'Value');
local ratio = (rangemax / spinmotormax);
scr.SetProperty('droRatio', 'Value', tostring(ratio));
-------------------------------------------------------
-- Set Feedback Ratio DRO Updated 5-30-16
-------------------------------------------------------
local range, rc = mc.mcSpindleGetCurrentRange(inst)
local fbratio, rc = mc.mcSpindleGetFeedbackRatio(inst, range)
scr.SetProperty('droFeedbackRatio', 'Value', tostring(fbratio))
-------------------------------------------------------
-- PLC First Run
-------------------------------------------------------
if (testcount == 1) then --Set Keyboard input startup state
local iReg = mc.mcIoGetHandle (inst, "Keyboard/Enable")
mc.mcIoSetState(iReg, 1) --Set register to 1 to ensure KeyboardInputsToggle function will do a disable.
KeyboardInputsToggle()
--scr.SetProperty('btnCycleStart', 'Label', 'Cycle Start\nGcode')
prb.LoadSettings()
---------------------------------------------------------------
-- Set Persistent DROs.
---------------------------------------------------------------
DROTable = {
[1000] = "droJogRate",
[1001] = "droSurfXPos",
[1002] = "droSurfYPos",
[1003] = "droSurfZPos",
[1004] = "droInCornerX",
[1005] = "droInCornerY",
[1006] = "droInCornerSpaceX",
[1007] = "droInCornerSpaceY",
[1008] = "droOutCornerX",
[1009] = "droOutCornerY",
[1010] = "droOutCornerSpaceX",
[1011] = "droOutCornerSpaceY",
[1012] = "droInCenterWidth",
[1013] = "droOutCenterWidth",
[1014] = "droOutCenterAppr",
[1015] = "droOutCenterZ",
[1016] = "droBoreDiam",
[1017] = "droBossDiam",
[1018] = "droBossApproach",
[1019] = "droBossZ",
[1020] = "droAngleXpos",
[1021] = "droAngleYInc",
[1022] = "droAngleXCenterX",
[1023] = "droAngleXCenterY",
[1024] = "droAngleYpos",
[1025] = "droAngleXInc",
[1026] = "droAngleYCenterX",
[1027] = "droAngleYCenterY",
[1028] = "droCalZ",
[1029] = "droGageX",
[1030] = "droGageY",
[1031] = "droGageZ",
[1032] = "droGageSafeZ",
[1033] = "droGageDiameter",
[1034] = "droEdgeFinder",
[1035] = "droGageBlock",
[1036] = "droGageBlockT"
}
-- ******************************************************************************************* --
-- _ _ _ __ __ _____ _ _ _____ _ _ _____ _ _ _ --
-- | | | | | | \ \ / / /\ | __ \ | \ | | |_ _| | \ | | / ____| | | | | | | --
-- | | | | | | \ \ /\ / / / \ | |__) | | \| | | | | \| | | | __ | | | | | | --
-- | | | | | | \ \/ \/ / / /\ \ | _ / | . ` | | | | . ` | | | |_ | | | | | | | --
-- |_| |_| |_| \ /\ / / ____ \ | | \ \ | |\ | _| |_ | |\ | | |__| | |_| |_| |_| --
-- (_) (_) (_) \/ \/ /_/ \_\ |_| \_\ |_| \_| |_____| |_| \_| \_____| (_) (_) (_) --
-- --
-- The following is a loop. As a rule of thumb loops should be avoided in the PLC Script. --
-- However, this loop only runs during the first run of the PLC script so it is acceptable. --
-- ******************************************************************************************* --
for name,number in pairs (DROTable) do -- for each paired name (key) and number (value) in the DRO table
local droName = (DROTable[name]) -- make the variable named droName equal the name from the table above
--wx.wxMessageBox (droName)
local val = mc.mcProfileGetString(inst, "PersistentDROs", (droName), "NotFound") -- Get the Value from the profile ini
if(val ~= "NotFound")then -- If the value is not equal to NotFound
scr.SetProperty((droName), "Value", val) -- Set the dros value to the value from the profile ini
end -- End the If statement
end -- End the For loop
---------------------------------------------------
end
-------------------------------------------------------
--if mc.mcSignalGetState (mc.mcSignalGetHandle (inst, mc.ISIG_INPUT63)) == 1 then
-- -- mcSignalWait(inst, ISIG_INPUT63, WAIT_MODE_Low, 0)
-- mc.mcCntlFeedHold (inst)
--else
-- -- Do something else
--end
--This is the last thing we do. So keep it at the end of the script!
machStateOld = machState;
machWasEnabled = machEnabled;