-
Re: Basics of the AF SDK
John MessingerSep 10, 2017 9:29 PM (in response to ainwood)
2 of 2 people found this helpfulHi Andrew,
Some interesting questions!
Looking at that code example, it's not really clear to me why the sample is structured this way. Instantiating the PISystems and PISystem objects is not necessary in order to retrieve a PIPoint value. Looking at the documentation for the PIServer.FindPIServer method overload used on line 4 of the sample, it seems the only benefit of using this is to get a PIServer object that then uses the credentials of the current user associated to the PISystem object. Personally I've never gone down this route for accessing a PIServer and it's associated child objects. In fact, I would probably re-write this as follows:
string piServerName = "BNE-DPI1"; PIServers myPIServers = new PIServers(); PIServer myPIServer = myPIServers[piServerName]; PIPoint myPIPoint = PIPoint.FindPIPoint(myPIServer, "CDT158"); // Display information about the PIPoint Console.WriteLine("Name of the PIPoint = {0}", myPIPoint.Name); Console.WriteLine("ID of the PIPoint = {0}", myPIPoint.ID); Console.WriteLine("Type of the PIPoint = {0}", myPIPoint.PointType); Console.WriteLine("PIPoint Current Value = '{0}'", myPIPoint.CurrentValue());
This is a matter of personal choice in my mind, but this is how I tend to approach something like this.
On your second question, it should be noted that the PISystems class is a global collection of PISystem objects, the key point being it is a collection. It represents the list of known PISystems (AF servers), much like the Known Servers Table in the PI-SDK. As such, it doesn't need to implement IDisposable. As to why PISystem implements IDisposable and PIServer doesn't, I don't really know. Given that this interface is supposed to be used to release unmanaged resources, I'm a little surprised that it is PISystem and not PIServer that implements this. Perhaps one of the AF developers such as David Hearn can answer this particular question.
Regards,
John
-
Re: Basics of the AF SDK
David HearnSep 11, 2017 1:15 PM (in response to John Messinger)
5 of 5 people found this helpfulThe advantage of using the FindPIServer method where you specify a PISystem object as a parameter is for a slight improved performance. If you already have a PISystem object for a user, this method will avoid resolving the user identity again when looking up the PIServer object for the current user. Each time you call 'new PIServers()' or use the FindPIServer method without specifying a PISystem, the current user identity must be resolved.
For the second question, an earlier release of AF implemented IDisposable on PISystem object to fix an issue with releasing WCF connections to the AF Server. This has been resolved in the newer versions of .NET and therefore is no longer needed but cannot be removed because of backwards compatibility. The only thing it does now is to remove references to managed memory used by the PISystem object, but it can be reused later by re-allocating its memory. For example it would release any cached objects read from the server.
-
Re: Basics of the AF SDK
John MessingerSep 13, 2017 12:02 AM (in response to David Hearn)
Thanks for that explanation David, much appreciated.
-
-
-
Re: Basics of the AF SDK
Rick DavinSep 11, 2017 1:03 PM (in response to ainwood)
2 of 2 people found this helpfulHi Andrew,
Looking at line 04 of your original post:
PIServer myPIServer = PIServer.FindPIServer(myPISystem, piServerName);
You are attempting to find a PIServer by its name. There are two particular overloads for this:
FindPIServer(PISystem, String)
Remarks: Find the PIServer from the specified name using the credentials of the current user associated with the specified PISystem. This method will NOT require a security check each time it is called if a PISystem is specified.
Remarks: This method will require a security check each time it is called. Use the FindPIServer(PISystem, String) version to avoid duplicate security checks.
If you are writing an app to interact with your data archive and it has little to do with any AF assets, you may find the second overload more to your liking.
-
Re: Basics of the AF SDK
gregor.vilkner Jun 12, 2018 8:45 PM (in response to ainwood)ok. so there's always been 2 folders in my (x86)\PIPC\AF\ directory
.\PublicAssemblies includes OSISOFT.AFSDK.dll version 2.0 targeting .net 3.5 (Details still says 2.9.5.8352) 3.69MB
and
.\PublicAssemblies\4.0 includes OSISOFT.AFSDK.dll version 4.0 targeting .net 4.5 (Details also says 2.9.5.8352) 4.57MB
and the 4.0 dll includes PIPoint and PIServer objects in the Osisoft.AF.PI namespace. So you're correct. No need to reference the pisdk.
Thanks,
Gregor
-
Re: Basics of the AF SDK
Eugene LeeJun 13, 2018 5:53 AM (in response to gregor.vilkner)
This is the same for the OSIsoft.AF.Data namespace. Only available in the .NET 4.5 version.
-