YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

Writing values into PI Tag using VBA Options · View
Markowic
#1 Posted : Friday, May 20, 2011 2:54:57 PM
Rank: Member
Groups: Member

Joined: 4/28/2011
Posts: 10
Location: Brasil
Hello.

After the issue to read a value in the PI Tag, now I'm experiencing troubles to write the vlaues there. As I do not know the structure of SDK whe I put the code to run it gives back a message "Obrigatory Object" "Incompatible Types".
The main problem is set the variables and objects acordingly with SDK language, once I do not know how to declare the variables to make PI understand what I want. Debugging the code it seems to be able to access the server.
Here is a code's fragment:

Code:
...
Dim HoraPI As Date
Dim Horapis As String
Dim Horapis2 As String
Dim ValorTAGPI As Double
Dim PIServer As PISDK.Server
Dim DataHoraPI As New PITimeFormat
Dim et As New PITimeFormat
Dim PIArray As PIValues
Dim PIvalue As PIvalue
'Acess the server
Set PIServer = Servers("SA-POPE-PISERV1")
Call PIServer.Open("UID=***;PWD=****")
TagName = ("CHECKLIST PROG")


Excel.Application.DisplayAlerts = False
Calculate
    ActiveWorkbook.Save
    Sheets("GERAÇÃO").Select
    diadoug = Range("AA3")
    'Create a timestap
        HoraPI = Range("AH1")
        Horapis = Left(HoraPI, 14)
        diatag = CDbl(DateValue(HoraPI))
       
   
    Range("AA3").Select
    Valor$ = ActiveCell.Value

        'Save a value in TAG
        'Set PITag = "checklist prog"
        Horapis2 = Horapis & "0:11"
        'DataHoraPI = Horapis & "0:11"
        ValorTAGPI = diatag & "101"
        Call PITag.Data.UpdateValue(Horapis2, ValorTAGPI)
...

Another thing is I guess I will need to set the references with the VBA too. How to do that?

Thanks for any help.
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
Shem
#2 Posted : Wednesday, May 25, 2011 11:07:31 AM
Rank: Member
Groups: Member

Joined: 5/5/2011
Posts: 22
Location: Moscow
Hi, Markowic!

Begin with the simple. Learn to change one value. It can be done so
Code:

Private Sub My_Function2()
Dim srv As Server
Dim dt As New PITimeFormat
Dim pt As PIPoint

Set srv = Servers("Your_PI_server")
TagName = "SINUSOID"
Set pt = srv.PIPoints(TagName) ' it's your PI point

dt.InputString = "25.05.2011 14:05:00" 'it's data. InputString - Converting String in PIdata format

pt.Data.UpdateValue 123, dt, dmReplaceDuplicates 'function for Update (reed help)

End Sub
Markowic
#3 Posted : Wednesday, May 25, 2011 2:11:31 PM
Rank: Member
Groups: Member

Joined: 4/28/2011
Posts: 10
Location: Brasil
Hello, Shem.

Advice listened and written.
The code you sent me has worked and now I will adapt it to my function.
Again thanks for your help.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.