|
|
Rank: Newbie Groups: Member
Joined: 8/26/2011 Posts: 8 Location: California
|
Hello, Is there a command in pi processbook that will return a tag's value at a given time?
I tried to do this by calling a PI datalink macro through the PI processbook vba environment, but it's not ideal and I'm now encountering problems with it. I have tried: myGhost = Excel.Application.Run("PIArcVal", TagName1, myTimes(i), 0, myServer, "auto") myValues(i) = myGhost(1) (this was within a for) I get an error: runtime error 1004 - Cannot run the macro "PiArcVal". The macro may not be available on this workbook or all macros may be disabled.
Basically, I'm trying to allow the end user to move the trend start and end times around, then calculate the slope of one of the traces on the trend, and then automatically make some calculations off of that. I can do the above with just the points in the trace, however, I noticed that the number of points varies significantly based on the time window chosen (even 3 mins longer changes the number of points in a trace significantly). This changes the slope of the trace, and therefore the final calculation.
Any help would be greatly appreciated..
|
|
|
|
|
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.
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
Hi tilak
Where will the end result be displayed, PB or Excel?
Excel would be much easier but does have it's limitations (65536 rows) when you do big time periods, you can also apply filter expressions. The next question you will have top ask youself is is, do you want sampled (even spaced) data or compressed (actual archived) data. What type of slopes, linear or polynomial.
|
|
|
Rank: Newbie Groups: Member
Joined: 8/26/2011 Posts: 8 Location: California
|
Hi, The end result needs to be displayed in PB. The only reason I brought excel.application.run into the program is because it's the only way I could find the value of a tag at a given time point. The less I use Excel the better. Evenly spaced data would be best, in fact I was using excel.application.run("piarcval",...) to fill in an array that had an interpolated value every 3 seconds. Linear slopes.
Thanks
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
There are a couple of ways you can get the value of a point.
OPTION1: You can have the tags in processbook (object) and use the object.getvalue(vrdate,vrstatus) PROS: You can use the "for each symbol in thisdisplay" to cycle through the tags and write data to an arrays based on an date selection CONS: Can't think of any, to early in the morning and I haven't had my coffee yet
OPTION2: You can use the sdk in VBA to declare your server, pipoints and use a for loop to write the data into an array at evenly spaced intervals. PROS: This could be a bit faster if you have a lot of tags CONS: You will have to change the code every single time you want to add another tag
LONG TERM: If this will be used by alot of user why don't you write and add-in for processbook, it might be a pain to roll-out eventually but nothing a couple of startup scripts can't solve.
|
|
|
Rank: Newbie Groups: Member
Joined: 8/26/2011 Posts: 8 Location: California
|
Thanks for your help. I've tried option 1 and it doesn't seem to work for me... I give it the time I want the value at (within the trend window) and I put 0 in for vrStatus, but it only returns one value, the same value for every time point. I think it's the value that corresponds with the time at the end of trend window.
I will try option 2 if I cant get option 1 working soon.
About the add in... I will have to look into it, but I first need to figure out a short term solution.
Thanks again, your help is greatly appreciated!
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
Try the following in ProcessBook VBA.
1.Make sure you have the correct references, Tool-References, PI-SDK Dialogs;PISDK 1.3 Tyoe Library;PISDKCommon;PITimeServer 1.1
2.Paste the following code and work your way from here, keep us updated on your progress and inform us if you run into any snags
Dim srv As PISDK.Server Dim ptval As PISDK.PIPoint Dim dt As New PITimeServer.PITime
Private Sub test()
'***********SET START TIME*********** dt = Now() '***********SET SERVER TO DEFAULT*********** Set srv = PISDK.Servers.DefaultServer '***********TAGNAMES*********** Dim pt1 As PIPoint Set pt1 = srv.PIPoints("sinusoid") '***********DATA EXTRACTION*********** Dim pv1 As PIValue Set pv1 = pt1.Data.Snapshot Dim pvs As PIValues Set pvs = pt1.Data.RecordedValuesByCount(Format(dt, "dd-mmm-yy hh:mm"), 50, dReverse, btInside) '***********LOOP THROUGH EACH COMPRESSED DATA*********** For Each pv1 In pvs Debug.Print pv1.TimeStamp.LocalDate & vbTab & pt1.Data.ArcValue(pv1.TimeStamp.LocalDate, rtAuto) Next
End Sub
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
You can also use the following
Set pvs = pt1.Data.InterpolatedValues("19-Dec-2011", "20-Dec-2011", 10)
10 is how much data you would like to extract between ST and ET or as PI-SDK documentation would say: Number of values to return - granularity of interpolation.
|
|
|
Rank: Newbie Groups: Member
Joined: 8/26/2011 Posts: 8 Location: California
|
I ended up using something along these lines:
Dim srv As PISDK.Server Dim ptval As PISDK.PIPoint Dim dt As New PITimeServer.PITime Set srv = PISDK.Servers.DefaultServer Dim pt1 As PIPoint Set pt1 = srv.PIPoints(myTagName) Dim pv1 As PIValue Set pv1 = pt1.Data.Snapshot MyTime = mystartTime For i = 1 to myUBound MyArray(i) = pt1.Data.ArcValue(MyTime, rtAuto) MyTime = myTime + 3 / 24 / 60 / 60 Next i
(I'm going from memory here since the code is at work, but I wanted to make sure I responded before getting distracted by the holidays)
Thank you Squatty so much, this had been frustrating me for a while!!!
|
|
|
|
Guest
|