Hi,
I would like to know if there is a simple way to increment a tag ID. I am trying to read the value of different tags to create a dataset then, I want to put it in a table.
headers = [“Status”, “Permissive”]
blankHeader = []
blankData = []
data = []
i = 0
system.gui.getParentWindow(event).getComponentForPath(‘Root Container.Table’).data = system.dataset.toDataSet(blankHeader, blankData)
nb_lignes = system.tag.read(“PLC_DepocheusePolymere/Conv Alim Concasseur/Permissives/ConvAlimConcasseur_PermissiveAbs_INT”)
while ( i < nb_lignes.value ) :
dataColonne1 = system.tag.read(“PLC_DepocheusePolymere/Conv Alim Concasseur/Permissives/Absolute**[i]**”)
dataColonne2 = system.tag.read(“PLC_DepocheusePolymere/Conv Alim Concasseur/Permissives/HMI_PermissiveAbs_ConvAlimConcasseur_i_”)
data.append([dataColonne1.value, dataColonne2.value])
i = i + 1
system.gui.getParentWindow(event).getComponentForPath(‘Root Container.Table’).data = system.dataset.toDataSet(headers, data)
Is there a simple way to do it?
Thanks a lots
Hi!
As a side note, if you enclose your code with three back-quotes before and after, it makes thing a bit easier to read.
You pretty well hit on the simple way of doing it, but if there are many tags it may not be the most efficient way.
A couple of other differences you may notice:
- since all the tags are in the same folder, a path variable can save some typing, and can provide portability.
- same thing for the table component. It’s not a huge problem, since it’s only used once in this case, but it does put the name up at the top for easy editing.
Hope this helps!
# Loop through once, read each tag separately
basePath = 'PLC_DepocheusePolymere/Conv Alim Concasseur/Permissives/'
table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table')
headers = ["Status", "Permissive"]
data = []
nb_lignes = system.tag.read(basepath+"ConvAlimConcasseur_PermissiveAbs_INT")
for i in range(nb_lignes.value):
dataColonne1 = system.tag.read(basepath+"Absolute[%s]" % str(i))
dataColonne2 = system.tag.read(basepath+"HMI_PermissiveAbs_ConvAlimConcasseur_%s_" % str(i))
data.append([dataColonne1.value, dataColonne2.value])
table.data = system.dataset.toDataSet(headers, data)
If you have a lost of tags to read, consider using two loops: one to create your tag lists and one create your dataset.
# Loop through twice, read all tags at same time
basePath = 'PLC_DepocheusePolymere/Conv Alim Concasseur/Permissives/'
table = system.gui.getParentWindow(event).getComponentForPath('Root Container.Table')
headers = ["Status", "Permissive"]
data = []
absoluteTags = []
concasseurTags = []
nb_lignes = system.tag.read(basepath+"ConvAlimConcasseur_PermissiveAbs_INT")
for i in range(nb_lignes.value):
absoluteTags.append(basepath+"Absolute[%s]" % (str(i)))
concasseurTags.append(basepath+"HMI_PermissiveAbs_ConvAlimConcasseur_%s_" % (str(i)))
dataColonne1 = system.tag.readAll(absoluteTags)
dataColonne2 = system.tag.readAll(concasseurTags)
for i in range(nb_lignes.value):
data.append([dataColonne1[i].value, dataColonne2[i].value])
table.data = system.dataset.toDataSet(headers, data)
3 Likes
Wow thanks a lot for your help!