23 Replies Latest reply on Oct 27, 2010 10:47 PM by Ahmad Fattahi

    PI and MATLAB paper announced on twitter?

    Asle Frantzen

      Hi people! On August 13th I read this on twitter:

       

      just finished a paper for using PI data into MATLAB (going under review before publishing... stay tuned!)

       

       

       

      ETA for this document?

       

       

        • Re: PI and MATLAB paper announced on twitter?
          andreas

          Real soon! The WP is still under review.

          • Re: PI and MATLAB paper announced on twitter?

            Yup, this is my bad: I'm the one who twittered about this and I still haven't had time to incorporate all the feedback I got from the review...

             

            I was heavily involved in preparing the OSIsoft vCampus Live! event and then went off for 3 weeks... I'll do my best to have it ready as soon as possible.

             

            In the meantime, do you have a specific question about this?

              • Re: PI and MATLAB paper announced on twitter?
                Asle Frantzen

                No specific question - we'll just wait 'til the document is done :)

                • Re: PI and MATLAB paper announced on twitter?
                  jack

                  What is the ETA of this paper?

                   

                  Thanks,

                    • Re: PI and MATLAB paper announced on twitter?

                      ETA = now!

                       

                      Finally! This paper just got posted on the vCampus Library, under the "White Papers and Tutorials > Miscellaneous" branch. I got great feedback from colleagues at OSIsoft, some of which should be added to the paper soon. In other words, you can expect revisions of this paper in not too long; we just decided to post it as it is now to prevent delaying it any longer.

                       

                      Enjoy and don't hesitate to provide feedback!

                        • Re: PI and MATLAB paper announced on twitter?
                          gempesaw

                          Hi there everyone,

                           

                          I m trying to use MATLAB to retreive values with PI. Right now i m getting this error message:

                           

                          ??? Invoke Error, Dispatch Exception:
                          Source: Microsoft OLE DB Service Components
                          Description: Invalid value for registry

                          Error in ==> adodbcn at 29
                          invoke(cn,'Open', cnstr);

                          Error in ==> PI_CurrentValue at 22
                              cn=adodbcn(cnstr);

                           

                          I am not sure what is the issue. Any help is very much appreciated.

                           

                          I m using the ADODB and PI OLEDB method

                           

                          Thank you,

                           

                          Vik

                            • Re: PI and MATLAB paper announced on twitter?
                              mhalhead

                              Daniel,

                               

                              I can't honestly tell you what the errors mean but there is a good change the problem is in the connection string; at a wild guess I would say the provider is incorrect. Techsupport would probably give you better support on this. However could I ask that you post a more detailed code snippet of connection setup (I would change the Data Source, Username and Password parameters, you shouldn't distribute that info).

                               

                              Below is a snippet of the connection string we're using:

                              ConnectStr = ['Provider=PIOLEDB;User ID=' dbUserName ';Password=' dbPassword ';Data Source=' dbSource ';Initial Catalog = ' archive ';Connection Timeout = 60'] 

                               

                              • Re: PI and MATLAB paper announced on twitter?

                                That "Invalid value for registry" makes me belive it's a "32-bit/64-bit mix" issue. Is it possible you installed the 64-bit PI OLEDB Provider with a 32-bit MATLAB?

                                  • Re: PI and MATLAB paper announced on twitter?
                                    Vikneshan

                                    Hi everyone,

                                     

                                     

                                     

                                    I m also using the PI OLEDB method prescribed in the white paper.

                                     

                                     

                                     

                                    I m having issues establish an adodb.connection

                                     

                                    ??? Invoke Error, Dispatch Exception:
                                    Source: ADODB.Connection
                                    Description: Provider cannot be found. It may not be properly installed.
                                    Help File: C:\Windows\HELP\ADO270.CHM
                                    Help Context ID: 12ee4f

                                    Error in ==> adodbcn at 29
                                    invoke(cn,'Open', cnstr);

                                    Error in ==> PI_CurrentValue at 29
                                        cn=adodbcn(cnstr);

                                     

                                    Any suggestions on how i could fix this? Please advice

                                     

                                    I m running the code on windows server 2008 rev2, not sure whether that matters.

                                     

                                    Thank you,

                                     

                                    Vikneshan

                                      • Re: PI and MATLAB paper announced on twitter?
                                        mhalhead

                                        Evening Vikneshan,

                                         

                                        We had a similar problem which was caused by the 32bit version of PI OLE DB being installed inadverently instead of the 64bit version. The fact that you are using Windows 2008R2 means that you have a 64bit system. I'm therefore assuming that you have installed the 64bit version of Matlab. This means that you will need the 64bit version of PI OLE DB.

                                          • Re: PI and MATLAB paper announced on twitter?
                                            Vikneshan

                                            Hi Michael,

                                             

                                             

                                             

                                            Thanks for the reply, I actually only have the 64bit PI OLEDDB installed. Could it be something else?

                                             

                                            Vikneshan

                                              • Re: PI and MATLAB paper announced on twitter?
                                                mhalhead

                                                Morning Vikneshan,

                                                 

                                                We did have a weird issue with the latest release of PI OLEDB; I don't know if this is causing your problem. We could run a query once through the PI OLEDB the second time you ran the query it would eventually timeout. The work around from techsupport was to down grade the PI SDK from 1.3.8 to 1.3.6. Before doing this I would stronglyrecommend that you contact techsupport as they are far better positioned that I am to provide this sort of advise; I've also found that their service is excellent.

                                                • Re: PI and MATLAB paper announced on twitter?
                                                  PIAdminUnison

                                                  Hi Guys,

                                                   

                                                  I am having problems with Matlab as well.  We are using Matlab 2010, PI-OLEDB 3.3.0.1(x86), and Windows 7 .  We are using the libraries from the vCampus site to try to get the data from PI OLEDB.  We run the demo routine and we get data without a problem.  We run the command a minute or so later and Matlab just hangs, i.e. we don't get our prompt back to issue a new command.  Any ideas?

                                                   

                                                  Jimmy

                                                    • Re: PI and MATLAB paper announced on twitter?
                                                      Ahmad Fattahi

                                                      Jimmy,

                                                       

                                                      What are you doing inside MATLAB? To narrow down the problem I would run the following tests:

                                                       

                                                      1)      Run something very simple inside MATLAB such as adding 1 to the input and returning. The goal is to make sure that there are no complications in the algorithm implemented inside MATLAB routines preventing it from converging to the solution, etc.

                                                       

                                                      2)      Can you take the PI side out as much as you can and push static values into MATLAB to see if it makes any difference?

                                                       

                                                      3)      Is it consistently hanging no matter what the value is, when you call it, if PI is involved or not?

                                                       

                                                      4)      If none of the above takes you anywhere maybe you can share some of your code here.

                                                        • Re: PI and MATLAB paper announced on twitter?
                                                          PIAdminUnison

                                                          Hi Ahmad,

                                                           

                                                          Here are the answers to your questions.

                                                           

                                                          Q1-2 We are just trying to run the PI_Demo.m script with our server credentials and no additional Matlab code.

                                                           

                                                          Q3 Yes, and the problem is “solved” by CTRL-ALT-DEL and forcing a closing then restart of Matlab

                                                           

                                                          Q4 attached

                                                           

                                                          [View:/cfs-file.ashx/__key/CommunityServer.Components.UserFiles/00.00.00.48.31/PI_5F00_Demo.m.txt]

                                                           

                                                          The code for Matlab is directly from your vCampus whitepapers.

                                                           

                                                          Later,

                                                           

                                                          Jimmy

                                                            • Re: PI and MATLAB paper announced on twitter?
                                                              Ahmad Fattahi

                                                              Unfortunately I can't see any attachments. is it me or you forgot to attach your code Jimmy?

                                                                • Re: PI and MATLAB paper announced on twitter?
                                                                  PIAdminUnison

                                                                  Hey Ahmad,

                                                                   

                                                                  Here is the code from the file.

                                                                  % % © Copyright OSIsoft, Inc.
                                                                  % This file is a demo of various MATLAB functions
                                                                  % that return data from PI via the PI OLEDB Provider.
                                                                  %
                                                                  % All these functions can be called with or without
                                                                  % the last parameter (the connection). Using this last
                                                                  % parameter makes subsequent calls much faster as the
                                                                  % time spent for establishing the connection is only
                                                                  % done once.

                                                                  % Change your PI Server name here
                                                                  server = 'svrpi1'

                                                                  % Build connection string
                                                                  cnstr = strcat('Provider=PIOLEDB.1;Data Source=',server,';Persist Security Info=False;Integrated Security = SSPI')

                                                                  % Open connection
                                                                  cn = adodbcn(cnstr)

                                                                  % % % % % % % % % % % % % % % % % % % % % % %
                                                                  % % % % % % % % % % % % % % % % % % % % % % %

                                                                  % Retrieves the current value for tag cdt158
                                                                  CurrentValue = PI_CurrentValue(server,'cdt158',cn)

                                                                  % Retrieves an archive value stored an hour ago for tag cdt158
                                                                  ArchiveValue = PI_ArchiveValue(server,'cdt158','*-1h',cn)

                                                                  % Retrieves the archived (compressed)
                                                                  % values for tag cdt158 during the last hour
                                                                  CompressedData = PI_CompressedData(server,'cdt158','*-1h','*',cn)

                                                                  % Retrieves the values for tag cdt158 on
                                                                  % sampled every 5 minutes during the last hour
                                                                  SampledData = PI_SampledData(server,'cdt158','*-1h','*','5m',cn)

                                                                  % Writes a value of 222 one hour ago, in tag cdt158
                                                                  WriteValue = PI_WriteValue(server,'cdt158','*-1h','222',cn)

                                                                  % Retrieves the list of tags that end with '158'
                                                                  TagSearch = PI_TagSearch(server,'*158',cn)

                                                                  % % % % % % % % % % % % % % % % % % % % % % %
                                                                  % % % % % % % % % % % % % % % % % % % % % % %

                                                                  % Close the connection
                                                                  invoke(cn,'close');
                                                                  %invoke(cn,'release')

                                                                  clear cn server cnstr;

                                                                  Later,

                                                                   

                                                                  Jimmy

                                                                    • Re: PI and MATLAB paper announced on twitter?
                                                                      Ahmad Fattahi

                                                                      Jimmy,

                                                                       

                                                                      Thanks for the code. I don't see any obvious problems; they work for me. Here are my troubleshooting suggestions:

                                                                       

                                                                      1) There is a possibility that we are having problems closing the connection and reconnecting. Could you create a loop for the portion between opening and closing the connection with a pause between every two iterations and see if you still experience the same problem? Something like this:

                                                                      for i = 1:10

                                                                      <Talking to the PI server to get values here as you have them already>

                                                                      pause (10)

                                                                      end

                                                                      This will wait 10 seconds before repeating the same commands talking to the PI server without closing the connection.

                                                                       

                                                                      2) If you look at PI SDK logs, do you see any trace of a second connection?

                                                                        • Re: PI and MATLAB paper announced on twitter?
                                                                          PIAdminUnison

                                                                          Hi Ahmad,

                                                                           

                                                                          My colleague did your above suggestion.  He ran it first at 8:46 AM and then again at 8:50.  The first time it iterated through the code 10 times without any problems.  The second time at 8:50, it hung during the first iteration.  Below is the information found in the PI-SDK log on the PI server.

                                                                           

                                                                           

                                                                           

                                                                          Severity, Program, Time, Message, Server, Collective, ID, Category, OriginatingHost, OriginatingOSUser, OriginatingPIUser, Priority, ProcessHost, ProcessOSUser, ProcessPIUser, ProcessID, Source1, Source2, Source3
                                                                          Debug, pinetmgr, 26/10/2010 8:46:16 a.m.,"PInet accepted TCP/IP connection, cnxn ID 1111 Hostname: , 192.168.152.33: 60718", SVRPI1, , 7004, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Information, pinetmgr, 26/10/2010 8:46:16 a.m.,"Connection accepted:     Process name:  MATLAB.exe(2436):remote(2436) ID: 1111", SVRPI1, , 7039, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Debug, pinetmgr, 26/10/2010 8:46:17 a.m.,"Connection ID: 1111 ; Process name: MATLAB.exe(2436):remote ; User: idPIUsers | PIWorld ; OS User: UNISON\Chris Reid ; IP: 192.168.152.33 ; AppID: 535 ; AppName: PI-OLEDB (connecting)", SVRPI1, , 7080, , , , , 10, , SYSTEM, , 7012, Connection Information, ,
                                                                          Information, pinetmgr, 26/10/2010 8:46:17 a.m.,"Successful login  ID: 1111. Address: 192.168.152.33. Name: MATLAB.exe(2436):remote. Identity List: idPIUsers | PIWorld. Environment Username : UNISON\Chris Reid. Method: Windows Login (SSPI,Kerberos)", SVRPI1, , 7082, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Information, pinetmgr, 26/10/2010 8:48:07 a.m.,"Deleting connection:  MATLAB.exe(2436):remote(2436), Shutdown request received from MATLAB.exe(2436):remote(2436), ID: 1111  192.168.152.33:60718", SVRPI1, , 7096, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Debug, pinetmgr, 26/10/2010 8:48:07 a.m.,"ID: 1111; Duration: 1.766667 min.; kbytes sent: 86.25488; kbytes recv: 19.13965; app: PI-OLEDB; user: idPIUsers | PIWorld; osuser: UNISON\Chris Reid; trust: ; ip address: 192.168.152.33; ip host: ", SVRPI1, , 7133, , , , , 10, , SYSTEM, , 7012, Connection Statistics, ,
                                                                          Debug, pinetmgr, 26/10/2010 8:48:07 a.m.,"Connection ID: 1111 ; Process name: MATLAB.exe(2436):remote ; User: idPIUsers | PIWorld ; OS User: UNISON\Chris Reid ; IP: 192.168.152.33 ; AppID: 535 ; AppName: PI-OLEDB (disconnecting)", SVRPI1, , 7079, , , , , 10, , SYSTEM, , 7012, Connection Information, ,
                                                                          Debug, pinetmgr, 26/10/2010 8:50:43 a.m.,"PInet accepted TCP/IP connection, cnxn ID 1112 Hostname: , 192.168.152.33: 60738", SVRPI1, , 7004, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Information, pinetmgr, 26/10/2010 8:50:43 a.m.,"Connection accepted:     Process name:  MATLAB.exe(2436):remote(2436) ID: 1112", SVRPI1, , 7039, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Debug, pinetmgr, 26/10/2010 8:50:43 a.m.,"Connection ID: 1112 ; Process name: MATLAB.exe(2436):remote ; User: idPIUsers | PIWorld ; OS User: UNISON\Chris Reid ; IP: 192.168.152.33 ; AppID: 535 ; AppName: PI-OLEDB (connecting)", SVRPI1, , 7080, , , , , 10, , SYSTEM, , 7012, Connection Information, ,
                                                                          Information, pinetmgr, 26/10/2010 8:50:43 a.m.,"Successful login  ID: 1112. Address: 192.168.152.33. Name: MATLAB.exe(2436):remote. Identity List: idPIUsers | PIWorld. Environment Username : UNISON\Chris Reid. Method: Windows Login (SSPI,Kerberos)", SVRPI1, , 7082, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Information, pinetmgr, 26/10/2010 8:54:51 a.m.,"Deleting connection:  MATLAB.exe(2436):remote(2436), Asynch read failed. [-10723] PINET: No Connection., ID: 1112  192.168.152.33:60738", SVRPI1, , 7121, , , , , 10, , SYSTEM, , 7012, , ,
                                                                          Debug, pinetmgr, 26/10/2010 8:54:51 a.m.,"ID: 1112; Duration: 4.116667 min.; kbytes sent: 85.91309; kbytes recv: 6.541016; app: PI-OLEDB; user: idPIUsers | PIWorld; osuser: UNISON\Chris Reid; trust: ; ip address: 192.168.152.33; ip host: ", SVRPI1, , 7133, , , , , 10, , SYSTEM, , 7012, Connection Statistics, ,
                                                                          Debug, pinetmgr, 26/10/2010 8:54:51 a.m.,"Connection ID: 1112 ; Process name: MATLAB.exe(2436):remote ; User: idPIUsers | PIWorld ; OS User: UNISON\Chris Reid ; IP: 192.168.152.33 ; AppID: 535 ; AppName: PI-OLEDB (disconnecting)", SVRPI1, , 7079, , , , , 10, , SYSTEM, , 7012, Connection Information, , 

                                                                           

                                                                           [View:/cfs-file.ashx/__key/CommunityServer.Components.UserFiles/00.00.00.48.31/PIMessageLog-_2D00_-MatLab.txt]

                                                                           

                                                                           

                                                                           

                                                                          Later,

                                                                           

                                                                          Jimmy

                                                                            • Re: PI and MATLAB paper announced on twitter?
                                                                              Ahmad Fattahi

                                                                              Jimmy,

                                                                               

                                                                              When I look at the PI SDK logs, I can't see any problems before it hangs. The connection is well established for the second time. However, it takes about 4 minutes (which is too long; should be less than 2 minutes) before it terminates the connection. Either it can't call the functions to retrieve data or fails to close the connection for the second time.

                                                                               

                                                                              I would tell MATLAB to print every single piece after retrieval so that we know where it hangs. Something like:

                                                                              
                                                                              

                                                                              % Retrieves an archive value stored an hour ago for tag cdt158
                                                                              ArchiveValue = PI_ArchiveValue(server,'cdt158','*-1h',cn)

                                                                              ArchiveValue

                                                                               

                                                                              and similarly done after each retrieval. it will show us where MATLAB will stop. Another possibility is that PI OLEDB can't get through to the PI server for some reason.

                                                                               

                                                                              At this point I would recommend you follow this up through our regular Tech Support as it seems we don't have fundamental programming problems (it works the first round after all). OSIsoft Tech Support is best suited and staffed to troubleshoot these cases and narrow down the problem to resolution.

                                                                               

                                                                              In case you have any more programming questions, we would be happy to address here on vCampus

                                                                               

                                                                               

                                                • Re: PI and MATLAB paper announced on twitter?
                                                  mmorris1984

                                                  In advance of the paper's release, can you specify how you accessed the data?  I am using ADODB objects and the PI-OLEDB for the data download, but I am interested in seeing if there is a performance advantage for using PI-SDK or other methods (e.g. database toolbox).

                                                    • Re: PI and MATLAB paper announced on twitter?

                                                      Here are the various methods I cover in the paper.

                                                      1. Using ADO and the PI OLEDB Provider
                                                      2. Using MATLAB's Database toolbox and the PI JDBC Driver
                                                      3. Using MATLAB's OPC Toolbox and the PI OPC DA Server
                                                      4. Using Integration Objects' OPC HDA Toolbox and the PI OPC HDA Server
                                                      5. Programmatically, using a mix of PI and MATLAB functions
                                                      6. Using comma-separated values (CSV) files

                                                      Once again, sorry for the delay... I got some good feedback from my colleagues and it took a little longer than expected to incorporate it (thanks to my 3 week leave!). Coming really soon, stay tuned!

                                                        • Re: PI and MATLAB paper announced on twitter?

                                                          Steve Pilon

                                                          Programmatically, using a mix of PI and MATLAB functions

                                                           

                                                          Just to add to this one: this is using MATLAB COM Automation Server and PI data under the form of objects like:

                                                          • A PIValues collection in PI ACE or PI SDK
                                                          • An AFValues collection in AF SDK
                                                          • DataSet object in ADO.NET (or a Recordset object in ADO)
                                                             --> using PI OLEDB or PI JDBC, for example

                                                          I also cover how one would make use of that in the context of PI ACE.