I'm having an issue with using scripting to acquire a float value of percentages in a database and then creating tags using system.tag.configure() to assign that returned float value to the tag. I've tried "float", "float4", "Float", "Float4" and the integer format and it continues to create the type of the tag as integer regardless. I need it to be a float value.
This is a snip it of my code, the values being assigned are returned values of a query from a sql database that has the values stored as floats. I even tried force casting it as float using float(value) and that didn't help either.
Ignition 8.1.38
Code
# HitCount_Threshold_Warning Tag
HitCountThresholdPrimary = system.db.runScalarPrepQuery(getHitCountThresholdQuery, [machine_group, machine_name, subprocess])
hit_count_threshold_primary_tag = {
"name": "HitCount_Threshold_Warning",
"type": "Float4",
"value": float(HitCountThresholdPrimary),
"valueSource": "memory",
"tagType": "AtomicTag"
}
tags2.append(hit_count_threshold_primary_tag)
# HitCount_Threshold_SecondWarning Tag
HitCountThresholdSecondary = system.db.runScalarPrepQuery(getHitCountSecondaryQuery, [machine_group, machine_name, subprocess])
hit_count_threshold_secondary_tag = {
"name": "HitCount_Threshold_SecondWarning",
"type": "Float4",
"value": float(HitCountThresholdSecondary),
"valueSource": "memory",
"tagType": "AtomicTag"
}
tags2.append(hit_count_threshold_secondary_tag)
# Configure all tags at once
system.tag.configure(subprocess_folder_path, tags, "o")
system.tag.configure(subprocess_folder_path, tags2, "o")
"type" should be changed to "dataType"
Fixed Code:
# HitCount_Threshold_Warning Tag
HitCountThresholdPrimary = system.db.runScalarPrepQuery(getHitCountThresholdQuery, [machine_group, machine_name, subprocess])
hit_count_threshold_primary_tag = {
"name": "HitCount_Threshold_Warning",
"dataType": "Float4",
"value": float(HitCountThresholdPrimary),
"valueSource": "memory",
"tagType": "AtomicTag"
}
tags2.append(hit_count_threshold_primary_tag)
# HitCount_Threshold_SecondWarning Tag
HitCountThresholdSecondary = system.db.runScalarPrepQuery(getHitCountSecondaryQuery, [machine_group, machine_name, subprocess])
hit_count_threshold_secondary_tag = {
"name": "HitCount_Threshold_SecondWarning",
"dataType": "Float4",
"value": float(HitCountThresholdSecondary),
"valueSource": "memory",
"tagType": "AtomicTag"
}
tags2.append(hit_count_threshold_secondary_tag)
# Configure all tags at once
system.tag.configure(subprocess_folder_path, tags, "o")
system.tag.configure(subprocess_folder_path, tags2, "o")
1 Like
Noah_Casey:
# HitCount_Threshold_Warning Tag
HitCountThresholdPrimary = system.db.runScalarPrepQuery(getHitCountThresholdQuery, [machine_group, machine_name, subprocess])
hit_count_threshold_primary_tag = {
"name": "HitCount_Threshold_Warning",
"dataType": "Float4",
"value": float(HitCountThresholdPrimary),
"valueSource": "memory",
"tagType": "AtomicTag"
}
tags2.append(hit_count_threshold_primary_tag)
# HitCount_Threshold_SecondWarning Tag
HitCountThresholdSecondary = system.db.runScalarPrepQuery(getHitCountSecondaryQuery, [machine_group, machine_name, subprocess])
hit_count_threshold_secondary_tag = {
"name": "HitCount_Threshold_SecondWarning",
"dataType": "Float4",
"value": float(HitCountThresholdSecondary),
"valueSource": "memory",
"tagType": "AtomicTag"
}
tags2.append(hit_count_threshold_secondary_tag)
# Configure all tags at once
system.tag.configure(subprocess_folder_path, tags, "o")
system.tag.configure(subprocess_folder_path, tags2, "o")
Wow, crazy. I tried dataType before but I didn't capitalize the F on float when I did that.
Thank you!!!
1 Like