12 Replies Latest reply on Jan 23, 2015 9:38 PM by proberts

    how can I use SMT3's archive editor to modify a point of type blob?

    proberts

      I've created a point of type blob using SMT3's point builder; it currently has a value of "Pt Created".  How can I assign a value to this using SMT3's Archive Editor?

      It seems to want only Analog or Digital from the selection box.

        • Re: how can i user SMT3's archive editor to modify a point of type blob?
          jose_dai

          Hi Peter,

           

          What kind value do you want to modify into the blob tag?, I did the test and effectively only permit put analog and digital values.

           

          Regards

          • Re: how can i user SMT3's archive editor to modify a point of type blob?
            pthivierge

            Hello Peter,

             

            Blob are a typically chosen to store arrays of bytes. Its maximum size is 976 bytes.

            Definitions Here.

             

            I believe that PI SMT cannot convert the value you enter into bytes, you would need to do that using a programmatic approach.

             

            A string tag has the same size limit as per this KB: https://techsupport.osisoft.com/Troubleshooting/KB/1482OSI8

            So to write using PI SMT, I would definitely use a string tag.

            • Re: how can i user SMT3's archive editor to modify a point of type blob?
              dng

              Hi Peter,

               

              Can you let us know what the application is for using a BLOB point type? Perhaps you can also comment on this post: What do you want to BLOB (not Blog) about??

              Usually, we can substitute BLOB with other point types. Since BLOB is inherently arbitrary, a lot of times it will be easier to use/manipulate other point types.

              If you would like to work with the tag programmatically, you can check out similar posts such as Getting snapshot and updating blob PI Point in C++.

              • Re: how can I use SMT3's archive editor to modify a point of type blob?
                gachen

                As Patrice and Daphne have both mentioned, blob tags are used to store arbitrary arrays of bytes. Because of this, their real purpose is to act as a custom type that you can use in PI tags when other types do not suit your needs (float, int, digital, string, etc). As such, being a "custom" type, the expectation is that the user defines how to read/write to/from blob tags, as the user is the only one who would understand what this byte array represents.

                 

                I would recommend (as the others have) to try and find another existing type that would be suitable for your needs. If a blob tag is absolutely necessary, then we'd probably have to discuss more the actual use case and determine if there would be a good way to access the tag programmatically.

                  • Re: how can I use SMT3's archive editor to modify a point of type blob?
                    proberts

                    ok.  So the REAL reason I asked the question was because I managed to get an application crash that affected my PI server; this is under investigation (OSIsoft TechSupport Case # 606272).

                    I created a tag ("t_blob")using SMT3's Point Builder of type Blob.  I then used SMT3's Archive Editor to add a value.  I tried a numeric and that was rejected; I then tried a string ("hello") and that, too, was rejected.  I then tried the drop-down selector for the value which only offers analog or digital, and those values (a numeric of 1) , also, were rejected. I understood a blob to be of type byte array, and guessed I could try a comma-delimited string ("1,2,3,4"); this crashed SMT3, and also disconnected all of my networked connections (I  was using PI-SMT in excel on another machine at the time).

                    So in summary, I haven't found a way of updating or adding a value to this tag, and was wondering if anyone else had; it seems that no-one has either!

                      • Re: how can I use SMT3's archive editor to modify a point of type blob?
                        gachen

                        From the Tech Support case, it appears that SMT crashed due to an InvalidCastException, which is likely due to some failure converting your string to a byte array. I was not able to reproduce the crash by entering "1,2,3,4" for a blob tag. Perhaps there were some other steps taken for SMT to crash?

                         

                        However, SMT crashing should not be causing any kind of network disconnections for other programs. What kind of symptoms did you see in the PI-SMT Excel plug-in on the other machine?

                         

                        To write to the blob tag, I found that you can actually use PI System Explorer to do this. You would need to create an attribute of type "Byte Array", then link this to the blob tag using a PI Point Data Reference. You can then specify the value (in decimal, 0-255) of each byte of the array. Keep in mind that there still aren't any good ways to "read" the values, since none of our programs will know what this byte array represents. If you look at the value in SMT, it will just say "<blob>". This again leads us to the original question... what are these blob tags being used for?

                          • Re: how can I use SMT3's archive editor to modify a point of type blob?
                            proberts

                            Thanks for your response.  I was creating some test tags (1 of each type)  with a value of 1 (or "1" as appropriate) to check that I could successfully read snapshot values for all (current) known tag types; I got stuck with the blob tag.  This was the first step in developing an app, so I don't actually have a proper purpose for such a tag, other than "can I read a snapshot value from such a tag?".  I guess that, without having a properly defined purpose (from a customer?) for such a tag, when I code my solution I'll just have to return something like "currently unsupported", and the problem goes away...

                            • Re: how can I use SMT3's archive editor to modify a point of type blob?
                              proberts

                              I should also have answered your other questions; my apologies.

                              I'm not aware of any other steps I took that caused the App crash.  As to the symptoms in PI-SMT Excel plugin, I received a timeout and network disconnection (not sure of the actual wording now); reconnections were initially rejected (too soon to reconnect, please try later) before I could reconnect (a matter of a minute or so).

                        • Re: how can I use SMT3's archive editor to modify a point of type blob?
                          proberts

                          To complete the discussion, I've now used Excel and VBA to both write and read a tag of type Blob.

                          To read I needed to use a variant datatype and then assign the "value" entity to another variant which I processed as a byte array, concatenating each value into a delimited string.  Tedious, but it works.

                          To write I assigned the delimited string elements to a redim'd byte array of the correct size and passed this to the PI value element, along with annotation and timestamp.  This also works.  Code snippets could be available if anyone is interested.

                            • Re: how can I use SMT3's archive editor to modify a point of type blob?
                              dng

                              Hi Peter,

                               

                              Thank you for the update! Since you offered, would you mind posting your code snippets in case some community members is interested in it now or in the future? Thanks.

                                • Re: how can I use SMT3's archive editor to modify a point of type blob?
                                  proberts

                                  Ok.  Here’s a sample procedure to read and write to a tag of type blob using Excel 2007 VBA

                                   

                                   

                                   

                                  Sub petersReadTag()

                                      Dim cxn As New PISDKDlg.Connections

                                      Dim aServer As Server

                                   

                                      'establish PI connection

                                      cxn.ShowConnectionDialog False, vbModal

                                      If cxn.Login.Connected Then

                                          Set aServer = Servers(cxn.Login.name)

                                          aServer.Open (cxn.Login.CurrentUser)

                                      Else

                                          MsgBox "no PI connection"

                                          Exit Sub

                                      End If

                                   

                                      'check it's valid

                                      If aServer Is Nothing Then

                                          MsgBox "invalid PI connection"

                                          Exit Sub

                                      End If

                                   

                                      On Error Resume Next

                                    

                                      Dim aTag As String

                                      aTag = "t_blob" ' name of tag of type blob

                                   

                                      Dim pipt As PISDK.PIPoint

                                      Set pipt = aServer.PIPoints(aTag)

                                   

                                      On Error GoTo 0

                                   

                                      If pipt Is Nothing Then

                                   

                                          MsgBox "tag not found, or not connected"

                                          Exit Sub

                                   

                                      End If

                                   

                                      Dim tStamp As String

                                                   

                                      If pipt.PointType = pttypBlob Then

                                   

                                          Dim vpv As Variant

                                          ' get the snapshot value

                                   

                                          Set vpv = pipt.Data.Snapshot

                                          If vpv Is Nothing Then

                                   

                                              MsgBox "Error reading tag value"

                                              Exit Sub

                                   

                                          End If

                                   

                                          'convert the variant to a string for representation purposes

                                   

                                          Dim z

                                          z = vpv.Value ' this is a byte array

                                   

                                          Dim s As String

                                          Dim j As Integer

                                   

                                          s = ""

                                   

                                          j = 0

                                   

                                          Do

                                              If j >= 976 Then Exit Do

                                              If z(j) = 0 Then Exit Do

                                              If s <> "" Then s = s & ";"

                                             s = s & CStr(z(j))

                                              j = j + 1

                                          Loop

                                   

                                          tStamp = Format(vpv.timestamp.LocalDate, "dd-mmm-yyyy hh:mm:ss")

                                          MsgBox "tag=\\" & aServer.name & "\" & pipt.name & vbCrLf & "array()=" & s & vbCrLf & "timestamp=" & tStamp

                                   

                                      Else

                                   

                                          Dim pv As PISDK.PIValue

                                   

                                            ' get the snapshot value

                                            Set pv = pipt.Data.Snapshot

                                   

                                          If pv Is Nothing Then

                                              MsgBox "Error reading tag value"

                                              Exit Sub

                                          End If

                                   

                                          tStamp = Format(pv.timestamp.LocalDate, "dd-mmm-yyyy hh:mm:ss")

                                          MsgBox "tag=\\" & " & aServer.name & "\" & pipt.name & vbCrLf & "value=" & pv.Value & vbCrLf & "timestamp=" & tStamp

                                   

                                      End If

                                   

                                  End Sub

                                   

                                   

                                  Sub petersWriteTag()

                                   

                                      Dim cxn As New PISDKDlg.Connections

                                      Dim aServer As Server

                                   

                                      'establish PI connection

                                      cxn.ShowConnectionDialog False, vbModal

                                      If cxn.Login.Connected Then

                                          Set aServer = Servers(cxn.Login.name)

                                          aServer.Open (cxn.Login.CurrentUser)

                                      Else

                                          MsgBox "no PI connection"

                                          Exit Sub

                                      End If

                                   

                                      'check it's valid

                                   

                                      If aServer Is Nothing Then

                                          MsgBox "invalid PI connection"

                                          Exit Sub

                                      End If

                                   

                                      On Error Resume Next

                                   

                                      Dim aTag As String

                                      aTag = "t_blob" ' name of tag of type blob

                                   

                                      Dim pipt As PISDK.PIPoint

                                      Set pipt = aServer.PIPoints(aTag)

                                   

                                      On Error GoTo 0

                                   

                                      If pipt Is Nothing Then

                                          MsgBox "tag not found, or not connected"

                                          Exit Sub

                                      End If

                                   

                                      Dim piVal As PIValue

                                      Set piVal = New PISDK.PIValue

                                   

                                      If pipt.PointType = pttypBlob Then

                                                    

                                          Dim bpv() As Byte

                                          Dim sa() As String

                                   

                                          Dim dlimiter As String

                                          dlimiter = ";"

                                          dim tx as string

                                           tx = "1;2;3;4'

                                          sa = Split(tx, dlimiter, , vbTextCompare)

                                   

                                          j = Application.CountA(sa)

                                          ReDim Preserve bpv(0 To j)

                                   

                                          j = 0

                                          Dim qs

                                          For Each qs In sa

                                   

                                              If CInt(qs) > 255 Then

                                                  MsgBox "values cannot exceeed 255"

                                                  Exit Sub

                                              Else

                                                  bpv(j) = CInt(qs)

                                              End If

                                              j = j + 1

                                          Next

                                   

                                          piVal.Value = bpv

                                   

                                      Else

                                          piVal.Value = .Range("values").Offset(r, 0).Value

                                      End If

                                   

                                      'set the timestamp

                                      Dim ts As New PITimeFormat

                                      ts.FormatString = "dd-mmm-yyyy hh:mm:ss"

                                      ts.InputString = "*"

                                     Set piVal.timestamp = ts

                                   

                                      ' inserting values in PI

                                      pipt.Data.UpdateValue piVal, DataMergeConstants.dmReplaceDuplicates

                                   

                                  End Sub