----------------------------------------------------------------------------- -- 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 MultiplyExample = {} 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) local value if (path:find('AnalogInput/')) then local index = string.gsub(path, 'AnalogInput/', '') index = tonumber(index) value, rc = mc.mcAnalogInputRead(mInst, index) if (rc == mc.MERROR_NOERROR) then return value end elseif (path:find('AnalogOutput/')) then local index = string.gsub(path, 'AnalogOutput/', '') index = tonumber(index) value, rc = mc.mcAnalogOutputRead(mInst, index) if (rc == mc.MERROR_NOERROR) then return value end else hReg, rc = mc.mcRegGetHandle(mInst, path) if (rc == mc.MERROR_NOERROR) then value, rc = mc.mcRegGetValue(hReg) if (rc == mc.MERROR_NOERROR) then return value end end end return 0 end -- Generated function for MachAPI. local function Write_Register(mInst, path, value) if (path:find('AnalogOutput/')) then local index = string.gsub(path, 'AnalogOutput/', '') index = tonumber(index) rc = mc.mcAnalogOutputWrite(mInst, index, value) if (rc == mc.MERROR_NOERROR) then return end else 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 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 -- Generated function for MachAPI. local function JogStart(mInst, axis, dir) local type = 0 type, rc = mc.mcJogGetType(mInst, axis) if (rc == mc.MERROR_NOERROR) then if (type == 0) then -- velocity mc.mcJogVelocityStart(mInst, axis, dir) else -- incremental local inc = 0 inc, rc = mc.mcJogGetInc(mInst, axis) if (rc == mc.MERROR_NOERROR) then inc = inc * dir mc.mcJogIncStart(mInst, axis, inc) end end end end local function JogStop(mInst, axis) local type = 0 type, rc = mc.mcJogGetType(mInst, axis) if (rc == mc.MERROR_NOERROR) then if (type == 0) then -- velocity mc.mcJogVelocityStop(mInst, axis) end 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.U_d_temp = 0 pmcvars.I_d_scratch2 = 0 pmcvars.U_d_AADC0 = 0 -- Call this function to retrieve the PMC cycle time interval -- that you specified in the PmcEditor. function MultiplyExample.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 MultiplyExample.PlcCycle() Write_I_b_mcr(1) -- start rung 2 Write_I_b_rung_top(Read_I_b_mcr()) -- start series [ if(Read_I_b_rung_top() == 1) then pmcvars.U_d_AADC0 = Read_Register(0, "Arduino/ADC0") end -- ] finish series -- start rung 4 Write_I_b_rung_top(Read_I_b_mcr()) -- start series [ if(Read_I_b_rung_top() == 1) then pmcvars.U_d_temp = 0 end -- ] finish series -- start rung 6 Write_I_b_rung_top(Read_I_b_mcr()) -- start series [ if(Read_I_b_rung_top() == 1) then pmcvars.I_d_scratch2 = 42.8000 pmcvars.U_d_temp = pmcvars.U_d_AADC0 * pmcvars.I_d_scratch2 end -- ] finish series -- start rung 8 Write_I_b_rung_top(Read_I_b_mcr()) -- start series [ if(Read_I_b_rung_top() == 1) then Write_Register(0, "Arduino/DAC0", pmcvars.U_d_temp) end -- ] finish series end return MultiplyExample