10 Replies Latest reply on Sep 21, 2011 7:56 AM by muwpa

    Trend Events

    muwpa

      Hi v-campus community.

       

      I'm using VS2010 and created a c# project from the Docking Window template which is provided in the Download section.

       

      What I want to do is to show some trend details (tag name, desc,...) in this DockWin. This DockWin should only be filled when a trend is selected. If not the window should be empty. Sounds easy? Unfortunately not for me :(.

       

      I don't know exactly how to get the data from the selected trend. I know "events" are a good suggestion, but I'm new to this topic.

       

      How can I catch the necessary event(s) and get access to the selected trend?

       

      Thanks in advance.

        • Re: Trend Events
          muwpa

          Ops, I recognized I put my post in the wrong section...think it belongs to "General .NET Development" or "PI ProcessBook/ActiveView and Microsoft Office Development".

           

          Sorry for that.

            • Re: Trend Events
              Asle Frantzen

              Hello Kerstin

               

              I haven't tried exactly what you are looking to accomplish, but I would start by checking out the help files provided with ProcessBook.

               

              If you click the Help menu in ProcessBook and select the second option - "PI ProcessBook VBA Language Reference" - you'll be able to browse through a lot of available options. I believe the different tags displayed in a trend are called "traces" - so you could start by checking out the documentation in the "Trend Class" section.

               

              There should be a few ways of identifying the different traces for the trend object.

               

              I don't know if that is the best way, and I also don't know if you can do what you're trying to accomplish this way, but give it a try!

               

              (Have you considered what to do if two tags/traces are active at the same time?)

                • Re: Trend Events
                  andreas

                  Kerstin,

                   

                  very brief - you might want to get first the event for an display activate (in OnConnection):

                   
                  m_theApp.DisplayActivate += new EApplication_DisplayActivateEventHandler(m_theApp_DisplayActivate);
                  

                   when the display is activated you can sign up for the event of selecting a symbol:

                   
                          public void m_theApp_DisplayActivate(Display aDisplay)
                          {
                              m_theApp.ActiveDisplay.SelectionChange += new EDisplay_SelectionChangeEventHandler(m_theApp_ActiveDisplay_SelectionChange);
                          }
                  

                   then you would have to check in m_theApp_ActiveDisplay_SelectionChange() if it is a trend symbol and do your work :-)

                    • Re: Trend Events
                      Asle Frantzen

                      And here the Trend object is a symbol.

                       

                      So her work would mean manipulating the selected symbol (trend) and identify the different traces of the trend.

                        • Re: Trend Events

                          Brief example (VBA) of how you would approach this:

                           

                           

                           
                          Private Sub Display_SelectionChange()
                          
                          If ThisDisplay.SelectedSymbols.Count = 0 Then
                              ' Nothing selected
                          Else
                              If ThisDisplay.SelectedSymbols(ThisDisplay.SelectedSymbols.Count).Type = pbSYMBOLTYPE.pbSymbolTrend Then
                                  Dim TheTrend As Trend
                                  Set TheTrend = ThisDisplay.SelectedSymbols(ThisDisplay.SelectedSymbols.Count)
                                  
                                  If TheTrend.TraceCount > 0 Then
                                      Dim iTrace As Integer
                                      For iTrace = 1 To TheTrend.TraceCount
                                          Debug.Print TheTrend.GetTagName(iTrace)
                                      Next iTrace
                                  Else
                                      ' Empty trend
                                  End If
                                  
                                  Set TheTrend = Nothing
                              Else
                                  ' Not a trend.
                              End If
                          End If
                          
                          End Sub
                          

                           

                           

                          You can manipulate the Trend from the ProcessBook object & symbol models but for accessing information on the data for each trace you would need to then use the appropriate SDK (PI SDK, AF SDK, ...).  You can loop through the values of a trace (Trend.GetTraceValue(...)) on a trend but the data is somewhat filtered for best displaying it on a trend.  

                           

                          Are you looking to build an add-in beyond the functionality of the "Details" add-in that comes with ProcessBook?

                           

                           

                            • Re: Trend Events
                              muwpa

                              Thanks for your answers. It works!

                               

                              Some Information I get from the Trend object, other Information I get from the tag (PISDK.Point).

                               

                              @Rhys: Yes, guess from which "Wolfgang" this project is from...

                                • Re: Trend Events

                                  It has got to be our friend from Austria...

                                    • Re: Trend Events
                                      muwpa

                                      Hello again!

                                       

                                      The thread continous...

                                       

                                      The Detail-Docking-Window for PB is already finished. The last thing to do is to react on trend changes with the Trend Event "DataRefresh" (especially when new tags are added/deleted from the trend).

                                       

                                      To react on every trend change I have to add the "DataRefresh" Event on every trend. So every time a trend is selected the following function is called:  

                                       
                                              public void CreateEventOnTrend(Trend t)
                                              {
                                                  try
                                                  {
                                                      ETrend_Event etrend = (ETrend_Event)t;
                                                      ETrend_DataRefreshEventHandler handler = new ETrend_DataRefreshEventHandler(this.DataRefresh);
                                      
                                                      etrend.DataRefresh -= handler;
                                                      etrend.DataRefresh += handler;
                                      
                                                  }
                                                  catch (Exception ex)
                                                  {
                                                      //catch Exception
                                                  }
                                              }
                                      

                                      The reason why I remove the event-handler first from the trend object is that I don't want to register the same event on a trend multiple times (--> same exeption as described below). This "remove" line of code causes no troubles (no error, no exception) at all. Then I add the event-handler to the trend object.

                                       

                                      This works quite good, but after register/unregister the event on the trend (which means select trend, select another trend,... ) serval times it throws a "System.Runtime.InteropServices.InvalidComObjectException" with the following error message:

                                       

                                      german: "Ein COM-Objekt, das vom zugrunde liegenden RCW getrennt wurde, kann nicht verwendet werden."

                                       

                                      english: "COM object that has been separated from its underlying RCW cannot be used."

                                       

                                      Don't know what to try next to handle this problem. Another suggestion is to check if the "DataRefresh" Event is already registered to a trend, but I found no functions which are quite helpful to do this.

                                       

                                      Thanks in advance for your answers!

                                       

                                      PS: To get a better idea from this AddIn...

                                       

                                      0537.TrendSettings_5F00_Vcampus.JPG