AnsweredAssumed Answered

Update PI values with MATLAB (AFSDK)

Question asked by hilltben on Jun 10, 2019
Latest reply on Jun 18, 2019 by rdavin

Can PI points be written to with MATLAB?

 

This is the closest example that I found on PI Square: https://pisquare.osisoft.com/message/25664?commentID=25664#comment-25664

The 2nd example here doesn't seem to work, perhaps because I cannot properly define his variable PI_POINT in a way that i can access the UpdateValue method:  PV.Data.UpdateValue(value,timestamp);  

 

 

%Example write - THIS IS MY FAILED ATTEMPT

PI_POINT = PIPoint.FindPIPoint(pisrv,'sinusoid')

 

timestamp = System.String('15-Sep-2013 11:01:00'); 

value=-10;   

PI_POINT.PV.Data.UpdateValue(value,timestamp); 

 

 

I can successfully connect to the pi server and access af as well through matlab, but can't seem to find the way to write to a pi point.

 

%Libraries

afsdk = NET.addAssembly('OSIsoft.AFSDK');

import OSIsoft.AF.*;

import OSIsoft.AF.Asset.*;

import OSIsoft.AF.Time.*;

import System.*;

import OSIsoft.AF.Data.*

import OSIsoft.AF.PI.*

 

%MATLAB example query of AF Structure - Shows that I can access AF

af_srvs = PISystems;

af_svr = af_srvs.Item('PI_SERVER');

af_db = af_svr.Databases.Item('AF_Database');

af_element_list = AFElement.FindElements(af_db, [], 'G*', ...

AFSearchField.Name, true, AFSortField.Name, AFSortOrder.Ascending, ...

intmax('int32'));

for i = 0:(af_element_list.Count - 1)

fprintf('%s\n', char(af_element_list.Item(i).Name));

end

 

 %MATLAB example to query aspects of the sinusoid function. - Shows that I can access PI

piservers = OSIsoft.AF.PI.PIServers; 

pisrv = piservers.DefaultPIServer; 

point = PIPoint.FindPIPoint(pisrv,'sinusoid');

point.Data

timerg = AFTimeRange('*-1d','*'); 

inter = AFTimeSpan(0,0,0,1);    % 1hr interval 

summarizedVals = point.Summaries(timerg, inter, AFSummaryTypes.Average, AFCalculationBasis.TimeWeighted, AFTimestampCalculation.Auto); 

 

 

Outcomes