3 Replies Latest reply on May 2, 2014 3:06 PM by Rick Davin

    Write String to PI Tag in VB


      Does anyone have example code of this? I'm simply trying to write a value in a text box (string) to a PI tag,





        • Re: Write String to PI Tag in VB

          Hello Trevor,


          Refer the example for updatevalue given in C:\Program Files (x86)\PIPC\HELP\pisdk.chm.

            • Re: Write String to PI Tag in VB
              Marcos Vainer Loeff

              Hello Trevor,


              If you are programming against VB.NET with .NET Framework 4 or 4.5, I would suggest you to use PI AF SDK 2012 (for .NET Framework 4) or PI AF SDK 2014 (for .NET Framework 4.5). Those versions of the product comes with Rich Data Access feature that allow y ou to connect directly to your PI Data Archive. Please check the Hands-On-Lab called "Migrating application from PISDK to PI AF SDK" from vCampus Live! 2013 which could be downloaded from the vCampus Download Center under extras category. You also should download PI AF Developer Tools 2014 which comes with the PI AF SDK programming reference. You should take a look at the UpdateValue() method from the PIPoint class within OSIsoft.AF.PI namespace.


              Hope this helps!!

                • Re: Write String to PI Tag in VB
                  Rick Davin

                  I was a bit confused by the title.  Are you trying to write to a PI Tag that is of Point Type String, or is the destination tag a Float32 or Int32?  Besides the basic mechanics of writing any value to a PIPoint, there are a few things to keep in mind:


                  A PIPoint of string has a value limit.  I'm guessing in neighborhood of 976 characters, but don't take that as gospel.  I could look it up, or you could.  I think you'd learn more if you looked it up ;-)


                  When dealing with system states and string PI Points, it gets messy.  If you attempt to write "No Result" to a Float32 tag, no problem.  Since "No Result" is not a number, PI attempts to use the "No Result" digital state.  If you write "No Result" to a string tag, how does PI know whether or not you want to write the string as is or else convert to the digital state?


                  Ditto if the tag is a digital tag and your custom digital stateset has states that may be ambiguous with system digital states.  By default (I believe), PI will try to map to your custom digital states first.


                  If writing to a non-string tag, you must attempt to convert the textbox.Text to the target data type.  If the text can be converted to a Single for a Float32 tag, then you're good.  If the text fails to convert, then you could probably safely assume the text is a digital state.  So if you are writing to a Float32 tag, you would get an error attempting to write the string "7.5".  But you could write 7.5 by using the legacy CSng() function or the .NET Convert.ToSingle() method.