Data type of tag custom property

Hi,

When using scrip console to create a tag with custom properties, how do you set the datatype of the custom property?

It seems like if I pass a string as value the datatype automatically sets to unicode. And if I pass a number as value the datatype automatically sets to float. But what if I want it to be an integer?

It’s probably not important, I’d just like to know :slight_smile:

provider = '[SCADA]'
tagpath = provider+'test'
tagname = 'tag_prop_test'
tagtype = 'Float4'
enabled = True
ro = False
val = 999
	
tag = {}
tag.update(name = tagname)
tag.update(valueSource = 'memory')
tag.update(dataType = tagtype)
tag.update(enabled = True)
tag.update(readOnly = ro)
tag.update(value = val)
tag.update(Trend_Data = int(9)) # the custom parameter, typecasting doesn't seem to work?

print "Initial config                                   ", system.tag.configure(tagpath,[tag],'o'), tagpath, tagname

t1 = system.tag.readBlocking(tagpath+'/'+tagname+'.Trend_Data')[0].value
print "Read tag value and datatype                      ", t1, type(t1)

# get config -> change datatype of custom parameter -> write back the changed config.
# --> datatype still float idstead of int?

c1 = system.tag.getConfiguration(tagpath+'/'+tagname, 0)[0]

print "Read tag config value and datatype               ", c1['Trend_Data'], type(c1['Trend_Data'])

c1['Trend_Data'] = int(9)
#c1['Trend_Data'] = None # remove the custom parameter

print "Changed config value and datatype                ", c1['Trend_Data'], type(c1['Trend_Data'])

print "Write back changed config                        ", system.tag.configure(tagpath, c1, 'o')

t1 = system.tag.readBlocking(tagpath+'/'+tagname+'.Trend_Data')[0].value
print "Read updated tag value and datatype              ", t1, type(t1)

Thanks

1 Like

I am having a similar issue, but I cant seem to create a custom property as anything other than a string. In the below code both DesiredHigh and DesiredLow are created and set as type string…

## read tag configuration from tagPath
tag = system.tag.getConfiguration(value,False)[0]

if 'DesiredHigh' not in tag or 'DesiredLow' not in tag:
				
	## Find path to parent tag folder
	a = str(tag['path'])
	parentPath = a.rsplit('/',1)[0]
			
	## add custom properties to tag configuration
	tag['DesiredHigh']= 0.2
	tag['DesiredLow']= '0'
	
	## write modified tag configuration back to tag
	system.tag.configure(parentPath, tag,"m")

Post early morning brain fade I realised that casting the value being written to the custom property seems to work fine.

i.e.

tag[‘DesiredHigh’]= int(55)
tag[‘DesiredLow’]= int(66)

@jacob.mann
I still can’t seem to get it working.
I still get float as datatype even if I typecast it’s value.
I updated my test code. Could you try to see if the test code works in your script console?
Did you check the datatype of the custom parameters after you did the
system.tag.configure(parentPath, tag,"m")
to see if it’s still an int?

My test code gives me the following output

Initial config                                    [Good] [SCADA]test tag_prop_test
Read tag value and datatype                       9.0 <type 'float'>
Read tag config value and datatype                9.0 <type 'float'>
Changed config value and datatype                 9 <type 'int'>
Write back changed config                         [Good]
Read updated tag value and datatype               9.0 <type 'float'>

Note that the changed config shows value 9 and type int correctly, but when writing back the changed config to the tag the value and datatype remains 9.0 and float for some reason?

Thanks