19 Replies Latest reply on Jul 2, 2014 10:34 PM by kokolopr

    Count System Digital States in a digital tag

    kokolopr

      Hello everybody

       

      I am trying to count number of bad digital events (system digital states) in a digital tag. I am using the following PI SDK function to filter them..

       

      mypoint = myserver.PIPoints.Item(pitagname)

      If myserver.PIPoints(pitagname.Trim).Data.Collecting = True Then
                'fetch events function and loop through events one-by-one

                myvalues = mypoint.Data.RecordedValues("-30d", "*", Nothing)
                mydigtotalEvents = myvalues.Count

       

      ---

       

      But all digital tag events are failing the data.collecting feature, why? How to go about it?

       

       

       

      Thanks in advance

       

      Prabhakar

       

      Saudi Aramco

        • Re: Count System Digital States in a digital tag

          Hello Prabhakar,

           

          In your code you just count the amount of events. In case a tag has a "bad" event, a state from SYSTEM Digital State Set, the IsGood property will be false. This is true as well for tags of type Digital.

           

          Please let me know if you find the following example useful:

           

           

           
          Imports PISDK
          Imports PISDKCommon
          Imports PITimeServer
          
          Module Module1
          
              Sub Main()
                  Try
                      Dim mySDK As New PISDK.PISDK()
                      Dim mySrv As Server = mySDK.Servers.DefaultServer
                      Dim myPtList As PointList
                      Dim myPt As PIPoint
                      Dim myValues As PIValues
                      Dim myValue As PIValue
                      Dim myState As DigitalState
                      Dim iCount As Integer
                      Dim iCountBad As Integer
                      mySrv.Open()
                      myPtList = mySrv.GetPoints("PtClassName = 'Classic' AND PointType = 'Digital'")
                      For Each myPt In myPtList
                          iCount = 0
                          iCountBad = 0
                          myValues = myPt.Data.RecordedValues("*-30d", "*", BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvShowFilteredState, Nothing)
                          For Each myValue In myValues
                              iCount = iCount + 1
                              myState = DirectCast(myValue.Value, DigitalState)
                              If myValue.IsGood() = False Then
                                  iCountBad = iCountBad + 1
                              End If
                          Next
                          Console.WriteLine(iCountBad.ToString() & "/" & iCount.ToString() & " SYSTEM states found for tag " & myPt.Name)
                      Next
                  Catch ex As Exception
                      Console.ForegroundColor = ConsoleColor.Red
                      Console.WriteLine(ex.Message)
                  Finally
                      Console.ForegroundColor = ConsoleColor.Gray
                      Console.Write("Done. Press any key to quit ...")
                      Console.ReadKey()
                  End Try
              End Sub
          
          End Module
          

           

            • Re: Count System Digital States in a digital tag
              kokolopr

              Thanks Gregor, that worked perfectly for digital tags. appreciate. Also, in a separate function i am looping all the numeric tags and its fails on one tag which has a BAD digital state inside it for 30 days. Although i am using type of function to check it.

               

               myserver = mysdk.Servers(plantServer)

               

                     myserver.Open(String.Empty)

               

                     If myserver.Connected = True Then

               

                         mypoint = myserver.PIPoints.Item(pitagname)

               

                          myValues = myPt.Data.RecordedValues("*-30d", "*", BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvShowFilteredState, Nothing)

               

                             For Each myValue In myValues

               

                                 myTagTimestamp = CStr(myvalues.value.TimeStamp.LocalDate)

               

                                 mycurrentTimeStamp = CDate(FormatDateTime(CDate(myTagTimestamp)))

               

                                 If myvalues.Item(CInt(i)).Value Is Nothing Or myvalues.Item(CInt(i)).IsGood = False Then

               

                                     'Bad Digital events isgood will take care

               

                                     If myvalues.Item(CInt(i)).Value.GetType.IsCOMObject Then

               

                                         DigitalValue = DirectCast(myvalues.Item(CInt(i)).Value, PISDK.DigitalState)

               

                                         my6badstatus = my6badstatus & String.Format(CStr(DigitalValue.Code))

               

                                     End If

               

                                     'my6badstatus = my6badstatus & myvalues.Item(CInt(i)).Value.ToString() & ";"

               

                                     myBadDigitalEvents = myBadDigitalEvents + 1

               

                                     If mybadstatusFlag = True Then

               

                                         mylastTimeStamp = mycurrentTimeStamp

               

                                     End If

               

                                     mybadstatusFlag = False

               

                                 ElseIf TypeOf (myvalues.Item(CInt(i)).Value) Is PISDK.DigitalState Then

               

                                     DigitalValue = DirectCast(myvalues.Item(CInt(i)).Value, PISDK.DigitalState)

               

                                     my6badstatus = my6badstatus & String.Format(CStr(DigitalValue.Code))

               

              ... fails, may be capturing time also will fail for a non-numeric tag

               

              myTagTimestamp = CStr(myvalues.value.TimeStamp.LocalDate)

               

              Thanks in advance and appreciate

               

              Prabhakar

               

              Saudi Aramco

                • Re: Count System Digital States in a digital tag

                  Hello Prabhakar,

                   

                  Your approach is correct. If you like to check on states from System Digital State Set, you check the IsGood property of the event (PIValue). Alternatively you can check if the PIValue is of type ComObject. It will be of ComObject for point type Digital anyhow. Hence if your code is supposed to work independently of the point type, I suggest checking for IsGood=False.

                   

                  Your code isn't working for me either but this might be because you just copied an excerpt. I however do see some issues and recommend reviewing your code e.g. if you are using For Each, you shouldn't be selecting by index. To illustrate what I am talking about, please review the following equivalent snippets.

                   

                   

                   
                              For Each myValue In myValues
                                  iCount = iCount + 1
                                  If myValue.IsGood = False Then
                                      iCountBad = iCountBad + 1
                                  End If
                              Next
                  

                   

                   
                              Dim iValues As Integer
                              iValues = myValues.Count
                              For iValIndex As Integer = 1 To iValues
                                  iCount = iCount + 1
                                  If myValues(iValIndex).IsGood = False Then
                                      iCountBad = iCountBad + 1
                                  End If
                              Next
                  

                   

                   

                   

                    • Re: Count System Digital States in a digital tag
                      kokolopr

                      Hi Gregor

                       

                      I am back to square one. This is for the last sample u sent. I tried the following code

                       

                                myserver = mysdk.Servers(plantServer)

                       

                                 myserver.Open(String.Empty)

                       

                                 If myserver.Connected = True Then

                       

                                     mypoint = myserver.PIPoints.Item(pitagname)

                       

                                     iCount = 0

                       

                                     iCountBad = 0

                       

                                     myvalues = mypoint.Data.RecordedValues("*-30d", "*", BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvShowFilteredState, Nothing)

                       

                                     getEventsdigital = "NORECORDS"

                       

                                     If myvalues.Count > 0 Then

                       

                                         getEventsdigital = "PASSED"

                       

                                         'loop for bad/good data

                       

                                         For Each myValue In myvalues

                       

                                             iCount = iCount + 1

                       

                                             If myValue.IsGood() = False Then

                       

                                                 iCountBad = iCountBad + 1

                       

                                             end if

                       

                                         Next

                       

                                      End if

                       

                      But it fails for one perticular tag, this tag is a digital tag, getting Bad value since last 6 months but has latest time stamps onit. what could be be the issue?

                       

                      Thanks

                       

                      Prabhakar

                        • Re: Count System Digital States in a digital tag
                          kokolopr

                          Hi Gregor

                           

                          Also, how to capture the status of a tag with PI-SDK codeing?

                           

                          Thanks

                            • Re: Count System Digital States in a digital tag
                              kokolopr

                              Hi Gregor

                               

                              I removed all code and ran the code for only digital tags and i found out that all digital tags which contained System Digital states 9bad) failed the RecordedValues function. Checked these failed tags by OLEDB Tester and found that they contained status -2, 307 etc. How can we capture the status value from SDK?

                               

                                        myserver = mysdk.Servers(plantServer)

                               

                                        myserver.Open(String.Empty)

                               

                                        If myserver.Connected = True Then

                               

                                             mypoint = myserver.PIPoints.Item(pitagname)

                               

                                             iCount = 0

                               

                                             iCountBad = 0

                               

                                             myvalues = mypoint.Data.RecordedValues("*-30d", "*", BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvShowFilteredState, Nothing)

                               

                                        End if

                               

                              But still it fails for all digital tags which have a bad state. Can we check why it does it> It is not even comming close to ISGOOD function. And it also fails the Try/Catch routine.

                               

                              Thanks

                               

                              Prabhakar

                                • Re: Count System Digital States in a digital tag

                                  Hello Prabhakar,

                                   

                                  At what point does the code fail? Is there an exception raised? If so, can you copy and paste the Message and InnerException?

                                   

                                  One thing that I can think of is that myvalues.Count = 0 or with other words there are no archived events for your PI Point within the query period.

                                   

                                  Can you please open PI SMT -> Archive Editor and retrieve the past 30 days of history? What do you get?

                                • Re: Count System Digital States in a digital tag

                                  Hello Prabhakar,

                                   

                                  Prabhakar

                                  Also, how to capture the status of a tag with PI-SDK codeing?

                                   

                                  Isn't this exactly the subject of our discussion or do you possibly refer to the questionable attribute of an event?

                                    • Re: Count System Digital States in a digital tag
                                      kokolopr

                                      Hi Gregor

                                       

                                      The calculation (windows Service written in ASP.NET 2010) fails at RecordedValues function.  Which is as shown below.

                                       

                                      myvalues = mypoint.Data.RecordedValues("*-30d", "*", BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvShowFilteredState, Nothing)

                                       

                                      I chekced with PI-SMT. The tag has 92 events since last 30d and all are showing "BAD" as it's value. Checked other tags which failed and also found that they have good numeric values but in-between they had "BAD" value. Which ever tag has a System digital State is failing. I even checked for count=0 but it fails before reaching this command.

                                       

                                      When i tried Try/Catch exception, it does not go into exception but simply the my service stops running.

                                       

                                      Regards

                                       

                                      Prabhakar

                                        • Re: Count System Digital States in a digital tag

                                          Hello Prabhakar,

                                           

                                          I believe if a service fails because of an unhandled exception, it writes to the Windows Application Event Log. Can you check with Windows event viewer for related messages?

                                           

                                          Does you service run under a specific service account or just as "Network Service" or "Local System"? Is this service running on the PI Server node?

                                           

                                          Authentication is often an issue with services. Depending on the service account and especially when connecting remotely, security might not be appropriate. If you are operating in a domain environment, the best option will be a specific service account created within the domain. You can then create a mapping between the domain account and a PI principal and allow read access to PI Point data for the PI principal.

                                           

                                          By the way, in case your issue is related to PI Point security, you should find messages with reference to the points ID stating "No read access. Secure object." in the PI Server log.

                                            • Re: Count System Digital States in a digital tag
                                              kokolopr

                                              Hi Gregor

                                               

                                              Windows event raises three of the following messages

                                               

                                              1. Log Name:      Application

                                               

                                              Source:        Application Error

                                               

                                              Date:          6/24/2014 7:14:45 AM

                                               

                                              Event ID:      1000

                                               

                                              Task Category: (100)

                                               

                                              Level:         Error

                                               

                                              Keywords:      Classic

                                               

                                              User:          N/A

                                               

                                              Computer:      SV800128.aramco.com

                                               

                                              Description:

                                               

                                              Faulting application name: DQAService.exe, version: 1.0.0.0, time stamp: 0x53a7ac58

                                               

                                              Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000

                                               

                                              Exception code: 0xc0000005

                                               

                                              Fault offset: 0x00000001

                                               

                                              Faulting process id: 0x10b0

                                               

                                              Faulting application start time: 0x01cf8f626681a259

                                               

                                              Faulting application path: D:\DQA\DQAService.exe

                                               

                                              Faulting module path: unknown

                                               

                                              Report Id: 1223d6bd-fb56-11e3-bd23-00155d36e734

                                               

                                              Event Xml:

                                               

                                              <Event xmlns="schemas.microsoft.com/.../event">

                                               

                                               <System>

                                               

                                                 <Provider Name="Application Error" />

                                               

                                                 <EventID Qualifiers="0">1000</EventID>

                                               

                                                 <Level>2</Level>

                                               

                                                 <Task>100</Task>

                                               

                                                 <Keywords>0x80000000000000</Keywords>

                                               

                                                 <TimeCreated SystemTime="2014-06-24T04:14:45.000000000Z" />

                                               

                                                 <EventRecordID>19736</EventRecordID>

                                               

                                                 <Channel>Application</Channel>

                                               

                                                 <Computer>SV800128.aramco.com</Computer>

                                               

                                                 <Security />

                                               

                                               </System>

                                               

                                               <EventData>

                                               

                                                 <Data>DQAService.exe</Data>

                                               

                                                 <Data>1.0.0.0</Data>

                                               

                                                 <Data>53a7ac58</Data>

                                               

                                                 <Data>unknown</Data>

                                               

                                                 <Data>0.0.0.0</Data>

                                               

                                                 <Data>00000000</Data>

                                               

                                                 <Data>c0000005</Data>

                                               

                                                 <Data>00000001</Data>

                                               

                                                 <Data>10b0</Data>

                                               

                                                 <Data>01cf8f626681a259</Data>

                                               

                                                 <Data>D:\DQA\DQAService.exe</Data>

                                               

                                                 <Data>unknown</Data>

                                               

                                                 <Data>1223d6bd-fb56-11e3-bd23-00155d36e734</Data>

                                               

                                               </EventData>

                                               

                                              </Event>

                                               

                                              2. Log Name:      Application

                                               

                                              Source:        Windows Error Reporting

                                               

                                              Date:          6/24/2014 7:14:58 AM

                                               

                                              Event ID:      1001

                                               

                                              Task Category: None

                                               

                                              Level:         Information

                                               

                                              Keywords:      Classic

                                               

                                              User:          N/A

                                               

                                              Computer:      SV800128.aramco.com

                                               

                                              Description:

                                               

                                              Fault bucket , type 0

                                               

                                              Event Name: BEX

                                               

                                              Response: Not available

                                               

                                              Cab Id: 0

                                               

                                              Problem signature:

                                               

                                              P1: DQAService.exe

                                               

                                              P2: 1.0.0.0

                                               

                                              P3: 53a7ac58

                                               

                                              P4: StackHash_f363

                                               

                                              P5: 0.0.0.0

                                               

                                              P6: 00000000

                                               

                                              P7: 00000001

                                               

                                              P8: c0000005

                                               

                                              P9: 00000008

                                               

                                              P10:

                                               

                                              Attached files:

                                               

                                              C:\Windows\Temp\WER37D3.tmp.appcompat.txt

                                               

                                              C:\Windows\Temp\WER391C.tmp.WERInternalMetadata.xml

                                               

                                              C:\Windows\Temp\WER394C.tmp.hdmp

                                               

                                              C:\Windows\Temp\WER68CA.tmp.mdmp

                                               

                                              These files may be available here:

                                               

                                              C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_DQAService.exe_eda4f5637ab69c278f33e26374f9165371b7df6b_cab_34af6af9

                                               

                                              Analysis symbol:

                                               

                                              Rechecking for solution: 0

                                               

                                              Report Id: 1223d6bd-fb56-11e3-bd23-00155d36e734

                                               

                                              Report Status: 4

                                               

                                              Event Xml:

                                               

                                              <Event xmlns="schemas.microsoft.com/.../event">

                                               

                                               <System>

                                               

                                                 <Provider Name="Windows Error Reporting" />

                                               

                                                 <EventID Qualifiers="0">1001</EventID>

                                               

                                                 <Level>4</Level>

                                               

                                                 <Task>0</Task>

                                               

                                                 <Keywords>0x80000000000000</Keywords>

                                               

                                                 <TimeCreated SystemTime="2014-06-24T04:14:58.000000000Z" />

                                               

                                                 <EventRecordID>19737</EventRecordID>

                                               

                                                 <Channel>Application</Channel>

                                               

                                                 <Computer>SV800128.aramco.com</Computer>

                                               

                                                 <Security />

                                               

                                               </System>

                                               

                                               <EventData>

                                               

                                                 <Data>

                                               

                                                 </Data>

                                               

                                                 <Data>0</Data>

                                               

                                                 <Data>BEX</Data>

                                               

                                                 <Data>Not available</Data>

                                               

                                                 <Data>0</Data>

                                               

                                                 <Data>DQAService.exe</Data>

                                               

                                                 <Data>1.0.0.0</Data>

                                               

                                                 <Data>53a7ac58</Data>

                                               

                                                 <Data>StackHash_f363</Data>

                                               

                                                 <Data>0.0.0.0</Data>

                                               

                                                 <Data>00000000</Data>

                                               

                                                 <Data>00000001</Data>

                                               

                                                 <Data>c0000005</Data>

                                               

                                                 <Data>00000008</Data>

                                               

                                                 <Data>

                                               

                                                 </Data>

                                               

                                                 <Data>

                                               

                                              C:\Windows\Temp\WER37D3.tmp.appcompat.txt

                                               

                                              C:\Windows\Temp\WER391C.tmp.WERInternalMetadata.xml

                                               

                                              C:\Windows\Temp\WER394C.tmp.hdmp

                                               

                                              C:\Windows\Temp\WER68CA.tmp.mdmp</Data>

                                               

                                                 <Data>C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_DQAService.exe_eda4f5637ab69c278f33e26374f9165371b7df6b_cab_34af6af9</Data>

                                               

                                                 <Data>

                                               

                                                 </Data>

                                               

                                                 <Data>0</Data>

                                               

                                                 <Data>1223d6bd-fb56-11e3-bd23-00155d36e734</Data>

                                               

                                                 <Data>4</Data>

                                               

                                               </EventData>

                                               

                                              </Event>

                                               

                                              3. Log Name:      Application

                                               

                                              Source:        Windows Error Reporting

                                               

                                              Date:          6/24/2014 7:14:59 AM

                                               

                                              Event ID:      1001

                                               

                                              Task Category: None

                                               

                                              Level:         Information

                                               

                                              Keywords:      Classic

                                               

                                              User:          N/A

                                               

                                              Computer:      SV800128.aramco.com

                                               

                                              Description:

                                               

                                              Fault bucket , type 0

                                               

                                              Event Name: BEX

                                               

                                              Response: Not available

                                               

                                              Cab Id: 0

                                               

                                              Problem signature:

                                               

                                              P1: DQAService.exe

                                               

                                              P2: 1.0.0.0

                                               

                                              P3: 53a7ac58

                                               

                                              P4: StackHash_f363

                                               

                                              P5: 0.0.0.0

                                               

                                              P6: 00000000

                                               

                                              P7: 00000001

                                               

                                              P8: c0000005

                                               

                                              P9: 00000008

                                               

                                              P10:

                                               

                                              Attached files:

                                               

                                              C:\Windows\Temp\WER37D3.tmp.appcompat.txt

                                               

                                              C:\Windows\Temp\WER391C.tmp.WERInternalMetadata.xml

                                               

                                              C:\Windows\Temp\WER394C.tmp.hdmp

                                               

                                              C:\Windows\Temp\WER68CA.tmp.mdmp

                                               

                                              These files may be available here:

                                               

                                              C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_DQAService.exe_eda4f5637ab69c278f33e26374f9165371b7df6b_cab_34af6af9

                                               

                                              Analysis symbol:

                                               

                                              Rechecking for solution: 0

                                               

                                              Report Id: 1223d6bd-fb56-11e3-bd23-00155d36e734

                                               

                                              Report Status: 0

                                               

                                              Event Xml:

                                               

                                              <Event xmlns="schemas.microsoft.com/.../event">

                                               

                                               <System>

                                               

                                                 <Provider Name="Windows Error Reporting" />

                                               

                                                 <EventID Qualifiers="0">1001</EventID>

                                               

                                                 <Level>4</Level>

                                               

                                                 <Task>0</Task>

                                               

                                                 <Keywords>0x80000000000000</Keywords>

                                               

                                                 <TimeCreated SystemTime="2014-06-24T04:14:59.000000000Z" />

                                               

                                                 <EventRecordID>19738</EventRecordID>

                                               

                                                 <Channel>Application</Channel>

                                               

                                                 <Computer>SV800128.aramco.com</Computer>

                                               

                                                 <Security />

                                               

                                               </System>

                                               

                                               <EventData>

                                               

                                                 <Data>

                                               

                                                 </Data>

                                               

                                                 <Data>0</Data>

                                               

                                                 <Data>BEX</Data>

                                               

                                                 <Data>Not available</Data>

                                               

                                                 <Data>0</Data>

                                               

                                                 <Data>DQAService.exe</Data>

                                               

                                                 <Data>1.0.0.0</Data>

                                               

                                                 <Data>53a7ac58</Data>

                                               

                                                 <Data>StackHash_f363</Data>

                                               

                                                 <Data>0.0.0.0</Data>

                                               

                                                 <Data>00000000</Data>

                                               

                                                 <Data>00000001</Data>

                                               

                                                 <Data>c0000005</Data>

                                               

                                                 <Data>00000008</Data>

                                               

                                                 <Data>

                                               

                                                 </Data>

                                               

                                                 <Data>

                                               

                                              C:\Windows\Temp\WER37D3.tmp.appcompat.txt

                                               

                                              C:\Windows\Temp\WER391C.tmp.WERInternalMetadata.xml

                                               

                                              C:\Windows\Temp\WER394C.tmp.hdmp

                                               

                                              C:\Windows\Temp\WER68CA.tmp.mdmp</Data>

                                               

                                                 <Data>C:\ProgramData\Microsoft\Windows\WER\ReportQueue\AppCrash_DQAService.exe_eda4f5637ab69c278f33e26374f9165371b7df6b_cab_34af6af9</Data>

                                               

                                                 <Data>

                                               

                                                 </Data>

                                               

                                                 <Data>0</Data>

                                               

                                                 <Data>1223d6bd-fb56-11e3-bd23-00155d36e734</Data>

                                               

                                                 <Data>0</Data>

                                               

                                               </EventData>

                                               

                                              </Event>

                                               

                                              Also i run the service under "Local System". no this Service is running on a seperate Server and has AD user read only access.

                                               

                                              Its ARAMCO Domain and this tag like others has read access. No, its not secuirity issue.

                                               

                                              Thanks in advance

                                               

                                              Prabhakar

                                                • Re: Count System Digital States in a digital tag

                                                  Hello Prabhakar,

                                                   

                                                  Exception code: 0xc0000005 indicates an access violation.

                                                   

                                                  Did you check the "attached files" referenced by WER? You should be able looking at the WER dumps using windbg.exe

                                                   

                                                  Honestly the messages are less useful than I expected and I tend looking into other options to collect information about the nature of the issue.

                                                   

                                                  Can you tell if the issue is reproducible for certain tags or does it e.g. occur after a period of time?

                                                   

                                                  Can you reproduce the failure in your development environment?

                                                   

                                                  Do you know exactly where your code fails? What line of code is causing the exception?

                                                   

                                                  The local and the PI Server's PI Message Log might contain additional information. Working with the logs in the forum is not ideal and because of this, I am thinking about involving Technical Support.

                                                    • Re: Count System Digital States in a digital tag
                                                      kokolopr

                                                      Hi Gregor

                                                       

                                                      I was looping and testing the above routine for 2000 tags and it was failing at this perticular tag 010XL1070.PV. The failed statement was recordedvalues. Then i put a if statement for it to skip the routine for first 1500 tags and check for last 500 tags (which included the 010XL1070.PV tag) and the service ran without any problem. The full function is as follows. What can be the issues here

                                                       

                                                         Function getEventsdigital(ByVal pitagname As String, ByVal plantServer As String) As String

                                                       

                                                             mydigbadstatus = "Failed Iteration, check tag attributes"

                                                       

                                                             getEventsdigital = "FAILED"

                                                       

                                                             Try

                                                       

                                                                 Dim myserver As PISDK.Server

                                                       

                                                                 Dim mysdk As PISDK.PISDK

                                                       

                                                                 Dim mypoint As PISDK.PIPoint = Nothing

                                                       

                                                                 Dim myValues As PISDK.PIValues = Nothing

                                                       

                                                                 Dim myValue As PIValue = Nothing

                                                       

                                                                 Dim DigitalValue As PISDK.DigitalState

                                                       

                                                                 mysdk = New PISDK.PISDK

                                                       

                                                                 Dim iCount As Integer

                                                       

                                                                 Dim iCountBad As Integer

                                                       

                                                                 Dim mybadstatusFlag As Boolean = False

                                                       

                                                                 Dim mycurrentTimeStamp As Date = Now

                                                       

                                                                 Dim mylastTimeStamp As Date = Now

                                                       

                                                                 mydigtotalEvents = 0

                                                       

                                                                 mydigBadDigitalEvents = 0

                                                       

                                                                 mydigdatagaphrs = 0

                                                       

                                                                 mydigbadstatus = ""

                                                       

                                                                 myserver = mysdk.Servers(plantServer)

                                                       

                                                                 myserver.Open(String.Empty)

                                                       

                                                                 If myserver.Connected = True Then

                                                       

                                                                     mypoint = myserver.PIPoints.Item(pitagname.Trim)

                                                       

                                                                     iCount = 0

                                                       

                                                                     iCountBad = 0

                                                       

                                                                     myValues = mypoint.Data.RecordedValues("*-30d", "*", BoundaryTypeConstants.btInside, "", FilteredViewConstants.fvShowFilteredState, Nothing)

                                                       

                                                                     getEventsdigital = "NORECORDS"

                                                       

                                                                     For Each myValue In myValues

                                                       

                                                                         iCount = iCount + 1

                                                       

                                                                         DigitalValue = DirectCast(myValue.Value, DigitalState)

                                                       

                                                                         If myValue.IsGood() = False Then

                                                       

                                                                             iCountBad = iCountBad + 1

                                                       

                                                                         End If

                                                       

                                                                     Next

                                                       

                                                                     getEventsdigital = "PASSED"

                                                       

                                                                     mydigtotalEvents = iCount

                                                       

                                                                     mydigBadDigitalEvents = iCountBad

                                                       

                                                                 End If

                                                       

                                                                 myserver.Close()

                                                       

                                                             Catch ex As Exception

                                                       

                                                                 getEventsdigital = "FAILEDFOR" & pitagname

                                                       

                                                                 mydigtotalEvents = -9

                                                       

                                                                 mydigBadDigitalEvents = -9

                                                       

                                                             End Try

                                                       

                                                             Dispose()

                                                       

                                                             Return getEventsdigital

                                                       

                                                         End Function

                                                       

                                                      Regards

                                                       

                                                      Prabhakar

                                                        • Re: Count System Digital States in a digital tag

                                                          Hello Prabhakar,

                                                           

                                                          You get an access violation when running your code for 2k points but it works when you break the 2k points into smaller chunks. I conclude your service exceeds the memory resources of your application node. You have modified your function to return the pi point name in case the exception is raised. Have you tried returning ex.Message?

                                                           

                                                           

                                                           
                                                                 Catch ex As Exception
                                                                     getEventsdigital = "FAILEDFOR" & pitagname & " - " & ex.Message
                                                                     mydigtotalEvents = -9
                                                                     mydigBadDigitalEvents = -9
                                                                 End Try
                                                          

                                                          Your function is called for each tag individually. Hence I expect resources would be freed up again. This makes me doubt the issue might be exceeding memory resources. Have you checked how memory consumption develops over time? You could collect performance counter data into PI tags using PI Performance Monitor interface or monitor resources through task manager.

                                                           

                                                          You are creating the connection to the PI Server within the function. This doesn't appear ideal to me. Instead of creating 2k connections, my idea would be to connect just once per cycle. Where do you get the tag names from? Do you maintain a document with tag names?

                                                           

                                                          As mentioned with other recent discussions where users asked how to do this or that in PI SDK, we nowadays suggest using AF SDK instead of PI SDK. The Rich Data Access assembly shipping with AF 2.6 should be preferred choice upon PI SDK with recent developments. 

                                                            • Re: Count System Digital States in a digital tag
                                                              kokolopr

                                                              thanks gregor for all the advise. Can u please let me know if recordedvalues function is multi-threaded? I mean when its processing and trying to get data from PI Server for one tag, the other tag recordedvalues would clash with it? Can i try Tread.Sleep command to make each recordedvalues process a tag sufficient time? I checked every possible way and found it will process this tag when number of records are less.

                                                               

                                                              I am going to try AFSDK soon.

                                                               

                                                              Thanks

                                                               

                                                              Prabhakae

                                                                • Re: Count System Digital States in a digital tag

                                                                  Hello Prabhakar,

                                                                   

                                                                  Please consider and use PI SDK single threaded. It offers the ability to handle callbacks asynchronously but if you create many threads in parallel which call RecordedValues for different tags you likely run into timing issues.

                                                                   

                                                                  PI Archive Subsystem is multi-threaded but the amount of threads is limited. PI Archive Subsystem threads are locking points when accessing them for read or write operations. Only one PI Archive Subsystem thread can access a PI Point at the same time. If there's an additional attempt from a second PI Archive Subsystem thread, this thread will have to wait until the first thread releases its lock to the point.

                                                                   

                                                                  There exists tuning parameter PIarchss_ThreadCount that controls the amount of threads PI Archive Subsystem will create. Threads will be used for different tasks like file management,  flush, read and write operations. The recommendation is setting PIarchss_ThreadCount equal to the amount of logical processors. AF SDK supports multi-threading but a client application should still not use a lot more threads querying for archive data than the PI System itself has to service the requests.

                                                                   

                                                                  With regards to your PI SDK based service, please don't try parallel processing.

                                                                    • Re: Count System Digital States in a digital tag
                                                                      JanvanderVen

                                                                      Hi,

                                                                       

                                                                      Gregor is right: "please don't try parallel processing.". I've been there, and I regret it.

                                                                       

                                                                      Kind regards,

                                                                       

                                                                      Jan

                                                                        • Re: Count System Digital States in a digital tag

                                                                          Hello Prabhakar,

                                                                           

                                                                          I was pinged there are a few things to clarify with my reply:

                                                                           

                                                                          1. First and foremost, probably the best way to achieve high performance is through bulk calls (potentially asynchronously) with AF SDK 2.5/2.6 and PI Server 2012 or later. In comparison to multi-threaded operation, bulk calls are processed in parallel on the server side, without any added complexity in client apps. Please take a look at Optimizing PI AF Server and PI AF SDK Applications for Performance and Scalability

                                                                           

                                                                          2. Please do not change PIArchss_ThreadCount except being advised to do so by OSIsoft Technical Support. The default of 8 RPC threads should be sufficient for nearly all installations. As long as you don't experience any issues, please don't touch PIArchss_ThreadCount. If you experience issues or are in doubt, please consult with OSIsoft Technical Support.

                                                                           

                                                                          3. Point locks in the Archive Subsystem allow either 1 writer (e.g., Flush thread), or N readers. Therefore all RPC threads can be servicing queries for the same PI Point, if necessary.

                                                                    • Re: Count System Digital States in a digital tag
                                                                      kokolopr

                                                                      Hi Gregor

                                                                       

                                                                      Finally resolved the issue. It was as you suggested, too many open/close of PI Server connections. Removed all of them i used just one connection for a single cycle and recorded values working fine. tested it for 100000 tags loop. thanks a lot.

                                                                       

                                                                      Prabhakar