17 Replies Latest reply on Oct 6, 2011 5:17 AM by hanyong

    Embedding ProcessBook display in a C# UserControl


      Does anyone have a sample of embedding a PB display in a .NET C# UserControl. I have a kiosk app with a tab control and I would like to embed a PB display inside one of the tabs using a UserControl. I suspect that it would be similar to embedding a PB display inside an Excel spreadsheet but I'm not sure which of the myriad of COM objects is the automation document server.



        • Re: Embedding ProcessBook display in a C# UserControl

          Hi George,


          I can think of 2 ways to do this.


          1) Use PI ActiveView, which allows users to view and interact with ProcessBook Displays outside of PI ProcessBook. You can add PI ActiveView Control (which is an COM Component) and add it to your form. You just need to edit the property of the object to give it a displayurl (a pointer to your ProcessBook display.


          2) If you do not have PI ActiveView (which is not included in the vCampus PI Products Kit) then another way is to create your own ActiveX from PI ProcessBook Display Control, referring to this blog post by Andreas. Step 7 indicates how to create the managed wrapper with PI ProcessBook Display Control, and you can add a reference to that in your C# project and load the display file to one of your tab pages at runtime.


          This is a slight variation from Andreas' code to do so:

          AxHost _pbDisplay = new AxPBDCtrl.AxPbd();
          IntPtr forceCreation = _pbDisplay.Handle;
          _pbDisplay.Dock = DockStyle.Fill;

          AxPBDCtrl.AxPbd _AxPbd = (AxPBDCtrl.AxPbd)_pbDisplay;
          _AxPbd.DisplayURL = @"C:\Users\hanyong\Documents\Display1.pdi";


          Thanks to Andreas for his wonderful example on creating a Preview Handler for ProcessBook Display.

          • Re: Embedding ProcessBook display in a C# UserControl

            Ummm, true: PI ActiveView isn't part of vCampus by itself, but _is_ part of the ProcessBook install - namely in the PBDCtrl.ocx control mentioned above.  And I had a PDI file up and displaying in a C# Win Forms app in about 5 minutes - it's THAT easy.  I didn't have to create a user control - just added the OCX to the VS Toolbox, then dragged an instance onto a form.


            I don't know what the licencing ramifications are of this (very likely an end-user machine needs a license of some sort), but this will at least allow you see how the ActiveView control works.



              • Re: Embedding ProcessBook display in a C# UserControl

                Hi folks!


                I'm the Product Manager for PI ProcessBook and PI ActiveView. Your lovely hosts asked me to weigh in on this thread some... so here goes.


                It is true that the OCX is delivered both with PI ProcessBook and PI ActiveView. However, the development on this component is very much driven by the PI ActiveView code.


                To clarify somewhat, bear with me while I explain the high-level relationship among these things. PI ProcessBook and PI ActiveView share the same codebase. Essentially, new features in the core ProcessBook application get rolled into ActiveView by default unless they are specifically coded out (I belive they use something like an IFDEF statement in the ActiveView code).


                The OCX, as you know, is an ActiveX control and relies on an executable to be its OLE Server. By default, the OCX will look for the ActiveView executable (acview.exe), for which it is optimized. When it finds that, there are some things that happen with caching and keeping the exe active, etcetera. Only one exe is launched regardless of how many OCX calls are made, thereby optimizing system resource usage. The URL properties are also designed to work with the acview.exe and you don't see a Task Bar icon when acview.exe is used. If the acview.exe is not found, then the procbook.exe (ProcessBook executable) will be used, but in that case you will see the Task Bar icon. This is an indication that you don't have the acview.exe installed. The behavior is different when the procbook.exe is used and we generally don't recommend that you use the OCX this way.


                I hope this is somewhat helpful.




                Laurie Dieffenbach


                OSIsoft Product Manager

                  • Re: Embedding ProcessBook display in a C# UserControl

                    One further note: there is a registry setting for PI ActiveView that determines how long the EXE stays resident once the calling OCX controls are closed. ProcessBook doesn't have this setting.

                    • Re: Embedding ProcessBook display in a C# UserControl

                      Just to follow up on Laurie’s comments. PI ActiveView will give best results with the pbdCtrl.ocx - among the topics discussed here

                      1. With ActiveView nothing appears on the task bar
                      2. After the last instance of the pbdCtrl is closed the ActiveView executable will automatically close after five minutes

                      One other difference is that ActiveView will do a Fit-all when the display is opened. Also with the pbdCtrl you cannot edit a display.


                      Andre Downey
                      Development Lead

                        • Re: Embedding ProcessBook display in a C# UserControl
                          Henryk Schneider

                          Are there any examples of using ActiveView in a web form/application (ideally ASP.NET) with the ability to pass some values (a string and a couple datetime values) to the display during runtime, either from codebehind or client side scripting?





                            • Re: Embedding ProcessBook display in a C# UserControl

                              Hi Henryk,


                              I would refer you to this post by Steve some time ago. As mentioned, you can find the examples to embed ActiveView into a web page using HTML 'object' tags.


                              As for your requirement of passing values to the display, you can access the object model Display of PI ActiveView control using vbscipt.


                              One example to set the display time range when the page is loaded:


                              <script language="vbscript" type="text/vbscript">
                              Sub window_onLoad()
                                    Pbd1.Display.SetTimeRange "*-4h", "*-1h"
                              end sub
                              <object ID="Pbd1" WIDTH="90%" HEIGHT="90%" CLASSID="CLSID:4F26B906-2854-11D1-9597-00A0C931BFC8">
                                 <param name = "DisplayUrl" value="<link to your pdi file>"/>


                              You can also access the symbols and perform task like adding trace to a trend by:

                              Pbd1.Display.Symbols.Item("Trend").AddTrace ("sinusoid")

                              You can see that accessing the object model of the Display is similar to how you would do it in VBA programming on ProcessBook. One way to do this is to try doing what you want in VBA on ProcessBook and convert it to vbscript appropriately.


                              If you have more questions on this, you can start a new discussion thread, since your question is quite different from the original question that started this thread.


                              Hope this helps

                                • Re: Embedding ProcessBook display in a C# UserControl
                                  Henryk Schneider

                                  Thanks Han.


                                  I had hoped it might be that simple on first attempt, but seems that accessing anything other than the standard object properties throws up an error.  In this case when trying to access the Display property as you have above, the following error is presented:


                                  Error: Object required: 'Pbd1.Display'





                                    • Re: Embedding ProcessBook display in a C# UserControl

                                      Can you let us know what you are trying to access from the PI ActiveView display. And also what is the code and .pdi file that you are using? Then it might be easier for us to figure out why you are getting the error.

                                        • Re: Embedding ProcessBook display in a C# UserControl
                                          Henryk Schneider

                                          Hi Han,


                                          Just trying to access a simple PDI.  The PDI at the moment doesn't have much in it,  a text object and trend object with sinusoid tag, no code behind at this point.


                                          The code I'm using is basically a copy of your first snippet above with DisplayURL of my PDI.  Which does load by the way.  Even if I call the DisplayURL method on the page load event, that works.  But referencing other .Display properties fails.


                                          I was trying to see if based on users selection on a web page list/query result I could call up an activeview object and pass it a string - substation name in this case, and a date range.  





                                            • Re: Embedding ProcessBook display in a C# UserControl

                                              I guess i have to ask you to post the exact code that you are using to find out why can be causing an error. In my testing, I tried to use the same methods to access other contents within a display as well. It has been working for me:

                                              <%@ Page Title="Home Page" Language="C#" AutoEventWireup="true"
                                                  CodeBehind="Default.aspx.cs" Inherits="testactiveviewaspnet._Default" %>
                                              <head id="Head1" runat="server">
                                                  <script language="vbscript" type="text/vbscript">
                                                      Sub Change_Time_Range_onClick()
                                                          Pbd1.Display.SetTimeRange "*-4h", "*-1h"
                                                      end sub
                                                      Sub Add_Sinusoid_onClick()
                                                          Pbd1.Display.Symbols.Item("Trend1").AddTrace "sinusoid"
                                                      End Sub
                                                      Sub Remove_Sinusoid_onClick()
                                                          Pbd1.Display.Symbols.Item("Trend1").RemoveTrace 2
                                                      End Sub
                                                      Sub Edit_Text_onClick()
                                                          Pbd1.Display.Symbols.item("Text1").Contents = "Set CDT158"
                                                      End Sub
                                                      PI ActiveView with VBScript 
                                                      <object ID="Pbd1"
                                                 <param name = "DisplayUrl" value="http://localhost:26657/Trend.pdi"/>
                                                      </object><br />
                                                      <input type="button" value="Add Sinusoid" onclick="Add_Sinusoid_onClick()" />
                                                      <input type="button" value="Remove Sinusoid" onclick="Remove_Sinusoid_onClick()" /><br />
                                                      <input type="button" value="Change Time Range" onclick="Change_Time_Range_onClick()" /><br />
                                                      <input type="button" value="Edit Text In Display" onclick="Edit_Text_onClick()" /> 

                                              The display file that i've used in the ActiveView control is attached.