----------------------------------------------------------------------------- -- 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_xxx 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_xxx symbols are internally generated. local temp = {} local pmcvars = {} -- One local variable to conatain all pmc generated variables local hIo, hReg, hSig, rc -- Generated function for MachAPI. local function Read_Register(mInst, 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(mInst, 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(mInst, 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(mInst, 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 MachAPI. local function Read_Io(mInst, path) hIo = 0 rc = mc.MERROR_NOERROR hIo, rc = mc.mcIoGetHandle(mInst, path) if (rc == mc.MERROR_NOERROR) then local state = 0 state, rc = mc.mcIoGetState(hIo) if (rc == mc.MERROR_NOERROR) then return state end end return 0 end -- Generated function for MachAPI. local function Write_Io(mInst, path, v) hIo, rc = mc.mcIoGetHandle(mInst, path) if (rc == mc.MERROR_NOERROR) then mc.mcIoSetState(hIo, v) end end pmcvars.I_b_mcr = 0 local function Read_I_b_mcr() return pmcvars.I_b_mcr; end local function Write_I_b_mcr(x) pmcvars.I_b_mcr = x; end pmcvars.I_b_rung_top = 0 local function Read_I_b_rung_top() return pmcvars.I_b_rung_top; end local function Write_I_b_rung_top(x) pmcvars.I_b_rung_top = x; end pmcvars.I_d_scratch2 = 0 pmcvars.U_d_Areg = 0 -- Generated function for I/O read. local function Read_U_b_Yout() return Read_Io(0, "Sim0/Output1") end -- Generated function for I/O write. local function Write_U_b_Yout(v) Write_Io(0, "Sim0/Output1", v) end -- Generated function for I/O read. local function Read_U_b_Ynew() return Read_Io(0, "") end -- Generated function for I/O write. local function Write_U_b_Ynew(v) Write_Io(0, "", v) end -- Call this function to retrieve the PMC cycle time interval -- that you specified in the PmcEditor. function temp.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 temp.PlcCycle() Write_I_b_mcr(1) -- start rung 1 Write_I_b_rung_top(Read_I_b_mcr()) -- start series [ if(Read_I_b_rung_top() == 1) then pmcvars.U_d_Areg = Read_Register(0, "Sim0/test0") end -- ] finish series -- start rung 2 Write_I_b_rung_top(Read_I_b_mcr()) -- start series [ pmcvars.I_d_scratch2 = 1 if(pmcvars.U_d_Areg == pmcvars.I_d_scratch2) then else Write_I_b_rung_top(0) end if(Read_I_b_rung_top() == 1) then Write_U_b_Yout(1) end -- ] finish series -- start rung 3 Write_I_b_rung_top(Read_I_b_mcr()) -- start series [ pmcvars.I_d_scratch2 = 0 if(pmcvars.U_d_Areg == pmcvars.I_d_scratch2) then else Write_I_b_rung_top(0) end if(Read_I_b_rung_top() == 1) then Write_U_b_Ynew(0) end -- ] finish series end return temp