How to Retrieve the Instrument Tag of a PI Point Using AF SDK: Understanding Lazy Loading
Learn why PI Point attributes like Instrument Tag may appear missing in AF SDK, and how to explicitly load them using lazy loading and bulk loading techniques for optimal performance.
Roshan Soni
How to Retrieve the Instrument Tag of a PI Point Using AF SDK: Understanding Lazy Loading
When working with OSIsoft PI and the Asset Framework (AF) SDK, it's common to need access to PI Point attributes, such as the Instrument Tag. However, new users may encounter a frustrating issue: the Instrument Tag appears in PI SMT (System Management Tools), but an attempt to access it via the AF SDK throws an error indicating that the attribute was not found.
Let's explore why this happens and how to resolve it.
The Challenge: Missing Instrument Tag in AF SDK
Suppose you're iterating over a list of PI Points and want to retrieve the Instrument Tag using code like this:
string instrumentTag = piPoint.GetAttribute(PICommonPointAttributes.InstrumentTag) as string;
Yet you receive an error or find the value is missing, even though PI SMT clearly shows the Instrument Tag is set.
The Solution: Explicitly Load Attributes
AF SDK employs a lazy loading strategy. This means that certain properties and attributes of objects, such as PI Points, are not fetched from the server until explicitly requested. This design pattern improves performance and responsiveness in client applications like PI System Explorer.
However, if you try to access an attribute that hasn't been loaded yet, you'll get an error. To remedy this, you should explicitly load the required attributes:
// Load the Instrument Tag attribute before accessing it
piPoint.LoadAttributes(PICommonPointAttributes.InstrumentTag);
string instrumentTag = piPoint.GetAttribute(PICommonPointAttributes.InstrumentTag) as string;
Why Lazy Loading?
Lazy loading optimizes network traffic and resource consumption. By default, AF SDK only fetches data from the PI Data Archive or AF Server when needed. This model is excellent for interactive applications but requires developers to be deliberate about preloading data.
Bulk Loading Strategies
When processing many PI Points, consider bulk loading to enhance performance. Rather than sequentially loading attributes for each point, you can use methods that retrieve attributes for multiple points at once, reducing the number of roundtrips to the server.
Takeaway
When accessing PI Point attributes like Instrument Tag via AF SDK, always remember to explicitly load those attributes before trying to use them. Understanding and leveraging lazy loading and bulk loading techniques will help your PI System applications perform efficiently and reliably.
Further Reading:
Tags
About Roshan Soni
Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.
No comments yet
Be the first to share your thoughts on this article.
Related Articles
Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead
A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.
Roshan Soni
Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB
Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.
Roshan Soni
Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?
Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.
Roshan Soni