290
« on: July 08, 2014, 08:13:11 AM »
How to pass a number to a function and get or set variables. Note: Your dro names have to be consistent to write to them, because I am using the concant feature to add the number to the dro's name. I have a read function in the PLC and a write function button
Lot of messing with, but now its just one line of code to add new ones in the future.
function SCR_getset(varnum)
local inst = mc.mcGetInstance();
local varvalue = 0;
varvalue = mc.mcCntlGetPoundVar(inst, varnum);
scr.SetProperty('drovar'..varnum, 'Value', tostring(varvalue)); --Concant dro&number
end
function GetVariablePoundDouble(varnum)
local inst = mc.mcGetInstance();
local varvalue = 0;
local val = 0;
varvalue = mc.mcProfileGetDouble(inst , 'drovar'..varnum , tostring(varnum), val);
mc.mcCntlSetPoundVar(inst, tonumber(varnum), varvalue);
end
function GetVariablePoundInt(varnum)
local inst = mc.mcGetInstance();
local varvalue = 0;
local val = 0;
varvalue = mc.mcProfileGetInt(inst , 'drovar'..varnum , tostring(varnum), val);
mc.mcCntlSetPoundVar(inst, tonumber(varnum), varvalue);
end
function SetVariablePoundDouble(varnum)
local inst = mc.mcGetInstance();
local varvalue = 0;
varvalue = mc.mcCntlGetPoundVar(inst, tonumber(varnum));
mc.mcProfileWriteDouble(inst ,'drovar'..varnum, tostring(varnum),varvalue);
end
function SetVariablePoundInt(varnum)
local inst = mc.mcGetInstance();
local varvalue = 0;
varvalue = mc.mcCntlGetPoundVar(inst, tonumber(varnum));
mc.mcProfileWriteInt(inst ,'drovar'..tostring(varnum),tostring(varnum),varvalue);
end
function GetPoundDroVariables()
SCR_getset(1); --pass number to function
SCR_getset(3901);
end
function VariableRead()
GetVariablePoundDouble(1);
GetVariablePoundInt(3901);
end
function VariableWrite()
SetVariablePoundDouble(1);
SetVariablePoundInt(3901);
end