AnsweredAssumed Answered

Write multiple values to multiple Timestamps on a single point - Matlab

Question asked by asobrino on Nov 22, 2019
Latest reply on Nov 25, 2019 by mtippett

I need to write faster to PI than I do in the next code:

 

 

% I have an array of 8640 measures (one every 10 seconds)
measure=rand(8640,1); %I fill with random values to test the code

time_array=[];
t=datenum('21-Nov-2019 00:00:00 AM');
for i_t=1:length(measure)
time_array{i_t,1}=datestr(t,'dd-mmm-yyyy HH:MM:SS AM');
t=t+10/24/60/60;
end

% I import the libraries
NET.addAssembly('OSIsoft.AFSDK');
import OSIsoft.AF.*;
import OSIsoft.AF.Time.*;
import OSIsoft.AF.PI.*;
import OSIsoft.AF.Asset.*;
import OSIsoft.AF.Data.*;
import OSIsoft.AF.PI.*;
import OSIsoft.AFSDK.PI.*;
import OSIsoft.PISDK.*;
import OSIsoft.PISDK.PISDK.*;
import OSIsoft.PISDK.PISDKCommon.*;

% Conect to the server and create the point
piservers = OSIsoft.AF.PI.PIServers;
pisrv = piservers.Item('PI-SERVER');% The name of the server is PI-SERVER
point = PIPoint.FindPIPoint(pisrv,'Mat_01'); % The name of the tag is Mat_01

tic
for i_t=1:length(measure)
value = AFValue(measure(i_t),AFTime(time_array{i_t}));
point.UpdateValue(value, AFUpdateOption.Replace)
end
toc

 

>> Elapsed time is 77.102840 seconds.

 

The problem is that I have to do it to multiple variables for several days. I need to create. 

I need something faster than a loop. 

Something like create a time range and update all the array of values. 

timerg = AFTimeRange(time_array{1},time_array{end});
inter = AFTimeSpan(0,0,0,0,0,10);

Outcomes