Accessing Numerical Codes
The numerical codes shown in the Lua API lists for
classes,
properties,
coding groups and
flag groups
in AspenTech Inmation can be accessed using Lua.
Examples are shown below.
Classes
See the Classes list in the Lua API.
Usage: syslib.model.classes.<class_name>
Example:
return syslib.model.classes.Node --returns 3813
-- OR
local T = syslib.model.classes
return T.Node--returns 3813
Properties
See the properties list in the Lua API.
Usage: syslib.model.properties.<property_name>
Example:
return syslib.model.properties.ObjectName -- returns 1
-- OR
local T = syslib.model.properties
return T.ObjectName --returns 1
| In the case of classes and properties , the values are loaded on demand so the properties will not be statically present in the table T if it is iterated. |
Coding Groups
See the Coding Groups list in the Lua API.
Usage: syslib.model.codes.<code_group_name>
Example:
return syslib.model.codes.SelectorGenItem.LUASCRIPT -- returns 5
-- OR
local T = syslib.model.codes.SelectorGenItem
return T.LUASCRIPT --returns 5
Code groups can also be referenced by their numerical code, see the example below.
return syslib.model.codes.SelectorGenItem[5] -- returns {"tag":"LUASCRIPT","meaning":"GenLuascript"}
-- OR
local T = syslib.model.codes.SelectorGenItem
return T[5] -- returns {"tag":"LUASCRIPT","meaning":"GenLuascript"}
Flag Groups
See the Flag Groups list in the Lua API.
Usage: syslib.model.flags.<flag_group_name>.<flag>
Returns the flag, as shown above returns the numeric flag value not the bit position.
Example:
return syslib.model.flags.ItemValueStorageStrategy.STORE_RAW_HISTORY -- returns 1
-- OR
local T = syslib.model.flags.ItemValueStorageStrategy
return T.STORE_RAW_HISTORY --returns 1
-- OR
syslib.model.flags.ModUserState.STATE_GOOD -- returns 1024
Flag groups can also be referenced by their numerical code.
return syslib.model.flags.PlcType[0x8000] -- returns {"tag":"PLC_TYPE_REMOTE", "meaning":"Plc Type Remote"}
-- OR
local T = syslib.model.flags.PlcType
return T[0x8000] -- returns {"tag":"PLC_TYPE_REMOTE", "meaning":"Plc Type Remote"}
The following code uses bitwise operations to compare the flag group value against the individual flag values to identify the set flags.
local flagValue = syslib.getvalue("/Guest Users.ProfileUserAccess")
--bitwise operations to identify flags
local resultText = ""
if ((flagValue & syslib.model.flags.ProfileUserAccessControl.USR_ACC_CTRL_OPC_DA) ~=0 ) then
resultText = resultText .. "DA, "
end
if ((flagValue & syslib.model.flags.ProfileUserAccessControl.USR_ACC_CTRL_OPC_HDA) ~=0 ) then
resultText = resultText .. "HDA, "
end
if ((flagValue & syslib.model.flags.ProfileUserAccessControl.USR_ACC_CTRL_OPC_AE) ~=0 ) then
resultText = resultText .. "AE, "
end
if ((flagValue & syslib.model.flags.ProfileUserAccessControl.USR_ACC_CTRL_OPC_UA) ~=0 ) then
resultText = resultText .. "UA"
end
return resultText
| In the case of coding and flag groups, the table T already has the values loaded and can be iterated to find all existing codes and flags. |
All information about classes, properties, codings and flags can be found on the respective Object Model Reference pages.