I'm retrieving information on a sampled data tag on PI. I'm using Matlab to perform the job.
I found the example in Error in AFCalculation.PercentTrue - gives always 100 percent true results So I tried to write the following in Matlab:
piservers = OSIsoft.AF.PI.PIServers;
pisrv = piservers.DefaultPIServer;
timerg = AFTimeRange('01-07-2018 00:00:00','02-07-2018 00:00:00'); % dd-mm-yyyy
inter = AFTimeSpan(0,0,0,1.0); % 1hr interval
inter2 = AFTimeSpan(0,0,0,0,1.0); % 1min interval
percentGood = AFValues();
strFilter = strcat('''sinusoid''','>200');
results = AFCalculation.PercentTrue(pisrv, strFilter, timerg,...
inter, inter2,AFTimestampCalculation.Auto, percentGood);
However, the code doesn't work.
I'm not sure about the following:
- syntax of filter expression, i.e., strFilter in the code. My actual tag on a real server indicates the status of an instrument, the value will be either 'On' or 'Off'. The tag name is Device1_On_Off. In Excel, it is PITimeFilter("'Device1_On_Off'= ""On""",...). I need to calculate to percentage of 'On' time. If I want to implement in Matlab, can I write like
strFilter = strcat('''Device1_On_Off''=','""On""'); ?
so I will get a filter expression like:
which resembles the expression in Excel.
- percentGood as the out parameter: is the last line correct in Matlab?
I also tried
methods(AFCalculation) in command line, however, I received the following error message:
Error using OSIsoft.AF.Data.AFCalculation
Abstract classes cannot be instantiated. Class 'OSIsoft.AF.Data.AFCalculation' is
declared as Abstract.
does this mean I cannot use methods of AFCalculation in Matlab? I have no problem when checking e.g., methods(AFValues).