19 Replies Latest reply on Feb 14, 2017 3:50 PM by gregor

    Calc Failed when using Analysis

    PabloSatler

      Hi,

       

      so I have several Custom Data References (CDR) that perform calculations using a MATLAB routine. The attribute which the CDR is assigned to works fine on PI System Explorer (PSE). As shown on the screenshot below (blue arrows), it shows the current value on the "attributes tab" and also the Times Series Data correctly, so it's working as expected.

       

      piquestion.JPG

       

      So, my next goal is create an analysis to run on a certain time basis (periodic, let's say, every minute or every hour), storing the calculated values from that routine to a PI tag (PI point), so that we can view it from a visualization tool, such as ProcessBook. However, when I use the attribute that has the CDR (for example, "attribute2", shown in the figure below), what I get as result is "Calc Failed". Though, when I evaluate the analysis as well as when I preview the results on the "analysis tab" on PSE, it works well. 

      piquestion2.JPG

      piquestion3.JPG

       

      So, any ideas on how to solve this issue?

       

      Thank you!

       

       

       

      Version Information:

      PI System Explorer 2016 SP2 32-bit edition

      PI AF Server 2.8.0.7444

      Matlab R2015a (8.5.0.197613) 32-bit, and Matlab Runtime of the same version

      AF SDK 2.8.2.7626 .NET:v4.0.30319

        • Re: Calc Failed when using Analysis
          gregor

          Hello Pablo,

           

          Can you please check the Application Event Log on your PI Analysis Service host for messages from source PI Analysis Service?

           

          Also please verify running PI System Explorer (PSE) on the PI Analysis Service host if you can successfully evaluate.

            • Re: Calc Failed when using Analysis
              PabloSatler

              Hi Gregor.

              thank you for your reply.

               

              I asked the person responsible for the server to check such logs, and he said the message that appeared was the following:

               

              ANDataCache.TrackConnectionState[]: ANDataCache:ANPeriodicTimeClassManager: Calculations would only be scheduled till last successful event retrieval at 11-Jan-17 10:15:31.

               

              Though, when he evaluated the analysis using PSE on the host, it returned a good value, instead of "Calc Failed". So, just to be clear, on the tab Analysis, he was able to sucessfully evaluate. However, on the tab Attributes, the PI tag the receives the value from the analysis still returns "Calc Failed" (like shown in the first screenshot above).

                • Re: Calc Failed when using Analysis
                  gregor

                  Hi Pablo,

                   

                  I searched the Technical Support database for this error and stumbled across an internal known issue with AF Client 2.8.2

                  Can you upgrade the Analysis host with PI AF Client 2016 R2 SP1?

                  It may be a good idea to upgrade to PI Analysis Service 2016 R2. I haven't checked the release notes but believe it comes with PI AF Client 2016 R2 which should already contain the fix for the known issue. I however suggest installing PI AF Client 2016 R2 SP1.

                    • Re: Calc Failed when using Analysis
                      PabloSatler

                      Hello again Gregor,

                       

                      We've upgraded both PI Analysis Service and PI AF Client to the versions you suggested, but it have not solved the issue unfortunately. Like before, we still can successfully evaluate the analysis, though on the attributes tab it returns "Calc Failed".

                       

                      PIAnalysisService_Error2.JPG

                       

                      Earlier today, looking at the logs with the Windows Event Viewer, we've found the following error message:

                       

                      ANCalculationGroupStatusManager.SaveCalculationGroupStatusToLocalStore[]: Unable to save calculation group status (AccessDenied)

                      System.UnauthorizedAccessException: Access to the path 'C:\ProgramData\OSIsoft\PIAnalysisNotifications\CalculationGroupStatus.xml' is denied.

                         at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

                         at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)

                         at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)

                         at OSIsoft.AN.ANDataIO.StreamProvider.GetStream(String fullPath, FileMode mode, FileAccess access, FileShare share, Result& result)

                        • Re: Calc Failed when using Analysis
                          gregor

                          Hello Pablo,

                           

                          The new error indicates missing write permissions of the account running PI Analysis Service to C:\ProgramData\OSIsoft\PIAnalysisNotifications\CalculationGroupStatus.xml

                           

                          Can you please verify this?

                            • Re: Calc Failed when using Analysis
                              PabloSatler

                              Hi Gregor,

                               

                              first of all, sorry for the delayed answers. As I'm not the server's administrator, I first pass the suggestions you gave me to him, and then I wait for his feedback. That's why is taking some time to answer you back.

                               

                              Talking about the analysis issue, the server's administrator tried to change the PI Analysis Service to an administrator account, with all privileges (read/write permissions). However, even doing this we still receive the "Calc Failed" message on the attributes tab. We did this based on this OSIsoft article. So. if this is not the right way to edit/change the permissions, can you explain a little more how one can verify the write permissions to such files, like the C:\ProgramData\OSIsoft\PIAnalysisNotifications\CalculationGroupStatus.xml file?

                               

                              Also, is there any other way to troubleshoot this? I mean, I tried using try-catches blocks on my code, for example, though no error or exception was caught. But I think the code is OK, once I can successfully evaluate. I'm saying that because the message "Calc Failed" is too vague for me, so I'm not being able to identify the real cause of the problem. Any other ideas will be greatly appreciated.

                               

                                • Re: Calc Failed when using Analysis
                                  gregor

                                  Hello Pablo,

                                   

                                  To verify the file permissions, open Windows Explorer, locate the file, select it, right click and chose 'Properties'. In the Properties Dialog, click the Security tab, click the button labeled 'Advanced' to open the 'Advanced Security' Dialog. Under 'Effective Permissions' you can chose a user and verify what access this user has.

                                   

                                  I've verified with my installation and found that 'C:\ProgramData\OSIsoft\PIAnalysisNotifications\CalculationGroupStatus.xml' exists, so it appears to belong to PI Analytics Service. I also checked our call database but it appears we haven't seen the problem you are experiencing before. It may make sense to continue troubleshooting in the context of a Technical Support case.

                                   

                                  I agree that 'Calc Failed' is a very generic error that does not contain any hints where to look at. What usually helps is trying to change the scope by changing on thing at time. Can you please see if you can configure your Analysis to output to a PI Point rather than your Custom Data Reference (CDR)?

                                   

                                  Can you please also verify if your CDR implements an override for UpdateValue and UpdateValues? Which of these methods is used will likely depend on the Analysis but I would assume that under normal conditions it would use UpdateValue. By the way, what Data Source is your CDR connecting to? Does the PI Analysis Service host have access to that Data Source and the account executing the service have write access to that Data Source?

                                    • Re: Calc Failed when using Analysis
                                      PabloSatler

                                      Hi Gregor,

                                       

                                      Can you please see if you can configure your Analysis to output to a PI Point rather than your Custom Data Reference (CDR)?

                                      I perhaps may be mistaken, but I believe my analysis is already outputting to a PI Point. My analysis is an expression analysis. I get the current value from the attribute assigned to my CDR and store this value in a PI Point (in a mapped PI Point, like explained in this video). The function I'm using is TagVal. Below there is a figure of my analysis tab.

                                       

                                      analysisPIForum.JPG

                                       

                                      Can you please also verify if your CDR implements an override for UpdateValue and UpdateValues?

                                      I'm not overriding either UpdateValue or UpdateValues. I'm using their base implementation. Should I override them? I'm instead overriding GetValue to return the values. Below are my Supported Data Methods and Supported Methods:

                                       

                                      public override AFDataReferenceMethod SupportedMethods

                                              {

                                                  get

                                                  {

                                                      return AFDataReferenceMethod.GetValue | AFDataReferenceMethod.GetValues | AFDataReferenceMethod.SetValue;

                                                  }

                                              }

                                       

                                      public override AFDataMethods SupportedDataMethods

                                              {

                                                  get

                                                  {

                                                      return AFDataMethods.RecordedValue |

                                                          AFDataMethods.RecordedValues |

                                                          AFDataMethods.InterpolatedValue |

                                                          AFDataMethods.InterpolatedValues |

                                                          AFDataMethods.InterpolatedValuesAtTimes |

                                                          AFDataMethods.PlotValues |

                                                          AFDataMethods.Summary | AFDataMethods.Summaries |

                                                          AFDataMethods.UpdateValue | AFDataMethods.UpdateValues |

                                                          AFDataMethods.DataPipe;

                                                      //return base.DefaultSupportedDataMethods;

                                                  }

                                              }

                                      By the way, what Data Source is your CDR connecting to? Does the PI Analysis Service host have access to that Data Source and the account executing the service have write access to that Data Source?

                                      The Data Source to my CDR are other PI Points (attributes). I'm overriding GetInputs to obtain the attribute's name. Currently, I'm using the PI Point CDT158 as an input source to my CDR, in order to test it. I believe both the PI Analysis Service and the account executing the service have the needed access privileges, because I have another Analysis (one that uses a CDR that does not have any Matlab Algorithm, only .NET ones) and  I'm able successfully map the results of that analysis to a PI Point.

                                        • Re: Calc Failed when using Analysis
                                          gregor

                                          Hi Pablo,

                                           

                                          I was under the impression 'Calc Failed' happens when you try to write back through you CDR. Please accept my apologies and thank you for the clarification!

                                          The screenshot indicates you are just using TagVal() function against your CDR and attempt to write back the result to a PI Point named Analysis2_Output_Matlab

                                          Can you please verify the data type returned by your CDR and the data type of Analysis2_Output_Matlab?

                                          Also, please verify the point security of Analysis2_Output_Matlab against Analysis2_Output_C# because PI Analysis Service appears to be able to service that point.

                                           

                                          Please forget about UpdateValue and UpdateValues but is your CDR implementing a ConfigString method?

                                            • Re: Calc Failed when using Analysis
                                              PabloSatler

                                              Hi Gregor,

                                               

                                              The screenshot indicates you are just using TagVal() function against your CDR and attempt to write back the result to a PI Point named Analysis2_Output_Matlab

                                              Exactly right. I want to store the values from the analysis to a PI Point so I can have a history of those values throughout the time.

                                              Can you please verify the data type returned by your CDR and the data type of Analysis2_Output_Matlab?

                                              Also, please verify the point security of Analysis2_Output_Matlab against Analysis2_Output_C# because PI Analysis Service appears to be able to service that point.

                                              My CDR returns an AFValue, but I assign the result of the Matlab routine as a Double. Just to be clear, the method "rotinaMatlab" returns a Double. Below there is a part of the GetValue's code.

                                               

                                              public override AFValue GetValue(object context, object timeContext, AFAttributeList inputAttributes, AFValues inputValues)

                                                      {

                                                             ......

                                                             ......

                                                          AFValue matlabResult = new AFValue();

                                                          matlabResult.Value = this.rotinaMatlab(values, nc, alfa); //Matlab routine is being used/called  

                                                          matlabResult.Timestamp = endTime; //Setting a time stamp  

                                                          return matlabResult;

                                                      }

                                               

                                              The data type of Analysis2_Output_Matlab is Float64, but so is the data type of Analysis2_Output_C#. I took a screenshot to show the data type and the point security. Both the PI Points Analysis2_Output_Matlab and Analysis2_Output_C# have identical values. 

                                               

                                              pipointAccess_analysis.JPG

                                               

                                              Please forget about UpdateValue and UpdateValues but is your CDR implementing a ConfigString method?

                                              Yes, and my ConfigString method is very similar to the one shown in this video.

                                                • Re: Calc Failed when using Analysis
                                                  gregor

                                                  Hi Pablo,

                                                   

                                                  Can you please post a screenshot showing the configuration details of Attribute Analysis2_Output_Matlab?

                                                    • Re: Calc Failed when using Analysis
                                                      PabloSatler

                                                      Hi Gregor,

                                                       

                                                      Here it is:

                                                       

                                                      ConfigurationDetails_PIPoint_Analysis_Matlab.JPG

                                                        • Re: Calc Failed when using Analysis
                                                          gregor

                                                          Hi Pablo,

                                                           

                                                          As far as I can see the Analysis configured to write against Analysis2_Output_Matlab is Analysis2.Variable1. It uses TagVal('Attribute6'), so Attribute6 is the input for this Analysis. Is Attribute6 configured to read from your CDR or where does your CDR come into play? Can you please share the configuration for Attribute6 as well?

                                                            • Re: Calc Failed when using Analysis
                                                              PabloSatler

                                                              Hi Gregor,

                                                               

                                                              Attribute6 is where my CDR comes into play. Below is the screenshot asked:

                                                               

                                                              ConfigurationDetails_DataReference_Matlab.JPG

                                                                • Re: Calc Failed when using Analysis
                                                                  gregor

                                                                  Thank you Pablo!

                                                                   

                                                                  I don't see anything wrong with your configuration and it appears your CDR is working properly, at least on your client.

                                                                  Is the PI Analysis Service running on a remote host?

                                                                  Have you registered your CDR and the Matlab library it is depending on? Are there additional dependencies?

                                                                  Can you please verify with PSE on a different client if Attribute6 is reporting is showing good there too?

                                                                    • Re: Calc Failed when using Analysis
                                                                      PabloSatler

                                                                      Hi Gregor,

                                                                       

                                                                      Is the PI Analysis Service running on a remote host?

                                                                      No. It is running on the same machine where the PI AF Server is installed.

                                                                       

                                                                      Have you registered your CDR and the Matlab library it is depending on? Are there additional dependencies?

                                                                      Yeah. When I register my CDR using regplugin I've put as support assembly the file MWArray.dll, which has the MATLAB library, and also the file algorithmName.dll, which has the algorithm used, built in MATLAB. Also, it's been installed both on the client and the host machines the MATLAB Runtime, so the MATLAB algorithm used by the CDR can run properly. I don't know/think there is additional dependencies yet to be registered.

                                                                       

                                                                      Can you please verify with PSE on a different client if Attribute6 is reporting is showing good there too?

                                                                      I did verify using PSE on another client and the issue is the same: being able to successfully evaluate but receiving "Calc Failed" on the attributes tab. And the attribute6 reports good there as well.

                                                                        • Re: Calc Failed when using Analysis
                                                                          gregor

                                                                          Hello Pablo,

                                                                           

                                                                          You've used regplugin to register your CDR and the assembly (MWArray.dll) it depends on. Do I understand correctly, that MWArray.dll implements functionality exposed by a MATLAB and another library which you did not register?

                                                                           

                                                                          Does the MATLAB library and algorithmName.dll exist in the GAC on any of the machines involved with your testing?

                                                                           

                                                                          Custom Data References are executed client side. To ensure the client has access and to simplify deployment, you register the library representing your CDR and libraries your CDR depends on. When a client e.g. PI System Explorer connects, the CDR and libraries it depends on become downloaded to the client. If you don't have all the libraries a CDR depends on available on the client, you very likely run into issues of the kind you are experiencing it.

                                                                           

                                                                          Another possible issue could be due to a 32-/64-bit conflict. When you install PI AF Client, PI System Explorer becomes installed in 2 flavors, a 32-bit and a 64-bit version (except your OS is just 32-bit). Have you tried the "other" flavor? AF SDK is compiled to "Any CPU" meaning that it will work with 32-bit and 64-bit. Can you please verify for which platform involved libraries are built?

                                                                           

                                                                          While thinking about additional possible reasons with many dependency libraries, can you please also verify other dependencies like specific .NET Framework versions required?

                                                                           

                                                                          Since the scope of your CDR involves many dependencies, you may want to try off very simple e.g. by reproducing one of the CDR samples. I just checked and none of the examples has a dependency on another library but you could take it from simple to advanced by adding dependencies one-by-one and test each "version".

                                                                            • Re: Calc Failed when using Analysis
                                                                              PabloSatler

                                                                              Hi Gregor,

                                                                               

                                                                              You've used regplugin to register your CDR and the assembly (MWArray.dll) it depends on. Do I understand correctly, that MWArray.dll implements functionality exposed by a MATLAB and another library which you did not register?

                                                                              I think I answered you wrongly. Sorry about that. MWArray, as shown here and here, is instead a MATLAB array wrapper class for .NET.

                                                                              Does the MATLAB library and algorithmName.dll exist in the GAC on any of the machines involved with your testing?

                                                                              MWArray does exist, though algorithmName.dll didn't. So, after some research I did manage to make it strong-named, and installed it in GAC.

                                                                              Another possible issue could be due to a 32-/64-bit conflict. When you install PI AF Client, PI System Explorer becomes installed in 2 flavors, a 32-bit and a 64-bit version (except your OS is just 32-bit). Have you tried the "other" flavor? AF SDK is compiled to "Any CPU" meaning that it will work with 32-bit and 64-bit. Can you please verify for which platform involved libraries are built?

                                                                              All the libraries involved were built to work with 32-bit, because all the Matlab algorithms that we have were targeted to that platform. The host is a 64-bit machine with Windows Server 2012 R2 Essentials, just to let you know. It had previously only the Matlab Runtime 32-bit installed. So, following your suggestion, we've installed the Matlab Runtime 64-bit on the host machine and it looks like it did the trick, because we are now receiving good values instead of "Calc Failed" (like shown in the picture below). I've also compiled my matlab assembly (algorithmName.dll) to target the 64-bit platform as well, just to make sure everything was built to that platform. However, I've tested some 32-bit algorithms trying to understand what caused the error and see if the error appears again using those algorithms, but it didn't, so we are being able to run analysis built in 32-bit too.

                                                                               

                                                                              analysisPIForumGoodValues.JPG

                                                                              So, the issue probably was due to this conflict between platforms. I will make more tests, but for now I can say my issue is solved.

                                                                               

                                                                              Thanks a lot for your patience and help.

                                                                              1 of 1 people found this helpful