23 Replies Latest reply on Mar 5, 2015 3:17 PM by Nicolas.Isambourg

    [PI-SQC] How to refresh automatically the SQC control chart

    Nicolas.Isambourg

      Hello,

       

      I developed a .NET application (named MQLab) that adds values to a PI Point with the PIData.UpdateValue method of PI-SDK.

      I'm developing another .NET application embedding the PI-SQC control chart of PI-ProcessBook through PI-ActiveView.

      The chart tag is the PI Point whose values are added by my .NET application "MQLab".

       

      I want the control chart to be automatically refreshed when a new value is added.

      A new value is automatically plotted on the control chart when at least 1 value is already plotted on the chart.

      At a moment, I set the type of the time scale to "sqcAbsoluteTime", the starttime to DateTime.Now (DateTime format: dd/MM/yyyy hh:mm) and the endtime to *. At this moment, no data point are plotted on the control chart (that's normal). After this, when the snapshot of the PI Point is updated, the new value isn't plotted on the control chart.

      It doesn't work any more when I call the Refresh method or reset the definition of the SQC control chart.

       

      Is there a workaround to refresh the chart automatically each time a new value is added ?

       

      Thanks,

      Best regards,

      Nicolas

        • Re: [PI-SQC] How to refresh automatically the SQC control chart
          bshang

          Hi Nicolas,

           

          The SQC Chart should automatically update based on the ProcessBook update rate. By default, this is every 5 seconds. Just to make sure there are no data retrieval issues outside of SQC, can you create a simple Trend symbol with the chart tag in question? Does the data trend properly for this tag and does the trend update when new values are inserted? Assuming this works, then please paste the relevant sections of your SQC VBA code here and we can take a closer look for any potential issues.

           

          In regards to whether or not the chart can automatically update when a new value is added, this won't be possible, as ProcessBook must poll the PI Server (based on the update rate) to retrieve new values. However, if the code being used to update the chart tag value exists along with the VBA code being used to reset and refresh the SQC chart, then you can execute these operations together to programmatically refresh the SQC chart and get the new values immediately. However, since a separate application is being used to update the chart tag value, then the ProcessBook client must poll the PI Server to get new values and place them on the chart.

           

          Barry

            • Re: [PI-SQC] How to refresh automatically the SQC control chart
              Nicolas.Isambourg

              Hello Barry,

               

              thank you for replying.

              I added a Trend symbol on the same display.

              When a new value is added :

              - the value is automatically plotted on the Trend symbol

              - the value is plotted on the SQC Symbol if at least 1 value is already plotted on the chart. If no value is plotted, the new value will not be plotted.

               

              Here is the source code of the method that adds a new value to a PI Point. This method is called in the .NET application "MQLab":

              Code:

              private void AddValueToPIPoint(double value, string pointName)
              {
                  if ((this.SdK == null) || (this.PIServer == null))
                  {
                      this.SdK = new PISDKClass();
                      this.PIServer = this.SdK.Servers.DefaultServer;
                  }
              
                  if (!this.PIServer.Connected)
                      this.PIServer.Open();
              
                  PIPoint pt = this.PIServer.PIPoints[pointName];
                  pt.Data.UpdateValue(value, 0);
              }
              

              Here is the source code of the method that adds and configures a SQC Symbol in the display. This method is called in the .NET application "SQC Monitoring":

              Code:

              private SQCSymbol AddAndConfigureSQCSymbol(Display display)
              {
                   // Ajout du Trend au display
                   SQCSymbol.SQCSymbol sqcSymb = (SQCSymbol.SQCSymbol)display.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolSQC);
                   if (sqcSymb != null)
                   {
                        var spcDefinition = spcTrend.GetDefinition();
                        spcDefinition.ChartType = ChartTypeEnum.sqcIndividuals;
                        spcDefinition.SetCalculationBasis(SamplingTypeEnum.sqcEventBased, 1, 1, null, null, null);
                        spcDefinition.SetVerticalScale(ScaleTypeEnum.sqcCenterline5Sigma, ScaleTypeEnum.sqcCenterline5Sigma);
                        spcDefinition.SigmaCalcMethod = SigmaCalcEnum.sqcSigmaRange;
                        spcDefinition.SetPlotTime(StartTypeEnum.sqcAbsoluteTime, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "*");
                        // etc.
                        sqcSymb.SetDefinition(spcDefinition);
                   }
              
                   return sqcSymb;
              }
              

              Thanks,

              Nicolas

                • Re: [PI-SQC] How to refresh automatically the SQC control chart
                  bshang

                  Hi Nicolas,

                   

                  In the method AddAndConfigureSQCSymbol(), the spcDefinition.ChartTag property does not appear to be getting set. This might explain why new values are not added even when Refresh/Reset is called on the SQC trend. Could you try adding something like

                   

                  var spcDefinition = spcTrend.GetDefinition();

                  spcDefinition.ChartTag = pointName;


                  You might need to pass in the string pointName into the  AddAndConfigureSQCSymbol() method as well if there isn't a reference to it already.

                    • Re: [PI-SQC] How to refresh automatically the SQC control chart
                      Nicolas.Isambourg

                      Hello Barry,

                       

                      Sorry, I forgot a part of the code. I configure the control limits in an other method:

                       

                      private void ConfigureControlLimits(SQCSymbolDefinition spcDef, string source, string cL, string lCL, string uCL)

                              {

                                  spcDef.ChartTag = source;

                                  spcDef.SetLimit(LimitEnum.sqcCL, LimitTypeEnum.sqcPITag, cL);

                                  spcDef.SetLimit(LimitEnum.sqcLCL, LimitTypeEnum.sqcPITag, lCL);

                                  spcDef.SetLimit(LimitEnum.sqcUCL, LimitTypeEnum.sqcPITag, uCL);

                                  spcDef.SetLimit(LimitEnum.sqcLSL, LimitTypeEnum.sqcNoLimit, null);

                                  spcDef.SetLimit(LimitEnum.sqcUSL, LimitTypeEnum.sqcNoLimit, null);

                              }

                       

                      Barry Shang a écrit:

                       

                      This might explain why new values are not added even when Refresh/Reset is called on the SQC trend.

                      Actually, it isn't exactly this. New values are added when at least 1 value is already plotted on the chart.

                      The problem occurs when there is "no or not enough data points" on the chart:

                       

                      Thanks,

                      Best regards,

                      Nicolas

                    • Re: [PI-SQC] How to refresh automatically the SQC control chart
                      bshang

                      Another issue you may be running into is that the SQC symbol only displays the archived events, unlike Trend symbol which displays the snapshot events as well (unless reset). Therefore, when a new event is added, it will show up in the Trend, but not yet in the SQC symbol. If an additional event is added, then this former snapshot will be pushed to the archive (assuming not compressed out) and will show up in the SQC symbol.

                       

                      Nicolas, could you try to test out the above on your side? Please turn off compression for the SQC Chart Tag, then input 2 values. In the SQC trend, only the first value should appear.

                       

                      The reason why the SQC plot will show only the archived events is because the SQC statistical parameters are calculated from the archived events, and those are the ones that should be displayed in the SQC plot.

                        • Re: [PI-SQC] How to refresh automatically the SQC control chart
                          Nicolas.Isambourg

                          Hello Barry,

                           

                          Tech Support suggested me to re-set the SPC definition to force the chart refresh.

                           

                          Code:

                          sqcTrend.SetDefinition(sqcTrend.GetDefinition())

                           

                          So, to summarize, when there is at least 1 data point on the chart, all new values are automatically added on the chart.

                          When I re-set the plot time (as below), no data points is on the chart.

                          spcDefinition.SetPlotTime(StartTypeEnum.sqcAbsoluteTime, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "*");

                           

                          The new values aren't added automatically on the chart.

                          I have to re-set the SPC definition:

                          sqcTrend.SetDefinition(sqcTrend.GetDefinition());

                           

                          After this, all new values are automatically added on the chart.

                          Now, the problem is: how to know when I have to re-set the SPC definition because I don't know when there is a new value.

                           

                          Thanks,

                          Best regards,

                          Nicolas Isambourg

                            • Re: [PI-SQC] How to refresh automatically the SQC control chart
                              gregor

                              Hi Nícolas,

                               

                              I understand after you set the plot time

                              spcDefinition.SetPlotTime(StartTypeEnum.sqcAbsoluteTime, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "*");
                              

                              No new values (events) are added automatically unless you set the definition

                              sqcTrend.SetDefinition(sqcTrend.GetDefinition());
                              

                              Your question, if I understand correctly, is how to know when you need to set the definition.

                               

                              How about setting the trend definition right after setting the plot time?

                              If you are in doubt, you can offer users a button they can press to force setting the definition.

                              • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                bshang

                                Hi Nicolas,

                                 

                                I would have the same suggestion as Gregor above. In general, the SQC Symbol definition should be reset if any part of its definition object is modified. This forces a redraw of the symbol with the updated definition.

                                 

                                After the reset, Processbook will ask the PI server if any new values for the chart tag have come in (by default, it does this every 5 seconds). If there are new values, then they will be added to the SQC trend. Let us know if we've understood your question correctly.

                                  • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                    Nicolas.Isambourg

                                    Hello Barry and Gregor,

                                     

                                    Gregor Beck:

                                    No new values (events) are added automatically unless you set the definition

                                     

                                    That's correct.

                                     

                                    Barry Shang a écrit:


                                    After the reset, Processbook will ask the PI server if any new values for the chart tag have come in (by default, it does this every 5 seconds). If there are new values, then they will be added to the SQC trend.

                                    Only if some values are already plotted on the SQC trend.

                                     

                                    Here is an example:

                                    Suppose there are 3 data points on a SQC trend.

                                     

                                    1. The chart tag value is updated, the value is automatically added to the SQC trend.

                                    2. I set the plot time: spcDefinition.SetPlotTime(StartTypeEnum.sqcAbsoluteTime, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "*");

                                    3. Then I reset the definition: sqcTrend.SetDefinition(sqcTrend.GetDefinition()); There is no data point on the SQC chart.

                                    4. The chart tag value is updated, the value is not automatically added to the SQC trend.

                                    5. The chart tag value is updated, the value is not automatically added to the SQC trend.

                                    6. I reset the definition. The 2 previous values are plotted on the SQC trend.

                                     

                                    So, I have to reset the definition after new values are added to the chart tag.

                                    How do I know when new values are added to the chart tag ? Do I need to use Event Pipe ?

                                     

                                    Thanks,

                                    Best regards,

                                    Nicolas

                                      • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                        gregor

                                        Hello Nicholas,

                                         

                                        Nicolas Isambourg wrote:

                                         

                                        2. I set the plot time: spcDefinition.SetPlotTime(StartTypeEnum.sqcAbsoluteTime, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "*");

                                         

                                         

                                        I recall this line confused me before but I am not sure if the issue that you're facing is related to the fact that you initialize the SQCSymbol with a period of 0s. The StartTime representation is a fixed TimeStamp however while "*" results into now() at every evaluation.

                                        Another thing is that the SQCSymbol is designed for the usage within ProcessBook. Using the control outside the ProcessBook context may cause unwanted behavior and makes it more difficult for us to reproduce the issue.

                                        The next thing that I stumbled across is that you don't seem to apply the changed definition (spcDefinition).

                                        Have you tried doing this:

                                         

                                        spcDefinition.SetPlotTime(StartTypeEnum.sqcAbsoluteTime, DateTime.Now.ToString("dd/MM/yyyy HH:mm"), "*");
                                        sqcTrend.SetDefinition(spcDefinition);
                                        

                                         

                                         

                                        I have created a test with a button to increase the StartTime, one button to decrease the StartTime, a Label that I use to display the current StartTime setting and to generate the string. Each time the user clicks either the button for increasing or decreasing the Label is updated with the new StartTime and the new StartTime is assigned to the SQC Symbol.

                                         

                                        Dim iSQCStartTime As Integer
                                        Private Sub btnDec_Click()
                                            If iSQCStartTime = Null Then
                                                iSQCStartTime = -10
                                            Else
                                                iSQCStartTime = iSQCStartTime - 10
                                            End If
                                            ApplyNewStartTime (iSQCStartTime)
                                        End Sub
                                        Private Sub btnInc_Click()
                                            If iSQCStartTime = Null Then
                                                iSQCStartTime = -10
                                            Else
                                                iSQCStartTime = iSQCStartTime + 10
                                            End If
                                            ' Let's consider StartTime in future illegal
                                            If iSQCStartTime > 0 Then iSQCStartTime = 0
                                            ApplyNewStartTime (iSQCStartTime)
                                        End Sub
                                        Private Sub ApplyNewStartTime(iStartTime As Integer)
                                            If (iStartTime = 0) Then
                                                StartTimeLabel.Caption = "*"
                                            Else
                                                StartTimeLabel.Caption = "*" & Str(iStartTime) & "m"
                                            End If
                                            Dim spcDef As SQCSymbolDefinition
                                            Set spcDef = SQCSymbol1.GetDefinition()
                                            spcDef.SetPlotTime sqcAbsoluteTime, StartTimeLabel.Caption, "*"
                                            SQCSymbol1.SetDefinition spcDef
                                        End Sub
                                        

                                         

                                        I am attaching the display to this post. Maybe we can use it to see if what you are trying to accomplish generally works with the SQC Symbol in ProcessBook

                                          • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                            Nicolas.Isambourg

                                            Hello Gregor,

                                             

                                            Another thing is that the SQCSymbol is designed for the usage within ProcessBook.

                                            Do you think I shouldn't use the SQC Symbol in my .NET application. I should use a SQC .NET component ?

                                             

                                            Using the control outside the ProcessBook context may cause unwanted behavior and makes it more difficult for us to reproduce the issue.

                                            When I use the control in ProcessBook (in a display I created), the new values are never added to the SQC trend. For each new value, I need to reset the definition after the value is updated.

                                            The next thing that I stumbled across is that you don't seem to apply the changed definition (spcDefinition).

                                            Have you tried doing this:

                                            Yes, I have. That doesn't fix the issue.

                                             

                                            I tested your display. Whatever the starttime value, the new values are never added automatically to the SQC trend.

                                             

                                            Thanks,

                                            Best regards,

                                            Nicolas

                                              • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                gregor

                                                Hello Nicolas,

                                                 

                                                When I use the test display and even after using the buttons to adjust the StartTime, each new event for CDT158 as well updates the SQC Symbol. If the same doesn't work for you, the issue might have a different source than that your code isn't working. I've created the test display with ProcessBook 2014 (3.4.0.251). What version are you running? Also the issue might be with lost sign-up for updates. Can you see if a Trend symbol updates for you?

                                                I have modified the test display by adding a Trend symbol and also setting StartTime via code. This will make it easier for you to see when what is updating.

                                                  • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                    Nicolas.Isambourg

                                                    Hello Gregor,

                                                     

                                                    I made a mistake. I replied too fast.

                                                    In PI-ProcessBook, whatever the starttime value, the new values are well and truly added automatically to the SQC trend.

                                                    However, if your display is embedded in PI-ActiveView, the new values aren't added automatically to the SQC trend when the starttime value is set to the current date and time.

                                                     

                                                    So the behaviour of the PI-SQC symbol is different between PI-ActiveView and PI-ProcessBook.

                                                     

                                                    Nicolas

                                                      • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                        gregor

                                                        Hello Nicolas,

                                                         

                                                        SQC02.pdi is working for me with PI ActiveView too. What version of PI ProcessBook and PI ActiveView do you have installed?

                                                          • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                            Nicolas.Isambourg

                                                            Hello Gregor,

                                                             

                                                            thank you for replying.

                                                            SQC02.pdi is working for me with PI ActiveView too.

                                                            When the starttime value is the current date and time ?

                                                             

                                                            My version of PI-ProcessBook is 3.4.0.251 and my version of PI-ActiveView is 3.4.0.279.

                                                             

                                                            Thanks,

                                                            Best regards,

                                                            Nicolas

                                                              • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                                gregor

                                                                Hello Nicolas,

                                                                 

                                                                I am using the exact same versions of PI ProcessBook and PI ActiveView.

                                                                The most recent StartTime with SQC02.pdi is *-10m. My attempt to set the StartTime of the Trend symbol to current time through VBA, raised runtime error 8324: Time Specifications are Invalid. Hence I've tweaked the code to consider *-10m the maximum possible.

                                                                SQC01.pdi allows setting the StartTime to current time and this works within ActiveView too but at least with SQC01.pdi I don't see this makes much sense because it will result the SQC chart becoming initialized with StartTime and EndTime equal to current time. The control will look like shown in below screenshot and for sure never update because of the time boundaries (please see second picture).

                                                                 

                                                                40707_01.jpg

                                                                40707_02a.jpg

                                                                  • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                                    Nicolas.Isambourg

                                                                    Hello Gregor,

                                                                     

                                                                    For example, on the below screenshot, I set the starttime to the current time then I save the display.

                                                                     

                                                                    In PI-ProcessBook, the new values will be added automatically to the trend. In PI-ActiveView, they will not added.

                                                                     

                                                                    So, it seems there isn't solution to my problem.

                                                                     

                                                                    Thanks,

                                                                    Best regards,

                                                                    Nicolas

                                                                      • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                                        gregor

                                                                        Hello Nicolas,

                                                                         

                                                                        I understand that you are interested in setting StartTime to now but not by using a "*" which indicates relative time but by using Now() and converting the returned Date into a time representing string. With this approach you are initiating the SQC Chart with a period of 0 seconds that grows over time because you specify EndTime as relative time "*".

                                                                        I've experimented a bit more with the SQC Chart control on ProcessBook and my observation is that the SQC Chart becomes only updated automatically if the initial period covers at least 2 events or with other words, the PI Point has 2 events for the period the SQC Chart becomes initialized with. If the amount of events is smaller than 2, the SQC Chart doesn't update.

                                                                        I've further looked into the option to initialize the SQC Chart with an amount of events before EndTime (StartType=sqcSamplesBeforeEnd). Using this option with an amount of Samples < 5 generates an error.

                                                                        40814.jpg

                                                                        It appears to me as if the developers of the SQC Chart Symbol considered a smaller amount of samples illegal. Even with < 10 samples the chart displays "Not enough samples"

                                                                        40814_2.jpg

                                                                        What I recall about statistic calculations is a bit rusty but I believe to recall that applying a calculation, requires at least 2 or 3 samples. What I don't know is with how many samples statistics can be considered reliable but it's obvious that results become better, the more samples are used.

                                                                        To close the circle, can you please explain why you like to initiate the SQC chart with StartTime=Now()? What's the use case for this?

                                                                          • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                                            Nicolas.Isambourg

                                                                            Hello Gregor,

                                                                             

                                                                            thanks again for your help.

                                                                            We need to group the values by SQC test campaign.

                                                                            We want to plot on the chart only the values of a SQC campaign.

                                                                            When a new campaign begins, we need to reset the SQC control chart. So I initiate the SQC chart with StartTime=Now() when a new campaign begins.

                                                                             

                                                                            Thanks,

                                                                            Best regards,

                                                                            Nicolas

                                                                              • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                                                gregor

                                                                                Hello Nicolas,

                                                                                 

                                                                                The solution I am suggesting involves a Trend. I have created the following 2 routines to apply StartTime and EndTime to the Trend / SQC Chart

                                                                                 

                                                                                Private Sub SetPBTrend(sStart As String, sEnd As String)
                                                                                    Dim bSuccess As Boolean
                                                                                    bSuccess = Trend1.SetTimeRange(sStart, sEnd)
                                                                                End Sub
                                                                                
                                                                                Private Sub SetSQCTrend(sStart As String, sEnd As String)
                                                                                    Dim spcDef As SQCSymbolDefinition
                                                                                    Set spcDef = SQCSymbol1.GetDefinition()
                                                                                    spcDef.SetPlotTime sqcAbsoluteTime, sStart, sEnd
                                                                                    SQCSymbol1.SetDefinition spcDef
                                                                                End Sub
                                                                                

                                                                                When starting a new campaign you would initiate both, the Trend and the SQC Chart. The code to do this would be similar to this

                                                                                 

                                                                                Private Sub CommandButton1_Click()
                                                                                    Dim sStartTime As String
                                                                                    sStartTime = Format(Now(), "dd-MMM-yyyy HH:mm:ss")
                                                                                    SetPBTrend sStartTime, "*"
                                                                                    SetSQCTrend sStartTime, "*"
                                                                                End Sub
                                                                                

                                                                                 

                                                                                Per default, displays update every 5 seconds but there's not always a new value. We usually see the Trend's EndTime and the trace updating. In case there's a new value the DataUpdate event of the Trend fires. Within the event handler, we check for the amount of values and copy StartTime and EndTime from the Trend in case TraceValuesCount = 3.

                                                                                 

                                                                                Private Sub Trend1_DataUpdate(ByVal ntrace As Integer)
                                                                                    Trend1.CurrentTrace = 1
                                                                                    If (Trend1.TraceValuesCount = 3) Then
                                                                                        SetSQCTrend Trend1.StartTime, "*"
                                                                                    End If
                                                                                End Sub
                                                                                

                                                                                 

                                                                                Finally you may be concerned about the additional Trend symbol showing on the display. Setting the Visible property to false does not require code but I found it more obvious how things work together and added another CommandButton to the Display.

                                                                                 

                                                                                Private Sub CommandButton2_Click()
                                                                                    If (Trend1.Visible = True) Then
                                                                                        Trend1.Visible = False
                                                                                        CommandButton2.Caption = "Un-hide Trend"
                                                                                    Else
                                                                                        Trend1.Visible = True
                                                                                        CommandButton2.Caption = "Hide Trend"
                                                                                    End If
                                                                                End Sub
                                                                                
                                                • Re: [PI-SQC] How to refresh automatically the SQC control chart
                                                  Nicolas.Isambourg

                                                  Hello Gregor,

                                                   

                                                  finally I did what you've suggested. I used a trend.

                                                  I finished debugging my .NET application.

                                                  My conclusion is that I don't like PI-SQC because in my case, I think this component isn't ready to be used in production.

                                                  Maybe I should use PI-Notification.

                                                   

                                                  Thanks again for your help.

                                                  Best regards,

                                                  Nicolas