Action examples
- Last UpdatedNov 16, 2022
- 2 minute read
The following examples illustrate the use of actions to modify data and processing logic.
StoreInPI() Example 1
Write a value of FIELD(1) to the tag named test:001 using current time.
StoreInPI ("test:001",,NOW(), FIELD(1),,)
StoreInPI() Example 2
Write the value of FIELD(1) to the tag "test:001" using the current time. If the value exceeds 200, indicate that the value is bad (-255 represents the code from the PI system digital set).
FIELD(1) = ["*,(*),*"]
IF( FIELD(1) > 200 ) THEN
FIELD(2) = -255
Else
FIELD(2) = 0
EndIf
StoreInPI ("test:001",,NOW(),FIELD(1),FIELD(2),)
StoreInPI() Example 3
Write the full PI data record. Because an annotation is included, the interface uses PI SDK to write the value.
[FIELD]
FIELD(1).NAME = "Tag"
FIELD(1).Type = "String"
FIELD(2).NAME = "Timestamp"
FIELD(2).Type = "DateTime"
FIELD(2).FORMAT = "yyyy-MM-dd hh:mm:ss"
FIELD(3).NAME = "Value"
FIELD(3).Type = "Number"
FIELD(4).NAME = "Status"
FIELD(4).Type = "Number"
FIELD(5).NAME = "Qflag"
FIELD(5).Type = "Number"
FIELD(6).NAME = "Annotation"
FIELD(6).Type = "String"
FIELD(7).NAME = "Result"
FIELD(7).Type = "Number"
[MSG]
MSG(1).Name = "Message1"
[Message1]
Message1.Filter = C1=="-"
Result = StoreInPI(Tag,, Timestamp, Value, Status, Qflag, Annotation)
If( Result <> 0) Then
StoreInPI("UFL_Error_Tag",, NOW(), Result,,)
EndIf
StoreInPIPoints() Example 1
Create a PI point in PtClass classic. The PI tag name is read through FIELD(1).
StoreInPIPoints (FIELD(1),, "String")
StoreInPIPoints() Example 2
Create a PI point in PtClass classic with 0 exception dev. and 0 compression. Use the Collection option field type for passing the attributes.
[FIELD]
FIELD(1).NAME = "Tag"
FIELD(2).NAME = "Desc"
FIELD(3).NAME = "Attributes"
FIELD(3).TYPE = "Collection"
Attributes=Clear()
Attributes=Add("excdev",0)
Attributes=Add("excdevpercent",0)
Attributes=Add("compdev",0)
Attributes=Add("compdevpercent",0)
Attributes=Add("excmax",0)
Attributes=Add("excmin",0)
Attributes=Add("compmax",0)
Attributes=Add("compmin",0)
Attributes=Add("descriptor",Desc)
StoreInPIPoints(Tag,,"Float32",Attributes)
AppendLines()
Suppose the input file contains the following lines:
BATCH: B1;
05-Feb-07 12:00:00;
Mixture1
UNIT: U1;
05-Feb-07 12:10:00;
Blue
The configuration file filters for "BATCH" and "UNIT" and appends the following two lines, as shown in the following example:
[MSG]
MSG(1).Name = "Batch_MSG"
MSG(2).Name = "Unit_MSG"
[Batch_MSG]
Batch_MSG.Filter = C1 == "BATCH*"
AppendLines(2)
Batch = ["(*);*"]
Timestamp = ["*:*;(*);*"]
Value = ["*:*;*;(*)"]
StoreInPI(Batch,,Timestamp, Value,,)
[Unit_MSG]
Unit_MSG.Filter = C1=="UNIT*"
AppendLines(2)
Unit = ["(*);*"]
Timestamp = ["*:*;(*);*"]
Value = ["*:*;*;(*)"]
StoreInPI(Unit,,Timestamp, Value,,)
The resulting lines look like this:
BATCH: B1; 05-Feb-07 12:0:00; Mixture1
UNIT: U1; 05-Feb-07 12:10:00; Blue
SetNextMsg()
Data file content: Name, Timestamp, Value
Tag1, 05-Feb-07 12:00:00, 1
Tag1, 05-Feb-07 12:10:00, 2
[FIELD]
FIELD(1).NAME = "TagName"
FIELD(2).NAME = "Timestamp"
Timestamp.TYPE = "DateTime"
Timestamp.FORMAT = "dd-MMM-yy hh:mm:ss"
FIELD(3).NAME = "Value"
FIELD(3).TYPE = "Number"
[MSG]
MSG(1).Name = "Description"
MSG(2).Name = "Events"
[Description]
Description.Filter = C1=="Name, Timestamp, Value"
' Check the next couple of lines in the context of MSG(2)
' until there is a line that does not satisfy the filter
SetNextMsg("Events",)
[Events]
Events.Filter = C1 == "*,*,*"
FIELD(1) = ["(*),*"]
FIELD(2) = ["*,(*),*"]
FIELD(3) = ["*,*,(*)"]
StoreInPI(TagName,,Timestamp, Value,,)
SkipFile()
In this example, the entire file is skipped because the first message matched the section that invoked SkipFile() function. The file is renamed as though it were processed normally.
Data file content: Invalid Sample ' Name, Timestamp, Value
Tag1, 05-Feb-07 12:00:00, 1
Tag1, 05-Feb-07 12:10:00, 2
[MSG]
MSG(1).Name = "FileValidation"
MSG(2).Name = "Message1"
[FileValidation]
FileValidation.Filter = C1=="Invalid*"
SkipFile()
[Message1]
SkipLines()
MSG(1).Name = "Message1"
[Message1]
Message1.Filter = C1=="*,*,*"
FIELD(1) = ["(*),*,*"]
FIELD(2) = ["*,(*),*"]
FIELD(3) = ["*,*,(*)"]
If (FIELD(3) IS NULL) Then
SkipLines(1)
Else
StoreInPI(FIELD(1),, FIELD(2), FIELD(3),,)
EndIf