Tag Archives: pi-sdk-vba

Read and Write A Tag Value From PI-Server Using PI-SDK Through VBA (Visual Basic)

13 Mar

Reading a tag value from PI-Server

Private Function TargetValue()
Dim valueRet As String
Dim srv As Server
Dim dt As New PITimeFormat
Dim pt As PIPoint

Dim MYPIServer As PISDK.Servers
Set srv = PISDK.Servers.DefaultServer

TargetValue = srv.PIPoints(“Target”).Data.Snapshot

‘ Target is the tag name here.
End Function

Writing a tag value to PI-Server

‘***************************Writing into Target Tag****************************
Private Sub WriteTargetInstructionPI()
Dim srv As Server
Dim dt As New PITimeFormat
Dim pt As PIPoint

Dim MYPIServer As PISDK.Servers
Set srv = PISDK.Servers.DefaultServer

TagName = “Target”
Set pt = srv.PIPoints(TagName) ‘ it’s your PI point

dt.InputString = “*”        ‘it’s data. InputString – Converting String in PIdata format

pt.Data.UpdateValue TextBoxTarget.Text, dt, dmReplaceDuplicates ‘function for Update (reed help)

End Sub

 

Note: I have used Sub for writing the tag value and Function for reading tag value for my own business logic. You can use either Function or Sub according to your own requirements.

Advertisements