Skip navigation
All Places > PI Developers Club > Blog > Author: andreas
1 2 Previous Next

PI Developers Club

22 Posts authored by: andreas Employee
andreas

PI ProcessBook: SetViewPort

Posted by andreas Employee Jul 10, 2009

SetViewPort

Another post on some small code snippets that might be of use for you.

 

ProcessBook displays can be huge and the amount of information overwhelming. With the help of VBA we can zoom the view to a certain area to catch the attention of the observer .

 

So what are we going to do?

  1. For demonstration we simply put a Value object on the PI ProcessBook. The example below uses the values of CDM158 - so adjust to your needs.
  2. Now we switch to VBA by hitting Alt+F11.
  3. Use the two combo boxes on the top of the code window to open the Value1_DataUpdate Sub.
  4. Type the following code into Value1_DataUpdate:
    Dim AspectRatio AsDouble
    AspectRatio = Me.ViewWidth / Me.ViewHeight
    SelectCaseMe.Value1.GetValue(vrDate, vrStatus)
      Case"Cascade"
          CallMe.SetViewPort(15000, -15000, 30000 / AspectRatio, 30000)
      Case"Program"
          CallMe.SetViewPort(15000, 0, 15000 / AspectRatio, 15000)
      Case"Prog-Auto"
          CallMe.SetViewPort(0, -15000, 15000 / AspectRatio, 15000)
      Case"Manual"
          CallMe.SetViewPort(0, 0, 15000 / AspectRatio, 15000)
      CaseElse
          CallMe.SetViewPort(15000, -15000, 30000 / AspectRatio, 30000)
    EndSelect

The result is a PI ProcessBook display that changes it's visible area dependent of the value of CDM158.

 

Note:
The top left corner of a PI ProcessBook display is (15000,-15000).

The Modified property

Have you ever thought about exiting a ProcessBook Display without getting prompted to save the changes?

 

The ProcessBook Display class exposes a property called Modified. Simply catch the BeforeClose event of the Display and set the Modified property to False. ProcessBook will not ask you to save the changes.

 

This can be handy if your users are allowed to change the display but you neither want them to safe the changes nor bother them with the question.

 
Private Sub Display_BeforeClose( ByVal bCancelDefault As Boolean
    Me.Modified = False
End Sub

A WebBrowser inside the Display

Adding a Browser to a ProcessBook is fairly simple:

  1. Open a ProcesBook Display.
  2. Press the Control button and add a Microsoft WebBrowser Control.
Now we will have to add some code to select the URL to display. For the sake of simplicity we will just choose a website to navigate to when the display is opened:
  1. Open the VBA editor either by pressing the apropriate button or by ALT+F11.
  2. Open the Code Window by a double-click on ThisDisplay in the Project Tree.
  3. Use the two combo boxes on the top of the code window to open the Display_Open Sub.
  4. Add the code below.

 
PrivateSub Display_Open()
    Me.WebBrowser1.Navigate( "http://www.osisoft.com" )
EndSub

You may imagine that other events can be used to drive the content of the WebBrowser control guiding the user of ProcessBook from events out of the process.

In my last post (AdHoc Calculations in RtWebparts (1)) I have shown you a simple dataset that takes a PE like expression and calculates it.
In RtBaseline Administration the Dataset would look like:
DataSet.jpg

 

In this post I am going to show you how to use it in a very simple display.

The Web Part Page

  1. We create an empty web part page and add a Form web part AddFormWebPart.jpg to it.
  2. We add an RtTrend web part AddRtTrend.jpg.
  3. Now we connect the two web parts:
    Connection.jpg

  4. The RtTrend needs to know where
    Connection2.jpg

    and what Information it gets from the Form WebPart:
    Connection3.jpg

  5. So we are ready to hit OK. As a first test let us try 'CDT158'+'SINUSOID'+1000:
    AddRtTrend2.jpg

  6. We finally have created a web part page where an end user can enter a PE formula and gets a trend of it!

The PIArchive..PICalc Table

PI ProcessBook features datasets. These allow an user to create a calculation that is calculated on the fly when somebody uses it in a Trend, Value, etc. In RtWebpart an administrator can create PI Calculation datasets but an ordinary user is not capable of doing this (you need to have access to the RtBaseline Services administration).

 

However, with the help of PI OLEDB we can create a simple relational dataset that takes the expression as a placeholder:

 

SELECT expr, time, CAST (value AS float32) result FROM piarchive..picalc WHERE expr = ? AND time > ? AND time < ? AND timestep = ?

 

This simple dataset can be used either with the expression defined at the level of the RtWebpart as well as the RtWebpart can consume the expression from another web part (for example the Form web part).

 

Note that the Relational Dataset first needs to be created in RtBaseline Services by the administrator. Because it contains a placeholder that allows end-users to use it with any expression in their Web Parts, it is only done once and then becomes a conveniences to end-users.

 

Read more in my next post AdHoc Calculations in RtWebparts (2)!

Introduction

Hi there!
Have you ever thought about a manual input to PI from SharePoint?

So here is what you need (at least if you do it like I did it ):

  1. Microsoft Office SharePoint 2007
  2. A SQL Server
  3. The PI OLEDB Provider
  4. And RtWebParts – because entering data is not so much fun if you cannot trend it!

O.k. now – what are we going to do?

Overview

Microsoft Office SharePoint Designer 2007 allows you to create a custom view of data – a Data View. The Data View supports various sources, in this example we will use a SQL query. The interesting part is that the Data View allows you to have an insert query as well.
And here starts the fun; we are going to insert a value from a Data View in a SQL table.

Wait a moment - this is vCampus, so what about PI? Well, we will create a job that moves that data from the SQL table to the PIArchive (via a linked server) – and voila – we have a manual input to PI from SharePoint (somehow ).
You will not get bored with the preparation - I have already a tag called ManualInputSQL, a table in my SQL server called ManualInputTest (with a datetime column as primary key and a value column) and I have created my linked PI Server called RtDemoPI.

Create a Web Part Page

So I am starting from a blank SharePoint Web Part page – and as I told you, we want to do some RtWebParts.

  1. We add an RtTrend and an RtTimeRange:

  2. RtWebpartPage1.jpg

  3. Now we are going to open this page in Microsoft Office SharePoint Designer:

  4. SharepointDesigner1.jpg

Create a Database Connection

To use a Data View we have to create a Database Connection first.

  1. We go to Data View > Manage Data Sources
  2. On the right hand column we can now expand Database Connections and select Connect to a database.
  3. We configure the database connection (in this case the server is the SharePoint server and I use the "sa" account to connect to the database.

  4. ConfDBConnection1.jpg

Note that this authentication option saves the username and password as clear text in the data connection, but for our test here this should be o.k.

  1. In the following dialog I specify the database and the table:

  2. ConfDBConnection2.jpg
  3. I am done with this part.

  4. DataSourceProp1.jpg
  5. Finally we press OK to finish the configuration of the database connection.

Put the Data View on the Web Part Page

  1. We Drop the Database connection to the Web Part Page to use the Data View:

  2. SharepointDesigner2.jpg
  3. And we change the Data View properties so that we can insert a value:

  4. DataViewProp1.jpg
  5. So it is time to see how it looks like and how we can insert data.

  6. RtWebpartPage2.jpg

The SQL Server

Now let us look at the job to move the data from SQL to PI:

  1. Open the Microsoft SQL Server Management Studio.
  2. Expand the SQL Server Agent and create a new job.
  3. Give the job a meaningful name and click the Steps page.
  4. The first step is to copy the data (remember, the PI server is a linked server called RtDemoPI, rtdemogmbh is the database, manualinputtest is the table and ManualInputSQL is the tag):

  5. INSERT rtdemopi.piarchive..picomp (tag,time,value)
    SELECT 'ManualInputSQL'AS tag,time,value
    FROM
    rtdemogmbh..manualinputtest

  6. The second step to delete the data:
  7. DELETE FROM rtdemogmbh..manualinputtest

  8. And we schedule the job to run every minute. If we have done this – we have our manual input to PI from Microsoft SharePoint!

  9. RtWebpartPage3.jpg

I am looking forward to 5 great days at the Microsoft TechEd Developers 2008 EMEA. Microsoft brought about 4000 developers and IT professionals together. We are here in the city of Barcelona that has some warm and sunny days prepared for us.

 

So what is the news to expect? The first keynote did provide us a glimpse of what visual studio 2010 will get us – and I can tell you this looks good!

 

Later this week we will hear about green computing – a theme that has been picked up by more and more people with the raising energy costs to operate a data center.

 

So stay tuned for more to come…

andreas

@UC2008

Posted by andreas Employee Oct 27, 2008

10o'clock pm in the hotel. We are getting the final touch ups for the virtual campus. Tomorrow we will go online!

Filter Blog

By date: By tag: