Reading tag values in Gateway (Subscribing to Tags)

In my module I would like to read a value of a tag created in a designer (Default tag provider). So that I can use the data to add column status in a record table on the gateway (as seen in the picture below).

Is there an example where I could see how to build such a module?
If not I would kindly ask if someone can point me on the right direction how to start. Because I am reading the Ignition sdk docs (under Working with Platform Services -> SQL Tags) but there is not much information and no examples. And all my attempts so far to read a value of a Tag have failed.
[attachment=0]status.png[/attachment]

I figured out how to read tag values so I am posting the solution here in case someone will be struggling with this like I was.

  1. First of all you need to make new class implementing TagChangeListener
public class TagListener implements TagChangeListener {
	TagPath path;
	public TagListener(TagPath path) {
		this.path= path;
		// TODO Auto-generated constructor stub
	}

	private final Logger log = Logger.getLogger(getClass());

	@Override
	public TagProp getTagProperty() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void tagChanged(TagChangeEvent arg0) {
		List <TagPath> list= new ArrayList<TagPath>();
		list.add(path);
		List<QualifiedValue> tags= GatewayHook.context.getTagManager().read(list);
		log.error("Value : "+ tags.get(0).getValue());
	}
}

With overriding the “tagChanged” function you define what should happen when the tag changes.

  1. Than you use the “TagManager” provided by the context you are in to subscribe to the wanted tag.
public void readingTest() throws IOException{
		TagPath myPath= TagPathParser.parse("[default]underTag/TestniTag");
		TagListener listener=new TagListener(myPath) {

		};
		List <TagPath> lista= new ArrayList<TagPath>();
		lista.add(myPath);
		GatewayHook.context.getTagManager().subscribe(myPath, listener);
		
	}
1 Like