This is the lua file i'm using here
-----------------------------------------------------------------------------
-- Name: PMC Module
--Created: 03/27/2015
-----------------------------------------------------------------------------
-- This is auto-generated code from PmcEditor. Do not edit this file! Go
-- back to the ladder diagram source for changes in the logic
-- U_********* symbols correspond to user-defined names. There is such a symbol
-- for every internal relay, variable, timer, and so on in the ladder
-- program. I_********* symbols are internally generated.
local VFD_Spindle_controller = {}
local hReg, hSig, rc
local mInst = 0
-- Generated function for MachAPI.
local function Read_Register(path)
hReg, rc = mc.mcRegGetHandle(mInst, path)
if (rc == mc.MERROR_NOERROR) then
local value, rc = mc.mcRegGetValue(hReg)
if (rc == mc.MERROR_NOERROR) then
return value
end
end
return 0
end
-- Generated function for MachAPI.
local function Write_Register(path, value)
hReg, rc = mc.mcRegGetHandle(mInst, path)
if (rc == mc.MERROR_NOERROR) then
rc = mc.mcRegSetValue(hReg, value)
if (rc == mc.MERROR_NOERROR) then
return
end
end
return
end
-- Generated function for MachAPI.
local function Read_Signal(path)
hSig = 0
rc = mc.MERROR_NOERROR
hSig, rc = mc.mcSignalGetHandle(mInst, path)
if (rc == mc.MERROR_NOERROR) then
local state = 0;
state, rc = mc.mcSignalGetState(hSig)
if (rc == mc.MERROR_NOERROR) then
return state
end
end
return 0
end
-- Generated function for MachAPI.
local function Write_Signal(path, v)
hSig = 0
rc = mc.MERROR_NOERROR
hSig, rc = mc.mcSignalGetHandle(mInst, path)
if (rc == mc.MERROR_NOERROR) then
mc.mcSignalSetState(hSig, v)
end
end
-- Generated function for signal read.
local function Read_U_b_FSpindle_CW()
return Read_Signal(1142)
end
-- Generated function for signal read.
local function Read_U_b_FSpindle_CCW()
return Read_Signal(1143)
end
-- Generated function for signal read.
local function Read_U_b_FSpindle_ON()
return Read_Signal(1141)
end
-- Call this function to retrieve the PMC cycle time interval
-- that you specified in the PmcEditor.
function VFD_Spindle_controller.GetCycleInterval()
return 10
end
-- Call this function once per PLC cycle. You are responsible for calling
-- it at the interval that you specified in the MCU configuration when you
-- generated this code. */
function VFD_Spindle_controller.PlcCycle()
mInst = mc.mcGetInstance()
if (Read_U_b_FSpindle_CCW() == 0 and Read_U_b_FSpindle_CW() == 1 and Read_U_b_FSpindle_ON() == 1) then
Write_Register("modbus0/wrtvfdcmd0", 1)
elseif (Read_U_b_FSpindle_CCW() == 1 and Read_U_b_FSpindle_CW() == 0 and Read_U_b_FSpindle_ON() == 1) then
Write_Register("modbus0/wrtvfdcmd0", 2)
else --if Read_U_b_FSpindle_ON() == 0) then
Write_Register("modbus0/wrtvfdcmd0", 5)
end
local spindle_rpm = scr.DroRead(mInst, 27)
Write_Register("modbus0/wrtvfdspeed0", spindle_rpm/12000*10000)
end
return VFD_Spindle_controller