piconfig examples
- Last UpdatedNov 13, 2024
- 5 minute read
- PI System
- PI Server
The following examples demonstrate how to accomplish various tasks by using piconfig.
Note: If you want to run piconfig commands from within a file, see Use input files for piconfig commands.
Create a point
Note that any unspecified attributes are set to their default values.
@tabl pipoint,classic
@mode create
@istr tag,pointsource,location1,span,zero
TestTag1,OPC,1,10000,5000
Rename a point
Because we are editing the primary key, you must specify the additional attribute, .
@tabl pipoint
@mode edit
@istr tag,newtag
TestTag1,TestTag2
Edit point security
The point and data security are set to the specified ACL strings. The tag attribute is used to specify the record by the primary key. Any additional attributes are edited.
@tabl pipoint
@mode edit
@istr tag,ptsecurity,datasecurity
TestTag2, “piadmin: A(r,w) | piadmins: A(r,w) | PIWorld: A(r) | PIBuffer: A(r)",
“piadmin: A(r,w) | piadmins: A(r,w) | PIWorld: A(r) | PIBuffer: A(r,w)"
Modify archive values
In this example, events from the piarc table are saved to the file, events.txt. The file is used as input in the second step, where values are multiplied by 1.5. This script increases all values of sinusoid by 50% for the last day.
@tabl piarc
@istr tag, starttime, endtime, count
@ostr tag, value, time
@ostr ...
@output events.txt
sinusoid, *-1d, *, 200
@mode edit
@istr tag, value, time
@modify value*= 1.5
@modify mode=replace
@input events.txt
@ends
Write a value to a point
This example writes a value of 10 to cdt158 at the current time.
@tabl piarc
@mode edit,t
@istr tag,time,value,mode
cdt158,*,10,noreplace
The field of the command specifies the archive write mode. The available modes are shown in the following table.
|
Mode |
Description |
|
|
Add unless event already exists at the same timestamp |
|
|
Add event regardless of existing events |
|
|
Add event regardless of existing events and skip compression test |
|
|
Add event and replace existing event if one exists at the same timestamp |
|
|
Replace existing event (fails if no event exists at the specified timestamp) |
|
|
Replace specified event (useful if multiple events exist at the same timestamp) |
|
|
Remove event |
Write an annotation
You can either add an annotation to an existing event or add a new event that is annotated. Processing follows these steps.
-
If there is an event with a matching timestamp and value, the annotation is added.
-
If there is a matching timestamp but the value is different, the value is replaced and annotated so that both the substituted and annotated flags will be set.
-
If the timestamp does not match an existing value, a new event is added with the annotation.
@tabl piarc
@mode edit
@istr tag,time,value,mode,annot
Cdt158,30-JUL-2014 10:15:40, 15, replace, “test annotation”
Remove a PI Firewall entry
In this example, hostmask is the primary key of the entry to be removed.
@tabl pifirewall
@mode del
@istr hostmask
hostmask
Change data security on a subset of points
This sample script first selects all points with the point source OPC, then modifies data security to the specified string. The updates begin after the command runs.
@tabl pipoint
@mode edit
@sele tag=*
@sele pointsource=OPC
@modi datasecurity=
“piadmin: A(r,w) | piadmins: A(r,w) | PIWorld: A(r) | PIBuffer: A(w)”
@ends
Generate a text file of archive data for sinusoid for the last day
@tabl piarc
@ostr tag,time,value
@ostr ...
@istr tag,starttime,endtime,count
@output C:\temp\values.txt
@echo off
sinusoid,*-1d,*,1000000
@exit
Create and delete multiple archive values using a text file
The input file C:\temp\values.txt contains times and values of the points to be created or deleted. For example:
sinusoid,25-may-15 08:07:24,1
sinusoid,25-may-15 11:41:39,1
sinusoid,25-may-15 16:22:09,1
sinusoid,25-may-15 16:25:13,1
In piconfig, enter the following commands:
@mode creat,t
@tabl piarc
@istr tag,time,value
@input C:\temp\values.txt
@ends
@exit
@mode dele,t
@tabl piarc
@istr tag,time,value
@input C:\temp\values.txt
@ends
@exit
Export data for multiple points using an input and output file
This example demonstrates how to use both input and output files with piconfig to export archive data for multiple points over a specified date range. By specifying multiple points and time ranges in an input file, you can efficiently manage and retrieve data, saving the output to a separate file for easy access.
-
Create the input file
Prepare an input file (input.cvs)
tag,starttime,endtime,count
Tag1,*-7d,*,10000
Tag2,*-7d,*,10000
Tag3,*-7d,*,10000
Here, each line specifies a tag, start time, end time, and a count of events to retrieve.
-
Generate the output file
Enter the following commands in piconfig to process the input and create an output file with the retrieved data:
@tabl piarc
@ostr tag,time,value
@ostr ...
@istr tag,starttime,endtime,count
@input input.csv
@output output.txt
@ends
@exit
Note: In the command , the ellipsis (…) specifies that the last attribute may be repeated a variable number of times. For more information, see Display repeating attributes.
Explanation of commands:
-
@tabl piarc: Specifies the PI archive table.
-
@ostr tag,time,value: Defines the structure for the output file (tag, time, and value).
-
@input input.csv: Loads tags, time ranges, and counts from the input file.
-
@output output.txt: Saves the output data to output.txt.
-
@ends: Ends the command set.
-
@exit: Exits piconfig.
After executing these commands, the output file output.txt will contain the specified archive data for each tag in input.csv.
-
Create a single archive value
@mode creat,t
@table piarc
@istr tag,time,value
sinusoid, 26-may-2015 03:27,10
@ends
@exit
Delete a single archive value
@mode dele,t
@table piarc
@istr tag,time
sinusoid, 26-may-2015 03:27
@ends
@exit
Find all points with a snapshot value of Pt Created
@tabl pisnap
@ostr tag,time
@output C:\tags.txt
@select status="Pt Created"
@echo off
@ends
@exit
Look up the database security setting for the PIModule database
@tabl DBSecurity
@ostr Security
@istr DBName
PIMODULES
@ends
@exit
Set a tuning parameter
This example sets the MessageLog_DayLimit tuning parameter, which specifies the number of days messages are retained in the PI message log.
The example first selects the PI timeout table and then sets create mode. The command defines an input structure consisting of a parameter name and value to be used to create a new record in the PI timeout table. Next, the name and value () are entered, setting the tuning parameter MessageLog_DayLimit to a value of .
c:\Program Files\PI\adm>piconfig
* (Ls - ) PIconfig> @tabl pitimeout
* (Ls - PITIMEOUT) PIconfig> @mode cr
* (Cr - PITIMEOUT) PIconfig> @istr name,value
* (Cr - PITIMEOUT) PIconfig> MessageLog_DayLimit,60
*> MessageLog_DayLimit,60
* (Cr - PITIMEOUT) PIconfig> @quit
PIconfig 1 Data lines
4 Command line
0 Records in error...
1 Records Created
Note: On a Data Archive server, you can set tuning parameters by using PI SMT, but on interface nodes, they can only be set by using piconfig.
Delete a digital state set
Note: We recommend that you do not delete a digital state set that has been in use, because archived events associated with the deleted set are no longer visible to PI SDK-based clients, such as ProcessBook 3.x, DataLink 3.x, and PI SMT. Instead, edit the set or create a new digital state set whenever possible. Users who try to retrieve archive values associated with a deleted digital set, whose clients run PI SDK 1.3.6.353 and later, will see:
? StateID: ## | Offset: ##
@tabl pids
@mode delete
@istr set
"SetName"
@ends
@exit
If you want to recover the digital state set, rename it by using the following commands:
@tabl pids
@mode edit
@istr set,newset
DigSet_xx,SetName
where xx is the ID of the deleted state set and SetName is the new name for the set.
Note: If you inadvertently delete a digital state set, contact the Customer Portal as soon as possible.