databasematlabosisoft

Accessing OsiSoft Database via AF Sdk in Matlab


I have a question of how to access the OsiSoft's PI database via Matlab R2016 and the PI AF SDK. I read the white paper "Using PI Data with MATLAB" by the PI DEVELOPERS CLUB, and using their sample code I am able to load the PISystems instance with the code below, however, the PISystems variable does not seem to contain any useful information

afsdk = NET.addAssembly('OSIsoft.AFSDK');
import OSIsoft.AF.*
import OSIsoft.AF.Asset.*
import OSIsoft.AF.Time.*
import System.*

af_srvs = PISystems; 

When I check the content of af_srvs, it is empty and I get

af_srvs = 

PISystems with properties:

Count: 0
Identity: Systems
DirectoryOptions: Default
Version: [1×1 System.String]
DefaultPISystem: []

To verify that the PI database is working in general, I used tools other than Matlab to retrieve data. I was able to access data via the Excel Datalink plugin, so the PI installation and configuration seems to work. I also checked the settings in the "PI SDK Utility", the correct Default Server is configured as well. Any ideas why

af_srvs = PISystems;

seems to be empty?


Solution

  • It seems I have used the wrong assembly. Here is a minimal example of how to read a sample from PI

    afsdk = NET.addAssembly('OSIsoft.AFSDK');
    import OSIsoft.AF.PI.*;
    
    piservers = OSIsoft.AF.PI.PIServers;
    %ListNET(piservers)
    %simply grab the default server
    %to get a non-default server use pisrv = piservers.Item('servername');
    
    pisrv = piservers.DefaultPIServer;
    point = PIPoint.FindPIPoint(pisrv,'Sinusoid');
    
    fprintf('The value of %s is %f at %s \n', char(point.Name), point.Snapshot.Value, char(point.Snapshot.Timestamp.LocalTime.ToString()));
    

    A good resource for sample code can be found here