Skip navigation
All Places > PI Developers Club > Blog > Author: spilon
1 2 3 4 Previous Next

PI Developers Club

48 Posts authored by: spilon

Some of you may have noticed I've been out for a few weeks... well I'm back


As you can imagine, I had (and still have) to catch up on emails and stuff, but you should see me active on the forums and others from now on. As a matter of fact, I just posted the PI ProcessBook 3.2 and PI Server 3.4.380 (WIS) setup kits on the vCampus Download Center. Enjoy!


I'd also like to take this opportunity to remind you 2 things:

  1. We're really hoping to see all technical folks in San Francisco on December 1-3 for the OSIsoft vCampus Live! event - don't forget to visit the related blog and registration website for more information. Also make sure you follow the event team on Twitter and contact them at in case you need more info.
  2. Remember we launched the Community Technology Preview (CTP) for the PI Web Services and PI OPC UA Server products - an exclusive opportunity for vCampus members to try these products out and provide feedback on their design/roadmap. Make sure you visit their respective blogs for more information: here for Web Services and here for OPC UA.


Thanks to all of you who made the discussion forums active, we now have over 1500 posts on the discussion forums! With the launch of OSIsoft vCampus in mid-November 2008, that represents less than 200 business days and an average of 7.5 posts/day! I think this is great, especially when you think that the few first months were (obviously) less active... Thanks again and keep the questions and comments coming!


You might also have noticed I was less active on the forums these last days (thanks to Rhys, who covered for me! )... well I have an excuse for this - a good excuse that is: I was less active because I was with our "Events" team, helping at the preparation of the OSIsoft vCampus Live! event, our 'technology' event of the year (and the the years to come!).


Indeed, you might remember how our last Users Conference was made more "business-oriented", focusing on business and industry topics. Well, the "other half" of the conference - the technical half - is the OSIsoft vCampus Live! event. It will be held in...  actually, no... I won't be talking about this in my blog...  we created a new blog for that event, so make sure you check it out and subscribe to its RSS feed!


As you'll see on that blog during the coming days and weeks, we are looking forward to getting your thoughts, ideas and maybe even some of your code :))



I'm thinking if we had some kind of "Friday Good News" series, this would be a real good candidate: I finally got a hold of the recording of the Web Services webinar held yesterday! As confirmed by the LiveMeeting support people, they had technical problems and I couldn't access the recording until this morning - 2 days later. This really scared me for a bit as I thought we really lost the thing...


But everything's back to normal, I should be able to post the recording shortly under the vCampus Auditorium (a few edits are necessary to make it better quality). I'll post a little something in the "Web Services and PI" discussion forum when it's there.


Have a good week-end!

PI SDK Web Service Examples

Posted by spilon Jul 29, 2009

What I suggest in this download is an updated version of the "PI Web Service Examples", which can be found on the Technical Support website's download center. It presents 4 Visual Studio 2008 projects in C#: 2 web services and 2 web service clients. They are grouped in 2 solutions (.sln files), so make sure you choose the right one:

  • PI SDK Web Service and Client Examples (IIS6-).sln:
    if you are running IIS6 and earlier (e.g. Windows XP, Windows Server 2003)
  • PI SDK Web Service and Client Examples (IIS7+).sln:
    if you are running IIS7 and later (e.g. Windows Vista, Windows 7, Windows Server 2008)

Please note that those are only examples and should not be used "as is" in production environments. They were originally developed with the idea to keep it really simple and as concise as possible; some parts need to be adapted to make them appropriate for real-life, larger-scale applications. One example of this is the cross-thread calling of UI elements after an asynchronous tag search - you should make sure to use the appropriate threading model to fit the structure and the needs of your applications.


With that said, it is definitely simpler to use the PI Web Services product (released as CTP - Community Technology Preview - to the vCampus community) rather than creating your web services to wrap some PI SDK functionality. Find out more about PI Web Services on the newly-created "Web Services and PI" blog!

As suggested in David's blog post, OSIsoft will be well represented next week at the Microsoft Worldwide Partner Conference (WPC) in New Orleans. And I will be there to represent the OSIsoft Virtual Campus and promote how people can leverage our products as well as Microsoft's to do great things.


2 questions for you:

  1. Will you be there?
    Don't hesitate to come and connect with me (come see us at the OSIsoft booth or arrange face-to-face with me through the WPC Connect tool)
  2. Do you have any Dynamic OBA (Office Business Application) - OBA with PI - to share with us?

And for those of you coming to the WPC, don't miss the following talk, where Prabal Acharyya (Director of the Microsoft World Wide Partner Alliance at Microsoft) will be co-presenting with Carlo Malaguzzi from Microsoft:
***BP005 Reducing Costs and Maximizing Revenue with Office Business Applications
***Mon 7/13 | 5:00 PM-6:00 PM | 208-210

When reading this discussion on the forums (where Yannick was inquiring about a PI SDK method that would perform multiple calculations at once) I realized something and I'm glad to see I'm not the only one in this boat: we, developers, are expecting more and more out of the various SDKs we are using nowadays. We expect the SDKs to expose always more "1-call" functionalities, with increased complexity, and we slowly get accustomed to fewer and fewer lines of code.


And I think I found why: the Microsoft .NET Framework. Let me explain:


In my opinion, Microsoft has significantly raised the bar in terms of SDKs with the .NET Framework, with its wide (wide? no, huge!) variety of classes and methods - and method overrides. When dealing with .NET classes (think of the various classes in System.Collection or the ADO.NET objects in System.Data, for instance), it seems to me like classes always expose a version of the method that perfectly suits my needs. The .NET designers thought of so many use cases and they expose so much functionality... good work, Microsoft!  But man, you're making us lazier...


We often take it for granted because it's more "infrastructural" (i.e. it's everywhere and invisible at the same time) than an actual product, but it is an actual product and it greatly simplifies (and reduces) the code we have to write. The Framework does so much behind the scene that it makes the (not-so-old) good old days look so far... manually-created and -maintained linked lists, bubble sorting, memory management and pointers, reading files or network streams, performing drawing, SQL or FTP tasks, etc.  When's the last time you wrote more than 10 lines of code to read a file?


I suggest you do this little exercise, just for the fun of it: open an old piece of code you wrote (say in 2000) and compare the number of loops you have with the number of loops you write in today's code - the difference is amazing. Happy .NET coding!

Yes, you did read the title ok! I'm talking to you, C# programmers, who always dreamt of writing PI ACE Calculations in C# rather than VB.NET 


Please don't get me wrong: I'm not saying C# is better than VB.NET (nor am I suggesting the opposite...) - we simply acknowledge that people have their own preference in terms of programming language, and decided to prepare something for people who know the power of PI ACE and have a preference for C#. So here's what we have to suggest: we recently put together a Tutorial that guides the reader through creating PI ACE Calculations and writing the code in C#, whereas PI ACE normally allows you to write VB.NET code.


This simple thirty-some steps document was made available on the vCampus Library, under the "White Papers and Tutorials > PI ACE" branch. Note that this is a vCampus-exclusive document and is therefore not supported by OSIsoft's regular Technical Support; please use the PI ACE Development discussion forum to post questions you may have. As far as releasing a version of the PI ACE Wizard that supports C# natively, we are currently evaluating the possibilit - please provide your feedback on the forum mentioned above.


Enjoy and make sure you give me any feedback you may have (you can add comments to this very post or shoot me an email!)

You might remember my April 7th blog post, which announced a webinar to recap the 2009 Users Conference held March 30 - April 1.
Well the webinar was held last Thursday and the recording is now available here.



The 2009 Users Conference
Lots announced - especially for 'data access'


That's it. It's over and it was, in my humble opinion, a frank success! Indeed, the 20th OSIsoft Users Conference was held last week in San Francisco and was rich in announcements and presentations of all kinds - especially in the 'Data Access' space.


vCampus was mentioned a number of times in the opening/closing keynotes, Cristobal (Escamilla) took care of the vCampus booth at the Product Expo and for my part, I gave a talk in the 'Data Access' track of the Product Theaters. Plus, anybody involved with vCampus - whether customer, partner or employee - had one of those cool vCampus "pins" on his/her name tag holder (let me tell you this drove curiosity and excitement for non-subscribers!).


It was really great to meet some of you in person and it was exciting to see how everybody else (i.e. non-members) was excited about the vCampus program! Registrations already started to feel this hype so this is good news for all of us: more content, more discussions, more everything!


For Those Who Could Not Attend the UC:
Next Webinar... Discoveries from UC2009 (April 30th)


Good news for those who could not attend the last Users Conference: we will hold a webinar to summarize what was announced during the event. A number of exciting news were communicated, a number of which pertain to the data access products (new products, new releases of existing products, etc.)   We feel it is important for PI developers to know about these and understand where we are going to make well-informed decisions. Ray Verhoeff, who is leading the 'Data Access' roadmap on the Engineering Leadership Team at OSIsoft, will make us the honor to join as a guest speaker.


The webinar is part of the vCampus-exclusive "Builders' Café Webinar Series" and is titled "Discoveries from UC2009". It is scheduled for April 30th at 9am Pacific Time and registration is already open, as you can see in the top-right corner of the vCampus Auditorium. Register Now!


vCampus Live!
(formely known as the OSIsoft Developers Conference, or DevCon)


Another very exciting announcement made last week was the "vCampus Live!" event, which can be thought of a revamped, redesigned Developers Conference (a.k.a. DevCon). This is a huge topic by itself so I don't want to talk too much about that here - stay tuned for future blog posts and announcements on this!

If you've been reading in the "development blogosphere" lately, you probably heard about Microsoft's MIX09 conference going on as we speak read, which conference exposes the latest Microsoft technologies for web designers and developers. One of the key topics in that conference (31 sessions in 3 days!) is Silverlight 3 (beta). In my humble opinion, one of the most important new features is the out-of-browser experience, a highly requested featured which enables Silverlight 3 applications to run as desktop applications on Windows and Mac computers.


I don't pretend having better blogging skills than the 100's of bloggers talking about that , so what I suggest is that you read Tim Heuer's blog post on the topic. Tim works for Microsoft as a program manager for Silverlight, and I found this blog post to be the most complete and comprehensive on Silverlight 3. Happy reading!

If you haven't yet registered for our next User Conference (March 31-April 1 in San Francisco), hurry up! We're 10 days away from the closing of the "Early Bird" registration offer. This offer consists of a $300 discount on conference registration, as well as a $40/night discount on hotel room.


The User Conference is the perfect venue to learn about OSIsoft's products and roadmap for the coming months/years, but also a great opportunity to connect with OSIsoft employees, customers and partners.


Visit for the UC2009 website for more details and for registration.





February 26th it is! Mark the date and register now!


With the help of a few eminent guest speakers, I'll be conducting the next of the vCampus-exclusive The Builders' Café webinar series: Programming .NET Add-Ins for PI ProcessBook.


This vCampus-exclusive webinar will present a side of PI ProcessBook that you may not know yet: automation and add-ins. In addition to presenting how to develop .NET add-ins to PI ProcessBook, this webinar will introduce a set of 4 sample add-ins from which you can start developing yours. Also, a live Q&A session will be held at the end of the webinar, for you to provide feedback or ask question to some of the people who made all this possible!


Guest speakers are:


Don't miss this... register now!

As you may already know, PI stores data with timestamps that read in number of seconds since January 1st, 1970 UTC.


For the first and only time in history (makes it sound more serious  ), this number will read 1234567890 on Friday the 13th: 13-Feb-09 23:31:30 UTC, more precisely.


'How can I see if this is true??', I hear from my desk...  here, using a command prompt:
     D:\PI\adm\> pidiag -tz "13-feb-09 23:31:30"

(Sorry for the word play  - or "acronym play"... I just couldn't resist )


More seriously... we would like to reiterate our invitation to our 20th Users Conference, taking place in San Francisco starting March 31st. You can review the details (there's been major changes!) and register for the event at


This year more than ever, we would be interested to hear about the impact of the current economic situation on your business and operations and discuss how PI can address the challenges you are facing now. Our upcoming Users Conference can perhaps help you, since a number of people - customer and partners of OSIsoft - will speak on this topic. If you have something to share which you feel would be beneficial for the whole commumity, please consider registering for own talk, using the "Call for Papers" link on the left-hand side of the link provided above.


We hope to see you and your colleagues at this event in a few weeks! We'll also make sure the members of the vCampus community meet and exchange around common interests!





One feature I think might be unknown or underestimated is the support for WebServices in PI ACE 2.x, which I'd like to cover here in a brief paper. Depending on the feedback you'll give me and how people like it, I might enhance it and turn it into a Tutorial destined for the vCampus Library. Happy reading and coding!




The What and the Why


On one hand we have web services, which are gaining popularity as they allow for very simple client-side applications that can work over the Internet (i.e. across firewalls) and that are interoperable across platforms, applications, and programming languages (because they use standards such as HTTP, SOAP and XML).


On the other hand we have PI Advanced Computing Engine (ACE), which allows people (developers and non-developers) to create simple or complex calculations that can be make use of PI data. In PI ACE 2.x, these calculations can be streamed on demand by invoking the exposed web services. This means a very easy (1 simple procedure for all ACE calculations) and efficient (calculations are done on the server) way to extend what yourself or somebody has done in PI ACE already.


Part 1 below is also outlined in the PI ACE User Guide, available on the vCampus Library (under Chapter 6: ACE 2.x Features, see Exposing Calculations via Web Service). That's why I'll focus a little more on Part 2 and 3, which explain how to "consume", how to use those web services.


Also, if you are not familiar with the installation, configuration or usage of PI ACE, please consult the PI ACE User Guide in the Library and don't hesitate to post in the PI ACE Development discussion forum.




Part 1 - Setting up the PI ACE web services


The first few steps consist of activating the streaming of PI ACE calculations via web services:

  1. Install and configure Internet Information Services (IIS) as per Microsoft's instructions.
  2. Install PI ACE 2.x – at least the Scheduler part.
  3. Create a directory in the wwwroot directory (such as PIACEWebService) and copy the file \PIPC\ACE\PIACEWebService.asmx to the directory.
  4. Create a subdirectory called bin and copy the file \PIPC\ACE\PIACEWebService.dll to it.
  5. Open the Microsoft IIS management console.
  6. Select the web service directory created in Step 1 (i.e. PIACEWebService), right-click it, and select Properties.
  7. Click Create and set appropriate security settings.

At this point the ACE web services are ready to be accessed and perform on-demand streaming of the ACE calculation results.


2 web services are exposed by PI ACE 2.x:

  1. GetACEContexts: retrieves all available ACE Contexts available for execution.
  2. Calculate: executes a given calculation (i.e. Context) with the specified Start Time, End Time and Interval.

The Calculate web service returns 3 pieces of information:

  1. Timestamp (in UTC Seconds)
  2. Value
  3. Type (this value gives precision on the type of the Value field: -2 is for text string, -1 is for numeric and a value of 0 and higher represents the code of a corresponding PI digital state)



Part 2 – Add a reference to the PI ACE Web Services
(example using Visual Studio 2008)


Using web services is very similar to using methods contained in regular assemblies that reside on your computer: you 'add a reference' to it in your project, you instantiate them and then use their methods. The only difference is that those are 'web references' or 'service references' as opposed to regular ones.

  1. Open Microsoft Visual Studio 2008
  2. Create a new "Windows Forms Application" Project (I called mine 'ACEWebServiceExample')
  3. In the Solution Explorer, right-click on the project and click Add Service Reference:
    (note the option is called Add Web Reference in Visual Studio 2005)
  4. 090119.01_2D00_AddServiceReference1.png

  5. On the Add Service Reference window, click Advanced:
  6. 090119.02_2D00_AddServiceReference2.png

  7. On the Service Reference Settings window, click Add Web Reference:
  8. 090119.03_2D00_AddServiceReference3.png

  9. On the Add Web Reference window:
    1. Navigate to the web service virtual directory (i.e. http://YourWebServer/PIACEWebService/PIACEWebService.asmx)
    2. Choose a name for your reference (i.e. myACEWebSrv)
    3. Click Add Reference
    4. 090119.04_2D00_AddServiceReference4.png

  10. You should now see the reference (with the name you gave in the last step) appear under Web References in the Solution Explorer:



Now is time to use this reference.




Part 3 – Consuming/Using the PI ACE Web Services
(example using VB.NET under Visual Studio 2008)

  1. Make the form bigger and place the following objects on it:
  2. 090119.06_2D00_ACEWebServiceForm.png

  3. Go in the code behind this form – use the View Code tool at the top of the Solution Explorer: 090119.07_2D00_ViewCode.jpg

  4. At the class level, declare and instantiate a variable that will hold and execute the ACE web services:

Private ws As New myACEWebSrv.PIACEWebService

  1. Get in the btnListContexts button's Click event and add the appropriate code to:
    1. declare the appropriate variables (a single string and a 1-dimension array of string)
    2. invoke the GetACEContexts method of the web service (and fill the array of string)
    3. clear the content of the drop-down list
    4. loop through the retrieved contexts (with the help of the single string variable and a For..Each structure)
    5. add these contexts to the drop-down list

Dim strContext, strContexts() As String
strContexts = ws.GetACEContexts()

For Each strContext In strContexts

  1. Get in the btnCalculate button's Click event and add the appropriate code to declare the following variables:
    1. A 1-dimension array of myACEWebSrv.PIACETagValues objects
      (this is the top-level object that will be used to retrieve the values)
    2. A single myACEWebSrv.PIACETagValues variable
      (to help looping through the array)
    3. A date initialized to January 1st, 1970
      (remember timestamps in PI are expressed in seconds since January 1st1970)

Dim ACEValues, arrayACEValues() As myACEWebSrv.PIACETagValues
Dim ACEEvent As myACEWebSrv.PIACEEvent
Dim date1970 As New Date(1970, 1, 1)

  1. Still in the btnCalculate button's Click event, we then we execute the Calculate method from the web service, and we:
    1. pass the values from the various fields on the form
    2. fill the 1-dimension array of PIACETagValues objects

arrayACEValues = ws.Calculate( _
    cmbContexts.Text, txtStartTime.Text, _
    txtEndTime.Text, Double.Parse(txtInterval.Text))

  1. Then we loop through the results and add them to the ListBox element:
    1. use a For..Each structure to loop through the series of values
      (there might be more than 1 output tag for the executed ACE Context)
    2. use a For..Each structure to loop through the values of a given series
    3. add these values to the list
      (note the .AddSeconds().ToLocalTime construction, where we add the retrieved timestamp – a number of seconds since 1970 – to our reference date, and we then transform it into local time  - as opposed to UTC)

For Each ACEValues In arrayACEValues
    lstResults.Items.Add("Values for tag: " & ACEValues.TagName)
    For Each ACEEvent In ACEValues.PIACEEvents

        lstResults.Items.Add( _
            date1970.AddSeconds(ACEEvent.TimeStamp).ToLocalTime.ToString() _
            & " - " & _




Voila! You now have a good idea of how you can make use of some of the methods and objects exposed by the PI ACE 2.x web services.






Only a few minutes and 30 lines of code later, you enabled and exercised the consumption of PI data over web services in a cross-language, cross-platform, very lean and efficient environment.


Also important to note, is the fact that the PIACETagValues object is based on XML and is serializable; this means one can use it in controls such as the DataGridView (set its .DataMember property) and manipulate it in many different ways. Who knows, maybe that'll be in 'Part 2' :)


Let me know what you think!

Filter Blog

By date: By tag: