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

Create a macro to get a tag Options · View
gnrteixeira
#1 Posted : Tuesday, October 28, 2008 4:14:20 PM
Rank: Newbie
Groups: Member

Joined: 10/28/2008
Posts: 3
Location: Rio de Janeiro
Hi,

I am a new user of PI and I am having some problems.
I would like to create a macro (VBA) to get a tag and to visualize the value of this tag in an Excel spreadsheet. Can anyone help me with that?

Thanks
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.
RJK Solutions
#2 Posted : Wednesday, October 29, 2008 12:05:58 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
Hi gnrteixeira,

Do you have PI-DataLink? If so, this is simple to do using the "Current Value" menu option (PI -> Current Value) and enter a PI Tag from your PI Server.

If you purely want to do this from VBA then you can do this with PI-SDK.
To do so, have a quick look at this post showing how to connect to a PI server: http://www.rjksolutionsl...t.aspx?g=posts&t=18

Then to use this you could do:


Code:
If ConnectToPI() Then

'Get your PI Point object
Dim MyTag as PISDK.PIPoint
Set MyTag = PIServer.PIPoints("TAGNAME")

' Assign the current value to a Cell in MS Excel
Worksheets("WorksheetName").Range("A1").Value = MyTag.Data.Snapshot.Value

Set MyTag = Nothing

Else

End If


Hope this helps..?
Post some specifics of what you need to do if you want a more comprehensive example.

Principal Consultant
Real-Time Data Management @ Wipro Technologies
gnrteixeira
#3 Posted : Wednesday, October 29, 2008 4:33:36 PM
Rank: Newbie
Groups: Member

Joined: 10/28/2008
Posts: 3
Location: Rio de Janeiro
It worked. Thanks a lot.

What I would like to do is to get a tag in a specific date and time.
Is it possible instead of writing the TAGNAME (Set MyTag = PIServer.PIPoints("TAGNAME")), use a cell from the excel worksheet (Set MyTag = PIServer.PIPoints("A1")?
RJK Solutions
#4 Posted : Wednesday, October 29, 2008 10:06:55 PM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 612
Location: Cheshire, United Kingdom.
No problem.
So long as your cell reference value returns a string that equates to a valid PI tag then you can use it.

So:

Code:
Set MyTag = PIServer.PIPoints(Worksheets("SheetName").Range("A1").Value)


is perfectly valid.

Principal Consultant
Real-Time Data Management @ Wipro Technologies
gnrteixeira
#5 Posted : Wednesday, October 29, 2008 11:55:14 PM
Rank: Newbie
Groups: Member

Joined: 10/28/2008
Posts: 3
Location: Rio de Janeiro
OK. I'll try this tomorrow at work.

My last question is to get a tag in a specific date and time (ex.: 15/10/2008 10:00).

Thanks again.
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.