Web Dev Python Tag Read

Hi,

I am trying do read some tags in webdev modules with Python.
Can any one give sample script to test it

In Ignition you need to create a python resource.
You can write the following code in the doPost section. It’s worth reading up on the differences of GET, POST and PUT commands.
Code for a basic tag read can look something like this:

	tagPath = request['params']['tagPath']
	tagVal = system.tag.read(tagPath).value
	
	return {'json': system.util.jsonEncode(tagVal)}

You will need to remember to add the Tag Provider to the TagPath variable. ie: probably “[default]”

Javascript function in your web app:

function readTag(){
	$.ajax({
		type: "POST",
		url: "../python/getTag",
		data: {"tagPath":"[Default]Silos/MilkSilo1/PP10001/Run"},
		contentType: "application/x-www-form-urlencoded",
		success: function(result){
			if (result){
				// Do something with results
			
			} else {
				// Error with tag read in Ignition
				// Do something else
			}
		},
	});
}

The url “/python/getTag” represents the path in your WebDev directory in Ignition.

Also a nice easy way to test is an application like the [Advanced Rest Client] (https://chrome.google.com/webstore/detail/advanced-rest-client/hgmloofddffdnphfgcellkdfbfbjeloo) in order to create the POST message without a webpage.

This blog post giving an example of using the WebDev Module might be useful in general: http://blog.perfectabstractions.com/2017/03/21/bring-your-ignition-data-to-the-web-with-the-webdev-module/