PoKeys 57E analog pots. This is in the PLC script, last thing at the end of the file. The two .lua files I have in my Profiles directory so they get copied in with the profile when updating Mach4. They can be anywhere, just point the dofile to the right place.
-------------------------------------------------
--My Stuff!!
-------------------------------------------------
--Runs the PoKeys FRO and SRO lua files as shown!
dofile("C:\\Mach4Hobby\\Profiles\\ESS_New\\PoKeys_analog_FRO.lua")
dofile("C:\\Mach4Hobby\\Profiles\\ESS_New\\PoKeys_analog_SRO.lua")
---------------------------------------------------------------------------
FRO/RRO .lua file
--Function to read value from analog register
function ReadRegister(device, analogPin)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("%s/Analog input %s", device, analogPin))
return mc.mcRegGetValueString(hreg)
end
--Function to set FRO value
function SetFRO(analog)
local percent = analog/1*250 --calculate percentage from 0% to 250%
local inst = mc.mcGetInstance()
mc.mcCntlSetFRO(inst, percent)
mc.mcCntlSetRRO(inst, percent) --sets RRO 0% to 250% to follow FRO
end
--Main
local device = "PoKeys57" --Change this to the name of your PoKeys device
local analogPin = "45" --Analog input pin number
analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetFRO(analogVal) -- Set FRO value in %
-------------------------------------------------------------------------------
SRO .lua file
function ReadRegister(device, analogPin)
local inst = mc.mcGetInstance()
local hreg = mc.mcRegGetHandle(inst, string.format("%s/Analog input %s", device, analogPin))
return mc.mcRegGetValueString(hreg)
end
--Function to set SRO value
function SetSRO(analog)
local percent = analog/1*1.0+0.5 --calculate percentage
local inst = mc.mcGetInstance()
mc.mcSpindleSetOverride(inst, percent)
end
--Main body -
local device = "PoKeys57" --Change this to the name of your PoKeys device
local analogPin = "44" --Analog input pin number on PoKeys
analogVal = ReadRegister(device, analogPin) --Save analog register value in variable
SetSRO(analogVal) -- Set SRO value in %
I could upload the two .lua files if you'd prefer that!!
I've now made a notepad file to remind me two years from now how I did this!!!
Tom