Christian.hetu

Accessing PI data from Matlab using PI OLEDB

Discussion created by Christian.hetu on Apr 8, 2011
Latest reply on Apr 11, 2011 by Christian.hetu

Hi!

 

 

 

I am trying to access PI data from Matlab.   I used the white papers in the library and I am able to connect and retrive data using the demo functions.

 

However, when I try to retrieve a large amount of information, for exemple, a few months of data for a point stored every 2 minutes, it crashes in the

 

adodbquery.m file.

 

invoke(cn,'BeginTrans');
try
  r = invoke(cn,'Execute',sql);
  invoke(cn,'CommitTrans');
  sclSuccess = 1;
catch
  invoke(cn,'RollbackTrans');
  sclSuccess = 0;
end 

%retrieve data from recordset
if r.recordcount>0
    x=invoke(r,'getrows');
    x=x';
else
    x=[];
end

%close recordset
invoke(r,'close');

 

It crashes at  r = invoke(cn,'Execute',sql); 

 

Here is the matlab output :

 

??? Undefined function or variable "r".

Error in ==> adodbquery at 40
if r.recordcount>0

Error in ==> PI_CompressedData at 31
Output=adodbquery(cn,sql);

Error in ==> PI_Demo at 36
CompressedData =
PI_CompressedData(server,pt,CompDH('2010-01-01'),CompDH('2011-01-01'),cn)

 

Note : I understand that this error is normal since r is undefined in the case our query crashes and is never assigned a value, but I kept the original file for this example

 

The query is allright.  When I enter it in the PIOLEDB.msc application, it works.  I cannot see all the data since the grid seems limited, but at least the query runs.

 

In my case it is :

 

select tag,time,value from piarchive..picomp2 where tag = 'im.cim.g01:mw' AND time between '2010-01-01' and '2011-01-01'

 

Was anyone able to retrive that kind of amount of data ?  I did some test and was able to retrieve many months ( more than 130k rows ), but a full year does not work.

 

I was thinking about retrieving more than a decade of data and I can't even get past a year and I would rather loop the process of querying the database.  This should work directly.

 

Also, I don't know if people experimented problems, but it seems the connections does not clear or close itself quite allright.  I sometimes have to restart my Matlab application and now the query works.  ( But never in the case of "big" queries )

 

 

 

Thanks for your help!

Outcomes