Data in label with script

Good morning, I want to display the data that has two tags (memory tags that I can change manually from the designer) without binding because I need different instances of the window that is going to show two labels.
Example:


Part 1
Labels         | Reading Tag          |  Display label 
lblCanalTag    |  04                  |  04                  
lblSectorTag   |  07                  |  07
Then, the instance of the window open and show it

Part2 (without close the first window that is open)
Labels            |  Reading Tag  |  Display label 
lblCanalTag       |  08           |  08          
lblSectorTag      |  010          |  010

Then, the instance of the window open and show it, so I have two instances now.

But I tried printing the data if the tag was reading because did not show the data in the labels, and it open various windows but are empty.

I have this code:

#Labels
lblCanalTag = system.gui.getParentWindow(event).getComponentForPath('Root Container.lblCanalTag').text
lblSectorTag = system.gui.getParentWindow(event).getComponentForPath('Root Container.lbSectorTag').text

#Reading tags
tgCanal = system.tag.readBlocking("[default]app_tags/Componentes/ArranquePedidos/Alarma_Canal_Vacio")
tgSector = system.tag.readBlocking("[default]app_tags/Componentes/ArranquePedidos/Alarma_Sector_Vacio")

#set text in the display of the label
lblCanalTag=tgCanal
lblSectorTag=tgSector

Hi @Esmeralda_Lopez

I would take a look at the documentation for the readBlocking function. It is expecting the first parameter to be a list and returns a list. I would suggest probably doing this with readAsync using a callback to set the labels text with the read value.

Also, It seems like you could probably accomplish this with an Indirect Tag Binding removing the requirement to script this entirely.

Hope that points you in the right direction!
JJ Coffman

In a Vision client, are callbacks on the UI thread? (I assumed not.) Setting the label from a callback that isn't on the UI thread requires the use of system.util.invokeLater and embedding a component reference in the callback. Ugly.

Indirect Binding is the correct answer.

1 Like