Get Started Accessing a PI Data Archive
This example shows you how to connect to an AVEVA® PI Data Archive and locate asset information.
The PI Data Archive is capable of storing decades of real-time data from hundreds of assets. Running this example assumes a PI Data Archive available for connection. The demo tags used in this example were provided by AVEVA and can be downloaded from AVEVA sharefile.
Create Client and Connect to Data Archive
Connect to the PI Data Archive using the piclient
function. In this example the Windows computer name is used as the PI server name. Your situation might vary depending on the PI System configuration.
host = getenv("COMPUTERNAME");
client = piclient(host);
List All Tags
Create a list of all tags available on the PI Server using the tags
function. Depending on your system, this query might return a large amount of data. If you have an extensive list of tags that makes this too slow or impractical, you can skip this step.
A tag is used by the PI System as an alias or shortcut to represent an asset attribute such as voltage, current, temperature, etc. Some tag names are short, others might be long and descriptive or include a unique ID.
allTags = tags(client)
allTags=478×1 table
Tags
_______________________________________________________________________________________________________________________
"Flynn I.Active Power Generated.1b86ebf3-1c0a-52bd-3222-38e6660052f2"
"Flynn I.Hydro Unit Attention Percentage.4ae999f5-f5ae-535c-3f43-fcb3775ee8a4"
"Flynn I.Hydro Unit Condition.f3ec518f-1059-5c79-00cf-28c97d06714b"
"Flynn II.Active Power Generated.1b86eb8e-1c0a-52bd-3222-38e6660052f2"
"Flynn II.Hydro Unit Attention Percentage.4ae99988-f5ae-535c-3f43-fcb3775ee8a4"
"Flynn II.Hydro Unit Condition.f3ec51f2-1059-5c79-00cf-28c97d06714b"
"Flynn River Hydro.Actual Power Generated.1670a44f-b666-5758-3021-6f6f8a37127d"
"Flynn River Hydro.Hydro Attention Percentage.e7b2c9f9-ef29-54be-0f3a-41a791e7bfd1"
"Flynn River Hydro.Hydro Condition.1bf06b5f-9e31-5615-1701-19b9b333770f"
"GU1 Generator.Analysis Generator Condition - Hours Since Last Maintenance.d7df31d2-dbb3-5ff3-346b-4102edc802cc"
"GU1 Generator.Analysis Generator Cooling - Bearing Temperature.7c20f57e-0f25-5474-3d73-b839651b5ed7"
"GU1 Generator.Analysis Generator Cooling - Cooling Water Output Temperature.844da429-3a04-505b-1315-ab4869963455"
"GU1 Generator.Analysis Generator Cooling - Cooling Water Pressure.e217c9ab-825a-5e3b-1915-657727f82eea"
"GU1 Generator.Analysis Generator Cooling - Core Temperature.204ab467-880e-5691-189c-3bc20e83484f"
"GU1 Generator.Analysis Generator Cooling - Rotor Winding Temperature.1c7fa6fd-9eaf-5fea-30ce-b1eca9436a20"
"GU1 Generator.Analysis Generator Lubricating - Lubricant Oil Output Temperature.d6db886f-e4fa-5c60-2552-bf41e4307e9d"
⋮
Narrow List of Tags to Specific Facility Using Wildcard
You can browse the list of tags returned in the previous step to locate a particular tag and assign it to a new variable. But it is more convenient to narrow the search using additional input parameters in the tags
function. For example, based on the list of tags returned in the previous step, specify a prefix in your tag search to narrow the results. The following code uses a wildcard to find all tags with the prefix "OSIDemo_Flynn I.".
tagsFlynnI = tags(client, Name = "OSIDemo_Flynn I.*")
tagsFlynnI=7×1 table
Tags
________________________________________________________________________
"OSIDemo_Flynn I.Dam Gates Opening.b2156e0a-0b4d-555c-3edf-cea1339a96b7"
"OSIDemo_Flynn I.Penstock Flow.322006e7-2097-5f17-0e4d-1be282f8c36c"
"OSIDemo_Flynn I.Penstock Opening.d49c75c6-5ef9-57a8-0366-9d71e9b595cf"
"OSIDemo_Flynn I.Penstock Pressure.c550b9de-f101-53be-1b5a-84e0f3c22991"
"OSIDemo_Flynn I.Reservoir Level.1a4f7e16-c4ad-55ea-0731-ca5ba86bcaf7"
"OSIDemo_Flynn I.Water PH.42e7dc15-656a-5aa7-181c-6adee980d38a"
"OSIDemo_Flynn I.Water Temperature.18d94851-7252-5c87-1fb3-d769fb949f15"
Use Multiple Wildcards to Narrow List of Tags
You can also use multiple wildcards to narrow a list of tags. The following code uses a wildcard before and after "Demo". This returns all tags containing the string "Demo". Notice the results now include tags containing both "Flynn I" and "Flynn II".
tagsDemo = tags(client, Name = "*Demo*")
tagsDemo=194×1 table
Tags
____________________________________________________________________________
"OSIDemo_Flynn I.Dam Gates Opening.b2156e0a-0b4d-555c-3edf-cea1339a96b7"
"OSIDemo_Flynn I.Penstock Flow.322006e7-2097-5f17-0e4d-1be282f8c36c"
"OSIDemo_Flynn I.Penstock Opening.d49c75c6-5ef9-57a8-0366-9d71e9b595cf"
"OSIDemo_Flynn I.Penstock Pressure.c550b9de-f101-53be-1b5a-84e0f3c22991"
"OSIDemo_Flynn I.Reservoir Level.1a4f7e16-c4ad-55ea-0731-ca5ba86bcaf7"
"OSIDemo_Flynn I.Water PH.42e7dc15-656a-5aa7-181c-6adee980d38a"
"OSIDemo_Flynn I.Water Temperature.18d94851-7252-5c87-1fb3-d769fb949f15"
"OSIDemo_Flynn II.Dam Gates Opening.b2156e77-0b4d-555c-3edf-cea1339a96b7"
"OSIDemo_Flynn II.Penstock Flow.3220069a-2097-5f17-0e4d-1be282f8c36c"
"OSIDemo_Flynn II.Penstock Opening.d49c75bb-5ef9-57a8-0366-9d71e9b595cf"
"OSIDemo_Flynn II.Penstock Pressure.c550b9a3-f101-53be-1b5a-84e0f3c22991"
"OSIDemo_Flynn II.Reservoir Level.1a4f7e6b-c4ad-55ea-0731-ca5ba86bcaf7"
"OSIDemo_Flynn II.Water PH.42e7dc68-656a-5aa7-181c-6adee980d38a"
"OSIDemo_Flynn II.Water Temperature.18d9482c-7252-5c87-1fb3-d769fb949f15"
"OSIDemo_GU1 Generator.Active Power.4db83f0a-ff87-5c67-385a-83cfe3ac560d"
"OSIDemo_GU1 Generator.Axial Vibration.373a6144-442d-5e69-1079-5986bf866fa1"
⋮
Narrow List of Tags Using MATLAB Pattern Matching
Narrow the list of tags using the MATLAB® contains
function. This example makes use of the tagsDemo
list from a previous step, returning all tags containing the string "Water".
tagsWater = tagsDemo(contains(tagsDemo.Tags,"Water"),:)
tagsWater=48×1 table
Tags
_____________________________________________________________________________________________
"OSIDemo_Flynn I.Water PH.42e7dc15-656a-5aa7-181c-6adee980d38a"
"OSIDemo_Flynn I.Water Temperature.18d94851-7252-5c87-1fb3-d769fb949f15"
"OSIDemo_Flynn II.Water PH.42e7dc68-656a-5aa7-181c-6adee980d38a"
"OSIDemo_Flynn II.Water Temperature.18d9482c-7252-5c87-1fb3-d769fb949f15"
"OSIDemo_GU1 Generator.Cooling Water Intake Temperature.2b0243be-4a97-5a48-1337-0e0b242c4795"
"OSIDemo_GU1 Generator.Cooling Water Output Temperature.7d1a79de-1957-5efc-1d55-aa5fcfccf36a"
"OSIDemo_GU1 Generator.Cooling Water Pressure.0c723cab-80c6-5630-13bf-38fdd7092768"
"OSIDemo_GU1 Generator.Water in Oil.801b9776-f2fd-5a9b-2725-d2e66ad4284f"
"OSIDemo_GU1 Turbine.Cooling Water Intake Temperature.f987f83c-7a17-5027-1492-0482f0ae04b9"
"OSIDemo_GU1 Turbine.Cooling Water Output Temperature.62d8c804-2b82-53bc-09f1-660ffa00aa70"
"OSIDemo_GU1 Turbine.Cooling Water Pressure Output.7c04ebc3-ae18-5207-0690-514252308c5b"
"OSIDemo_GU1 Turbine.Water Flow.cf5b84c3-af11-5637-2317-f518e59b0c9f"
"OSIDemo_GU1 Turbine.Water in Oil.562f5784-a814-5b11-3dd7-44b9735068ca"
"OSIDemo_GU1 Turbine.Water pH Intake.2f31dbfe-6f9a-5005-083c-db8531de4d07"
"OSIDemo_GU1 Turbine.Water pH Output.59993b66-79da-591e-1d17-ea5fad61a12b"
"OSIDemo_GU2 Generator.Cooling Water Intake Temperature.2b0243d3-4a97-5a48-1337-0e0b242c4795"
⋮
Identify Tag Based on Its Position in Existing Tag List
When narrowing your tag search, you can quickly single out a particular tag from a tag list by specifying its position in the list. This is often more convenient than identifying a tag by its name, which can sometimes be lengthy. For example, you can identify "OSIDemo_Flynn I.Water Temperature..." in the tagsWater
list of the previous example by indicating the second entry in tagsWater
.
tagFlynn1Water = tags(client, Name = tagsWater{2,:})
tagFlynn1Water=table
Tags
________________________________________________________________________
"OSIDemo_Flynn I.Water Temperature.18d94851-7252-5c87-1fb3-d769fb949f15"
Clean Up
When you are finished working with the PI Data Archive, disconnect and remove the client by clearing its variable from the workspace.
clear client;