Sepasoft MES Module Suite
Adding Sample Definitions for Tag Collectors
The following is an example script that creates a Sample Definition for each tag we wish to collect. In these examples the tag is both the sample definition and the attribute within that definition. In the final section of the script, the tag bindings are populated on the quality location's tag collector property.
Create Tag Sample Collectors
Python |
##where atts is a list of tag sample collector names. ##e.g. atts = ['motor 1 hz', 'motor 2 hz', 'motor 3 hz'] attList = atts.split(' ') for att in attList: print att ##create a sample definition named after the singular tag attribute with "tag_" prepended. definition_name = 'tag_' + att interval_name = 'Every Value Change' attribute_name = att location_path = 'Enterprise\Site 1\OEE Area\Sample Location' tagPath = location_path.replace('\', '/') + '/' + att # Properties that will be configured on that Tag. tagName = att valueSource = "memory" tagGroup = "Default" # Configure the tag. tag = { "name": tagName, "valueSource": valueSource, "tagGroup" : tagGroup } # Set the collision policy to Abort. Thus, if a Tag already exists at the base path, # we will not override the Tag. If you are overwriting an existing Tag, then set this to "o". collisionPolicy = "a" # Create the Tag. baseTagPath = "[default]Enterprise/Site 1/OEE Area/Sample Location" system.tag.configure(baseTagPath, [tag], collisionPolicy) # rule_name = 'c Nelson Rule 1' # limit_name = 'c LCL' # enterprise = system.mes.loadMESObjectByEquipmentPath('New Enterprise') # interval_prop = enterprise.getComplexProperty('Interval', interval_name) # if interval_prop is None: # raise Exception(interval_name + ' not found') # interval_uuid = interval_prop.getPropertyUUID() # rule_prop = enterprise.getComplexProperty('Rule', rule_name) # if rule_prop is None: # raise Exception(rule_name + ' not found') # rule_uuid = rule_prop.getPropertyUUID() # limit_prop = enterprise.getComplexProperty('ControlLimit', limit_name) # if limit_prop is None: # raise Exception(limit_name + ' not found') # limit_uuid = limit_prop.getPropertyUUID() try: sample_def = system.mes.loadMESObject(definition_name, 'SampleDefinition') print 'sample def already created', definition_name except: samp_def = system.mes.createMESObject('SampleDefinition') samp_def.setName(definition_name) # samp_def.setIntervalUUID(interval_uuid) samp_def.setInterval(interval_name) # NEW!! samp_def.setDefaultSampleSize(1) # defaults to 1 samp_def.setComingDueMinutes(0.0) # defaults to 0.0 samp_def.setOverdueMinutes(0.0) # defaults to 0.0 samp_def.setIntervalCount(0.0) samp_def.setIntervalDuration(0.0) samp_def.setAutoApprove(True) # defaults to false #samp_def.addRule('C Nelson Rule 1') # NEW!! #samp_def.addLimit('c LCL') # NEW!! # samp_attr = samp_def.createComplexProperty('SampleAttribute', attribute_name) samp_attr = samp_def.addAttribute(attribute_name) samp_attr.setAttributeDataType('REAL') # Defaults to REAL - other options INTEGER, BOOLEAN, INSPECTED_COUNT, NONCONFORMING_COUNT, NONCONFORMITY_COUNT samp_attr.setSampleDefaultChart('INDIVIDUAL') # Defaults to NONE - other options XBAR_R, XBAR_S, INDIVIDUAL, MEDIAN, U, C, P, NP, HISTOGRAM, PARETO, CP, PP, PPM, ADT, BOX_AND_WHISKER, CPPP samp_attr.setFormat('#0.00') samp_attr.setOrder(0) # Defaults to 0 samp_attr.setSampleSize(1) # Defaults to 1 samp_attr.setSampleDefaultValue(0) # Defaults to None # samp_attr.setSampleMinValue(0) # Defaults to None # samp_attr.setSampleMaxValue(100) # Defaults to None samp_attr.setUnits('lbs') # Defaults to None samp_attr.setSampleDefaultWeight(1.0) # Defaults to 1.0 # location = system.mes.loadMESObjectByEquipmentPath(location_path) # location_uuid = location.getUUID() # samp_loc = samp_def.createComplexProperty('SampleLocation', location_uuid) samp_loc = samp_def.addLocation(location_path) # samp_loc.setLocationLink(system.mes.object.link.create(location)) # samp_loc.setIntervalUUID(interval_uuid) samp_loc.setInterval(interval_name) # NEW !! #samp_loc.setTag(tagPath) # Defaults to None samp_loc.setComingDueMinutes(0.0) # Defaults to 0.0 samp_loc.setOverdueMinutes(0.0) # Defaults to 0.0 samp_loc.setIntervalCount(0.0) # Defaults to 0.0 samp_loc.setIntervalDuration(0.0) # Defaults to 0.0 samp_loc.setAutoApprove(True) # Defaults to False # samp_rule = samp_def.createComplexProperty('SampleRule', rule_name) # samp_rule.setSPCRuleUUID(rule_uuid) # samp_limit = samp_def.createComplexProperty('SampleLimit', limit_name) # samp_limit.setLimitKindUUID(limit_uuid) system.mes.saveMESObject(samp_def) print 'created new sample definition', samp_def location = system.mes.loadMESObjectByEquipmentPath(location_path) array = location.getComplexPropertyItemNames('TagCollector') for item in array: cp = location.getComplexProperty('TagCollector', item) collectorName = 'Sample Attribute-%s-%s' % (definition_name, att) if item == collectorName: print 'set the tag path' cp.setTagPath(tagPath) system.mes.saveMESObject(location) break |
Sepasoft MES Module Suite