12 Replies Latest reply on Dec 8, 2016 1:55 PM by gregor

    using SDK functions in ASP

    jfarrera

      Hi, I would like to know if you can facilitate some ASP examples of SDK functions to read anr write tags values

       

      Regards

       

       

        • Re: using SDK functions in ASP
          Daniel Takara

          Hola Julio,

           

          I am not really an ASP expert, but I took this as an opportunity to try and learn too.

           

          Starting from the ASP/PI-SDK sample code to list the states of a digital set (available on the PI-SDK online help), I managed to elaborate some code to get archive data of a PI tag and write values to a PI tag using ASP/PI-SDK. It has minimal error checking, but it works.

           

          This assumes you've got the PI-SDK installed on the web server (IIS, in this case, as we're talking about ASP) and trust/SSPI settings properly defined in PI for the web server.

           

          To get the archive data, you can basically write an .htm file and a .asp file:

           

          GetTagValues.htm

           

          <HTML>
          <HEAD>
          <TITLE></TITLE>
          </HEAD>
          <BODY>
          <Form Action="GetTagValues.asp" Method="POST">
          <P><STRONG><FONT face="" size=5>Example to Get Tag Values</FONT></STRONG></P>
          <P>Enter Server Name:
          <INPUT id=text1 name=text1></P>
          <P>Enter Tag Name:
          <INPUT id=text2 name=text2></P>
          <P>Enter Start Time:
          <INPUT id=text3 name=text3></P>
          <P>Enter End Time:
          <INPUT id=text4 name=text4></P>
          <P><INPUT id=submit1 name=submit1 type=submit value=Submit></P>
          </FORM>
          </BODY>
          </HTML>

           

          GetTagValues.asp

           

          <%@ Language=VBScript %><HTML>
          <HEAD>
          </HEAD>
          <BODY>
          <P> </P>
          <%
          set pisdk = Server.CreateObject("PISDK.PISDK")
          strServerName = Request.Form("text1")
          strTagName = Request.Form("text2")
          strStartTime = Request.Form("text3")
          strEndTime = Request.Form("text4")
          set srv = pisdk.Servers(strServerName)
          set pt = srv.PIPoints(strTagName)
          set dat = pt.Data
          boundaryType = 0 'btInside
          set asyncStatus = Nothing
          set PIvalues = dat.RecordedValues(CDate(strStartTime), CDate(strEndTime),boundaryType,,,asyncStatus)
          for each PIvalue in PIvalues
             Response.Write "<P>" & PIvalue.TimeStamp.LocalDate & " -- " & PIvalue.Value & " </P>"
          next
          %>
          </BODY>
          </HTML>

           

          To write values to a PI tag, you can use something like the .htm file and a .asp file below:

           

          WriteTagValue.htm

           

          <HTML>
          <HEAD>
          <TITLE></TITLE>
          </HEAD>
          <BODY>
          <Form Action="WriteTagValue.asp" Method="POST">
          <P><STRONG><FONT face="" size=5>Example to Write a Value to a Tag for a Specied Timestamp </FONT></STRONG></P>
          <P>Enter Server Name: 
          <INPUT id=text1 name=text1></P>
          <P>Enter Tag Name:
          <INPUT id=text2 name=text2></P>
          <P>Enter Timestamp:
          <INPUT id=text3 name=text3></P>
          <P>Enter Value:
          <INPUT id=text4 name=text4></P>
          <P><INPUT id=submit1 name=submit1 type=submit value=Submit></P>
          </FORM>
          </BODY>
          </HTML>

           

          WriteTagValue.asp

           

          <%@ Language=VBScript %><HTML>
          <HEAD>
          </HEAD>
          <BODY>
          <P> </P>
          <%
          set pisdk = Server.CreateObject("PISDK.PISDK")
          strServerName = Request.Form("text1")
          strTagName = Request.Form("text2")
          strTimestamp = Request.Form("text3")
          strValue = Request.Form("text4")
          Response.write "<SPAN STYLE='font-weight : bold;'>" & strStateSet & "</SPAN>"
          set srv = pisdk.Servers(strServerName)
          set pt = srv.PIPoints(strTagName)
          set dat = pt.Data
          mergeType = 0 'dmReplaceDuplicates
          set asyncStatus = Nothing
          dat.UpdateValue strValue, CDate(strTimestamp),mergeType,asyncStatus
          If Err.number <> 0 then
            TrapError Err.description
          else
            Response.Write "<span style='font-weight : bold;'>" & "Value " & strValue & " was written successfully for

           

          tag " & strTagName & " at timestamp " & strTimestamp & "</span>"
          End If

           

          %>
          </BODY>
          </HTML>

           


          Regarding security and permissions, you may want to set it up both in IIS and PI, so that the users will be granted with the proper priviledges when requesting archive data of the PI tag or sending data to a PI tag using the ASP page.

           

          This is my understanding of the details of the sequence of requests among all the modules involved (everyone is welcome to make corrections or further comments):

           

          authentication2_5F00_sm2.JPG

           

          ===========

           

          01. The user has logged on to Windows in his machine MACHINE01 with the domain account DOMAIN01\USER_XYZ. He/She opens the Internet Explorer web browser and types the URL http://webserver01/GetTagValues.htm in the address bar. The web browser makes a request to download GetTagValues.htm from the web server webserver01, providing user authentication information to IIS on webserver01.

           

          02. IIS on webserver01 checks the authentication information provided by the web browser on step 01 with the Active Directory Domain Controller.

           

          03. The Active Directory Domain Controller confirms the authenticity of the authentication information provided by the web browser on step 01.

           

          04. IIS returns the requested file GetTagValues.htm to the web browser.

           

          05. The user clicks on the "Submit" button on web page GetTagValues.htm.

           

          06. The GetTagValues.htm web page calls the routine defined on file GetTagValues.asp, which requests archive data of PI tags from PI Server piserver01, by means of the PI-SDK installed on webserver01.

           

          07. Triggered by a command on GetTagValues.asp, the Microsoft surrogate process on webserver01 (DLLHOST.exe) requests a connection to the PI Server on piserver01 via the PI-SDK, providing authentication information received by the web browser on step 01.

           

          08. piserver01 checks with the Active Directory Domain Controller the authenticity of information related to OS domain and OS user provided by DLLHOST.exe of webserver01 on step 07.

           

          09. The Active Directory Domain Controller confirms the authenticity of the authentication information provided by DLLHOST.exe of webserver01 on step 07.

           

          10. This step depends on the PI Server version:

           

          - case 1: the PI Server on piserver01 is version 3.3 onwards

           

          The connection between the PI Server on piserver01 and DLLHOST.exe on webserver01 is established with the credentials of a PI User, depending on how the records in the PI Trust table of piserver01 are specified. The credentials of that PI User must have appropriate read/write access based on what your PI SDK calls need to do.

           


          - case 2: the PI Server on piserver01 is version 3.4.380 onwards and the PI-SDK on webserver01 is version 1.3.6.361 onwards and configured to connect to the PI Server on piserver01 via SSPI/NTLM

           

          The connection between the PI Server on piserver01 and DLLHOST.exe on webserver01 is established with the credentials of a PI Principal (which can be a PI User, a PI User Group or a PI Identity), depending on how the records of its PI mapping table are specified (the PI mapping table maps Microsoft Active Directory accounts/groups or Windows local accounts/groups to PI principals). The credentials of that PI Principal must have appropriate read/write access based on what your PI SDK calls need to do.

           

          11. A command in GetTagValues.asp requests archive data of a PI tag.

           

          12. The PI Server returns the requested archive data of the PI tag to IIS on webserver01.

           

          13. IIS receives the requested archive data of the PI tag, which is used to render the ASP server code to generate the html to be returned to the web browser.

           

          14. The web browser receives the web page rendered by the ASP code of GetTagValues.asp.

           

          ===========

           

          In order to enforce steps 02 and 03 (to implement proper IIS security), you may follow the suggestion from the PI-SDK documentation: "To fully secure access to the application, the virtual directory should be set to use "Integrated Windows Authorization" in IIS.  Using Windows Explorer, the ASP file should be made accessible only to the desired domain users.  When configured in this manner, browsers connecting to this page will be issued a challenge (often silently) and if the authentication is successful the page will run in IIS impersonating the logged on user of the browser.  Behind the scenes, the PI-SDK obtains the identity of the logged in user and passes it to the server.  The server validates this identity against the domain controller.  This means that users outside the domain and associated trusted domains can not be validated and will not be granted a trust connection."

           

          The screenshots below illustrate how you would set this up in IIS 6.0:

           

          iis01.JPG

           

          iis02.JPG

           

          iis03.JPG

           


          Hope this helps.

           

           

          1 of 1 people found this helpful
            • Re: using SDK functions in ASP
              jfarrera

              Thank you Daniel,

               

              For your quick and usefully response, I have been able to read and write tags values from the PI server now

               

              Regards

               

               

                • Re: using SDK functions in ASP

                  Wow, as Julio wrote: what a quick and useful reply! Very good work, especially on the flow/security diagram - you even included a few words on Windows Integrated Security in PI 3.4.380.

                   

                  Just a couple quick comments:
                    - I think you need to swap numbers 2 and 3 in the diagram
                    - On #10, I would suggest adding a few words on the fact that the credentials applied to the connection are those defined in the PI Trust. How about something like this: "The connection between the PI Server on piserver01 and DLLHOST.exe on webserver01 is established with the credentials specified in the PI Trust. These credentials must have appropriate read/write access based on what your PI SDK calls need to do."
                   
                  I'm starting to think it would be worth creating a White Paper out of this topic, which would be published on the vCampus Library. That's also something you might want to add to the Your ideas of topics for webinars!! post in the Generic vCampus Discussion

                    • Re: using SDK functions in ASP
                      Daniel Takara

                      Steve, thank you very much for your careful and insightful review! I just edited my post taking your suggestions into consideration.

                       

                      Regarding a white paper on this topic, yes, that would be very, very interesting! I'm really interested in WIS and I even participated in the 380 beta program. Really nice opportunity to interact with the great PI Server team!

                        • Re: using SDK functions in ASP

                          Steve, where is the OSI hint for Web Services and PI?
                          I would keep one eye on the developments OSI are doing in this arena if you have requirements for web based access to data from PI, especially when later versions will include access to AF.

                            • Re: using SDK functions in ASP

                              Very good point! You're like that little voice that reminds me of important things

                               

                              @Julio: as Rhys' suggested, we are working on a new offering called PI Web Services - I suggest you start a new thread there, I'm sure the dev team will be happy to answer your questions For those who recently joined vCampus or just haven't heard of that, a new product called PI Web Services is now available to vCampus members exclusively, as a Community Technology Preview (CTP).

                               

                              You can find all the info on how to try it out in the Web Services and PI blog, and then post your questions and feedback on the Web Services and PI forum.

                                • Re: using SDK functions in ASP
                                  mjarvis

                                  I'm trying to use the code to retrieve archive values, but I get a http 500 error. Do I need to enable anything special for asp? I'm really looking for a simple way to get PI WebServices values via HTML, is there an easy way?

                                    • Re: using SDK functions in ASP

                                      @Michael: just to make sure, are you trying to use the code above (with PI SDK) or you are trying to make use of the PI Web Services product, as your post seems to indicate?

                                       

                                      If it's the latter, you might want to post in the "Web Services and PI" discussion forum.

                                       

                                      If you are really trying to use the code above to make of PI SDK, can you indicate when exactly this error is occurring?

                                        • Re: using SDK functions in ASP
                                          mjarvis

                                          Not sure what was wrong with the code before, but this code worked for me

                                           

                                          <%@ Language=VBScript %><HTML>

                                           

                                          <HEAD>

                                           

                                          </HEAD>

                                           

                                          <BODY>

                                           

                                          <P> </P>

                                           

                                          <%

                                           

                                          set pisdk = Server.CreateObject ("PISDK.PISDK")

                                           

                                          set srv = pisdk.Servers("pitemp")

                                           

                                          'Define which points you need values for

                                           

                                          set pt1 = srv.PIPoints("sinusoid").Data.Snapshot

                                           

                                          set pt2 = srv.PIPoints("cdt158").Data.Snapshot

                                           

                                          set pt3 = srv.PIPoints("sinusoidu").Data.Snapshot

                                           

                                          set pt4 = srv.PIPoints("ba:active.1").Data.Snapshot

                                           

                                          set pt5 = srv.PIPoints("ba:conc.1").Data.Snapshot

                                           

                                          'This is where the response is written to the page

                                           

                                          Response.Write "<P>" & pt1.Value & "  " & pt1.TimeStamp.LocalDate & "</P>"

                                           

                                          Response.Write "<P>" & pt2.Value & "  " & pt2.TimeStamp.LocalDate & "</P>"

                                           

                                          Response.Write "<P>" & pt3.Value & "  " & pt3.TimeStamp.LocalDate & "</P>"

                                           

                                          Response.Write "<P>" & pt4.Value & "  " & pt4.TimeStamp.LocalDate & "</P>"

                                           

                                          Response.Write "<P>" & pt5.Value & "  " & pt5.TimeStamp.LocalDate & "</P>"

                                           

                                          %>

                                           

                                          </BODY>

                                           

                                          </HTML>

                                            • Re: using SDK functions in ASP
                                              mhamel

                                              @Michael: You must use CreateObject method directly. You use also Document.Write instead of Response.Write.

                                               

                                               <%@ Language=VBScript %><HTML>
                                              <HEAD>
                                              </HEAD>
                                              <BODY>
                                              <P> </P>

                                               

                                              <script type="text/vbscript">
                                              Document.write("My Test Page...")

                                               

                                              Set PISDK = CreateObject ("PISDK.PISDK")
                                              Set SRV = PISDK.Servers("MANTI-CORE")

                                               

                                              'Define which points you need values for
                                              Set pt1 = SRV.PIPoints("sinusoid").Data.Snapshot
                                              Set pt2 = SRV.PIPoints("cdt158").Data.Snapshot
                                              Set pt3 = SRV.PIPoints("sinusoidu").Data.Snapshot
                                              Set pt4 = SRV.PIPoints("ba:active.1").Data.Snapshot
                                              Set pt5 = SRV.PIPoints("ba:conc.1").Data.Snapshot

                                               

                                              'This is where the response is written to the page
                                              Document.Write "<P>" & pt1.Value & "  " & pt1.TimeStamp.LocalDate & "</P>"
                                              Document.Write "<P>" & pt2.Value & "  " & pt2.TimeStamp.LocalDate & "</P>"
                                              Document.Write "<P>" & pt3.Value & "  " & pt3.TimeStamp.LocalDate & "</P>"
                                              Document.Write "<P>" & pt4.Value & "  " & pt4.TimeStamp.LocalDate & "</P>"
                                              Document.Write "<P>" & pt5.Value & "  " & pt5.TimeStamp.LocalDate & "</P>"

                                               

                                              </script>
                                              </BODY>
                                              </HTML>

                                               

                                              Let me know if that worked for you.

                                • Re: using SDK functions in ASP
                                  Daniel Takara

                                  Julio Farrera

                                  Thank you Daniel, For your quick and usefully response

                                   

                                  You are very welcome, Julio. I'm glad I could help.

                                • Re: using SDK functions in ASP
                                  gregor

                                  Hello Guillaume BOURSIER,

                                   

                                  Because you marked Daniel Takara's reply as helpful, please note that this is an older discussion from 2009. After cross-reading it, I like to let you know that the content is kind of outdated.

                                  PI SDK has been announced deprecated meanwhile and there are other Developer Technologies today that are a better fit.

                                  PI AF SDK is our recommendation when developing managed .NET applications. PI Web API is a RESTful service which includes Windows authentication but will require you to configure your ASP.Net application for Kerberos and the PI Web API host for Kerberos Delegation to allow forwarding Windows credentials over multiple hops.

                                  1 of 1 people found this helpful