2 Replies Latest reply on Jan 11, 2011 2:40 AM by Ahmad Fattahi

    Simulink - PI connection issue



      Attempting to record multiple data points
      • We are attempting to include a MATLAB function in a certain point of a block diagram in Simulink in order to collect data from 3 - 5 streams simultaneously by means of a mux which sends the data to the MATLAB function as a vector.
      • The MATLAB function works by splitting the data contained in the vector, sending them to PI by means of a PI OLEDB connection, and outputting them again in a vector, so the simulation continues and iterates a specific number of times depending on the total time pre-defined for the simulation.
      • At this point there is a four-second delay each time the iteration passes over the MATLAB function, which contains a PI OLEDB connection for sending the values to PI. This delay is the time by default the connection takes to send data from MATLAB to PI and this could be OK for a short process we could run and for others in which we can tolerate small intervals of time, i.e. the simulation of control charts from random values.
      Slide 2

      The issue
      Slide 2
      • The problem is when we need to run a Simulation that tends to reach the steady state in a few seconds but after a number of iterations. We’re trying to record data in a more complex design where it is needed to collect all the exit streams (in our case 15 values) in one vector and send the data together to PI by means of a MATLAB function. In this case the connection with PI makes the simulation impractical because the normal reaching of the steady state of 3 seconds in Simulink changes to approximately 50 minutes when the PI OLEDB code is used. Even when it’s possible to handle (increase) the default simulation time in Simulink to analyze the process, the PI connection must not be a limitation to do this handling.
      • On the other hand, the computer interface becomes unmanageable in terms of maximizing and minimizing other windows, even to stop the simulation. We’d like to know if there is a way to put into the MATLAB function other kind of connection to PI or if it is necessary to use another technique to send data from Simulink to PI.
      The function code
      function [z, WriteVal] = MainExit(u)
      server = 'PI_SERVER';
      cnstr = strcat('Provider=PIOLEDB.1;Data Source=',server,';User ID=piadmin;Password=PI_SERVER;Persist Security Info=False;Connection Timeout=60');
      cn = adodbcn(cnstr);
      WriteVal = PI_WriteValue(server,'level sp/mA','*',num2str(F),cn);
      WriteVal = PI_WriteValue(server,'level/mA','*',num2str(G),cn);
      WriteVal = PI_WriteValue(server,'level PID OP/mA','*',num2str(H),cn);
      WriteVal = PI_WriteValue(server,'CW flow/mA','*',num2str(I),cn);
      WriteVal = PI_WriteValue(server,'CW flow PID OP/mA','*',num2str(J),cn);
      WriteVal = PI_WriteValue(server,'temp sp/mA','*',num2str(K),cn);
      WriteVal = PI_WriteValue(server,'temp/mA','*',num2str(L),cn);
      WriteVal = PI_WriteValue(server,'temp PID OP/mA','*',num2str(M),cn);
      WriteVal = PI_WriteValue(server,'level/cm','*',num2str(N),cn);
      WriteVal = PI_WriteValue(server,'CW flow/(cu.m/sec)','*',num2str(O),cn);
      WriteVal = PI_WriteValue(server,'temp/degC','*',num2str(P),cn);
      WriteVal = PI_WriteValue(server,'CW temp/degC','*',num2str(Q),cn);
      WriteVal = PI_WriteValue(server,'HW valve/mA','*',num2str(R),cn);
      WriteVal = PI_WriteValue(server,'HW flow/(cu.m/sec)','*',num2str(S),cn);
      WriteVal = PI_WriteValue(server,'HW temp/degC','*',num2str(T),cn);
      clear server cnstr cn;


        • Re: Simulink - PI connection issue
          Ahmad Fattahi

          Fifty minutes is definitely too long for passing tens of data points over. I have the following suggestions for you:

          • Please take a look at the White Paper we have on connecting MATLAB to PI (in OSIsoft vCampus Library > White Papers and Tutorials > Miscellaneous). You can find multiple ways of making the connection on top of PI OLEDB including PI JDBC/MATLAB Database Toolbox and PI OPC which you can definitely give a try if you have corresponding Toolboxes and OSIsoft products. However, you may also want to pay special attention to the PI SDK and programmatic way of doing that.
          • Please take a look at this post and this post on a thread on vCampus for another straightforward way making the connection.

           Please keep this thread updated as you progress so we all can see what the root cause was

            • Re: Simulink - PI connection issue
              Ahmad Fattahi

              Here is another point. You can go ahead and investigate the PI OLEDB logs to see where exactly the time is being spent. This is another option for you to troubleshoot your existing code. Please see PI OLEDB documentation under "Logging" to set the logging and its level to your desired detailed level.


              In any case, please keep this thread updated and let us know how your are progressing.