An Industrial IOT Platform

OPScript - Working with Tags

The Tag Id

In Open-Plant, all connected instruments, sensor and devices are identified by a Tag Id. The Tag Id is a unique identifier. For example FIC101, which is a typical name for a flowmeter sensor. In most control system naming conventions, a dot separator will proceed the name. The dot subdivides the TagId into TagName and Parameter in the examplary manner below:

TagId 'FIC101.PV' will have TagName = 'FIC101' and Parameter = 'PV'

TagId 'R01.PI102.MV' will have TagName = "R01.PI102' and Parameter = 'MV'. The last dot is used as the separator for TagName and Parameter.

TagId 'FIC106' will have TagName = 'FIC106' and the Parameter will be empty (=""), as there are no dot separators.

IMPORTANT NOTE: In Open-Plant TagIds are NOT Case Sensitive, i.e. FIC101.Value = fic101.value.

The Tag Window

The Tag window provides the easiest way to add tags into OPScript. It can be accessed directly within OPScript as shown below. Once a Tag object has been added into OPScript, a set of functions will be available for access for each tag


This function allows you to access existing tag details 
//The following prints 'FIC101.Value' Tag Id to the console
string TagId = OP.Tag("FIC101.Value").Id;
Once accessed, it gives a host of tag properties such as
-Id (The TagId)
-TagName (E.g. FIC101)
-Parameter (E.g. Value)
-UnitOfMeasure (E.g. DegC)
-Description (The description of the device/tag)
-Corporate (The organization/company name)
-Plant (The Plant's name)
-Area (The are where the device belongs to)
-Unit (The operating unit where the device belongs to)
-Param1...Param9 (Place holder variables for custom properties)
-DataType (The Tags value data type: Real, Int or Bool)
-Interpolation (How data is construed between data point: Linear or Digital)
-DatabaseLocation (The location of the Tag in the Open-Plant Database
-DuplicateThresholdInMS (Further explaned below)
-SampleTimeOutInS (Determines how long a sample is considered fresh and not out-of-date. Default is 180 seconds)


This function allows you to check if a tag exists in the system. It return TRUE if a tag exists and FALSE otherwise
//The following logs if 'FIC101.Value' exists
bool FICExists = OP.TagExists("FIC101.Value");
if (FICExists) OP.Log("FIC101 Exists");


This function saves a Tag and all it's properties (e.g. UnitOfMeasure, Description, Plant, Area, Parameter,etc) into Database. It return true if the operation is successful and false otherwise.
//The following logs if 'FIC101.Value' exists
bool SaveSuccess = OP.SaveTag("FIC101.Value");
if (SaveSuccess) OP.Log("Save Successful!");

What is Duplicate Threshold?

The Duplicate Threshold (Tag Property DuplicateThresholdInMS) is a threshold settings before a sample can be said to be a duplicate with another sample. It is specified in Miliseconds. The default value is 250ms.

If a sample falls between +/-250ms of another sample, this sample is considered a duplicate.

A duplicate sample will be rejected by the server.
//The following logs if 'FIC101.Value' exists
bool SaveSuccess = OP.SaveTag("FIC101.Value");
if (SaveSuccess) OP.Log("Save Successful!");

OP.ListTags - Looping through entire tag list

At times, one may need to run an analysis that involves each tag in the system. To do so, the OP.ListTags function returns a list of Tag Objects.

The function has the following input:
- SearchWildCard: Returns only Tags that matches the wildcard. Use "*" to return all Tags.
- NumberOfTagsLimit: The number of tags to return. If not specified, it will return all tags that matches the wild card.

Example use:
//This logs all the Tag and its values
List Tags = OP.ListTags("*");
foreach (Tag T in Tags)
	OP.Log(T.Id + " = " + T.LastValue);

Accessing Tag Values



This function returns the current value of a tag. If there is no current value, a NULL value is returned. 

A value is considered current if it is not older than it's timeout value.

The timeout value is a property of the tag. If not set, it's default value is 180seconds (3 minutes)

This is used for real time data analytics where the 'freshness' of the value is of concern.
//This shows the current value of 'FIC101.Value' in the console
var CurrentValue = OP.Tag("FIC101.Value").Value;


This function returns the last or most recent value of a tag. Unlike 'OP.Tag.Value' it will not return null if the value is old. 

This is used for historical analytics, where the validity of real time values are not of a concern.
//This shows the last known value of 'FIC101.Value' in the console
var LastKnownValue = OP.Tag("FIC101.Value").LastValue;


This function returns the value of a tag at a specified timestamp.

The timestamp can be specified as:
- a DateTime object. The DateTime must be specified in UTC.
- a string Timestamp semantic.

A timestamp semantic is a format which takes a timestamp relative to the current time (NOW). For example:
- NOW-1 Hour
- NOW-10 Minutes
- NOW-5 Second

Time semantic works in UTC by default so no UTC conversion is required.
var SpotValue1 = OP.Tag("FIC101.Value").SpotValue(DateTime.UtcNow);
var SpotValue2 = OP.Tag("FIC101.Value").SpotValue("2020-06-18 20:02:00");
var SpotValue3 = OP.Tag("FIC101.Value").SpotValue("Now");
var SpotValue4 = OP.Tag("FIC101.Value").SpotValue("Now-1Hour");
var SpotValue5 = OP.Tag("FIC101.Value").SpotValue("Now-5Day");
var SpotValue6 = OP.Tag("FIC101.Value").SpotValue("Now-10Minute");


This function returns the Nth Value of a tag. 

RawValue(0) return the last value. It will have the same as "OP.Tag.LastValue".

RawValue(1) returns the second last value.

//RawValue1 and LastValue are similar values
var RawValue1 = OP.Tag("FIC101.Value").RawValue(0);
var LastValue = OP.Tag("FIC101.Value").LastValue;

//This obtains the second last value
var RawValue2 = OP.Tag("FIC101.Value").RawValue(1);

Creating / Deleting a Tag



This function creates a new tag based on a specified TagId and automatically saves it into the Open-Plant Database. 

It returns TRUE if operation is successful and FALSE otherwise. If a tag ALREADY EXISTS, it STILL returns TRUE.

It has a number of parameter inputs, best shown in the examples below: 
OP.CreateAndSaveTag("FIC101.Value","M3Hr", DataType.Real, Interpolation.Linear,"This is a Flowmeter","CompanyXYZ","PlantA","AreaA","UnitA");


This function deletes a Tag specified by the TagId. It returns true if the operation is successful and false otherwise. 

By default, this function only deletes the Tag, it won't delete the tag data values. This is a safety feature to ensure a Tag deletion won't delete "years" of accumulated plant data.

An additional parameter, if set TRUE, will delete the data values as well.
//This only deletes the Tag data
bool DeleteTagSuccess = OP.DeleteTag("FIC101.Value");
if (DeleteTagSuccess) OP.Log("Delete Tag Successful");

//This deletes the Tag and all it's values
bool DeleteTagAndDataSuccess = OP.DeleteTag("FIC101.Value", true);
if (DeleteTagAndDataSuccess) OP.Log("Delete Tag and Data Successful");
Open-Plant is a revolutionary Industrial IOT Platform software, used to create and deploy Industrial IT apps/solutions. It is an all-encompassing solution offering both back-end and front-end components i.e. the full stack. From our user's experience, creating and deploying Industrial IT apps became 10x faster and 10x less cost. We serve the mining, energy, oil & gas, construction and manufacturing industry. 


Perth, Australia