|
|
Rank: Member Groups: Member
Joined: 4/28/2011 Posts: 10 Location: Brasil
|
Hello, First of all congratulations for the outstanding job. I joined the forum a few days ago and was looking for ideas for a panel I need to do. Despite of finding some very useful code, I still could not reach what I want. Basically I have stored in a tag values where each value refers to a day and a task. In one day I have several tasks. What I need is given a date to know if the value corresponding to a particular task is stored in the TAG. I've done a test code using Excel but without connection to the database and I translated the date for long format and merged with the task code. It worked well. What I need now is to jump from Excel to VB associated to PI System. I understand that I should get a window of values from the TAG based on the date that I'm checking and store them in an array and then test the values there to know if the value I'm looking for exists. But as I have no practice with the PI System’s code, I'm lost. Can you help me? Sincerely, Flavio.
|
|
|
|
|
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: Member Groups: Member
Joined: 5/5/2011 Posts: 22 Location: Moscow
|
I can help you, probably. In what difficulty consists?
|
|
|
Rank: Member Groups: Member
Joined: 4/28/2011 Posts: 10 Location: Brasil
|
Shem wrote:I can help you, probably. In what difficulty consists? Hi Shem, Thanks for your answer. My dificult is I do not know how to write the code to make the VB read the TAG and save the values in the array once I'm not used to PI-Datalink commands. Best regards.
|
|
|
Rank: Member Groups: Member
Joined: 5/5/2011 Posts: 22 Location: Moscow
|
Hi, Markowic! Open new Excel. Press Alt+F11 (open VBA) At first it is necessary to connect PI-SDK. Go to Tools/references choose "PI-SDK 1.3. Type Libary" and "PITimeServer 1.1 Type Libary". Press Ok. Save you work book. Go to Data Link to connection and connect your PI-server. It can be done by means of VBA, but for simplicity we will make so. Open VBA Choose Sheet1 and create new function, for example Code:Private Sub My_Function() Dim srv As Server Dim dt As New PITimeFormat Dim x As Double
dt.InputString = "12.05.2011 00:00:00" Set srv = Servers("Gabov") x = srv.PIPoints("SINUSOID").Data.ArcValue(dt, rtAfter) End Sub
dt.InputString = "12.05.2011 00:00:00" - dt is time in PI format Set srv = Servers("Gabov") - "Gabov" is name PI-server x = srv.PIPoints("SINUSOID").Data.ArcValue(dt, rtAfter) - value "SINUSOID" on dt (12.05.2011 00:00:00) More info about PI-SDK functions in help for SDK (C:\Program Files\PIPC\HELP\pisdk.chm) Or other example Code:Private Sub My_Function() Dim srv As Server Dim dt As New PITimeFormat Dim x As Double
dt.InputString = "12.05.2011 00:00:00" Set srv = Servers("Gabov") x = srv.PIPoints("SINUSOID").Data.Snapshot End Sub You will receive an Snapshot So it is possible to obtain the data and save the values in the array. If there are other questions ask. Than to a smog I will help.
|
|
|
Rank: Member Groups: Member
Joined: 4/28/2011 Posts: 10 Location: Brasil
|
Shem, I appreciated the directions to connect to the PI server and I'll use them. But as I have read the code you are taking only one value with a specific timestamp. What I need is, given a day (i.e. today 12/05/2011) I wanted to feed an array with all values in a time window, lets say 1 week. Maybe (*-1 week,*) I guess. This is because I need to test all values within this timewindow to check if there is a specific value there. I mean doesn't care when it was put in the TAG and I will not know when it was put there. Thanks,
|
|
|
Rank: Member Groups: Member
Joined: 5/5/2011 Posts: 22 Location: Moscow
|
Hi! You can use this code Code:Private Sub My_Function() Dim srv As Server Dim TagName As String Dim FilterString As String Dim st As New PITimeFormat Dim et As New PITimeFormat Dim PIArray As PIValues Dim PIvalue As PIvalue
Set srv = Servers("Gabov") TagName = "SINUSOID"
st.InputString = "12.05.2011 11:00:00" ' Start tine et.InputString = "12.05.2011 16:00:00" ' End time
FilterString = "TagVal('" & TagName & "') > 50" Set PIArray = srv.PIPoints(TagName).Data.RecordedValues(st, et, , FilterString, fvRemoveFiltered)
If PIArray.Count <> 0 Then 'if you have values ' '..... ' 'for example TimeOfValue = "" For Each PIvalue In PIArray TimeOfValue = TimeOfValue & Chr(10) & Chr(13) & PIvalue.TimeStamp.LocalDate Next MsgBox "You have " & PIArray.Count & " values in:" & TimeOfValue Else MsgBox "You have't values." End If
End Sub Instead of an "st" and "et" it is possible to use an PIdata ("*"). Then Set PIArray = srv.PIPoints(TagName).Data.RecordedValues("*-7d", "*", , FilterString, fvRemoveFiltered) FilterString -A string containing a filter expression (see help "PI Performance Equation"). You can use "TagVal('SINUSOID') > 50" or "TagVal('SINUSOID') = ""Shutdown""" More in detail about this function RecordedValues it is written in the help. I hope you now at you it will turn out to solve your problem ;)
|
|
|
Rank: Member Groups: Member
Joined: 4/28/2011 Posts: 10 Location: Brasil
|
Hello Shem,
This code seems to be what I am looking for. I'll make some tests here and will give you a follow up later. Thanks a lot for your help.
|
|
|
Rank: Member Groups: Member
Joined: 11/30/2010 Posts: 15 Location: New York, USA
|
shem a lot of good information here .. thanks ! i myself am trying to learn how to use VBA and pi - sdk to access data etc. from the pi server, gave a quick browse and will look more later. i find the best way for me to learn is to look through everyone s code samples to try to learn VBA as well as the best ways of accessing data from pi
|
|
|
Rank: Member Groups: Member
Joined: 4/28/2011 Posts: 10 Location: Brasil
|
Shem wrote:Hi! You can use this code
Instead of an "st" and "et" it is possible to use an PIdata ("*"). Then Set PIArray = srv.PIPoints(TagName).Data.RecordedValues("*-7d", "*", , FilterString, fvRemoveFiltered)
FilterString -A string containing a filter expression (see help "PI Performance Equation"). You can use "TagVal('SINUSOID') > 50" or "TagVal('SINUSOID') = ""Shutdown"""
More in detail about this function RecordedValues it is written in the help.
I hope you now at you it will turn out to solve your problem ;) Hello Shem, I've worked over the code you've sent me and it is doing what I wanted. Now I just need to do some improvements. Code:Set srv = Servers("PISERV1") TagName = "CHECKLIST PROG"
DataProg = UserForm1.TextBox2.Value ValorData = CDbl(DateValue(DataProg)) AuxDataprog = ValorData - 7 DataProg2 = CDate(AuxDataprog)
st.InputString = DataProg2 & " 00:00:00" ' Start tine et.InputString = DataProg & " 00:00:00" ' End time
FilterString = "TagVal('" & TagName & "') > 50" Set PIArray = srv.PIPoints(TagName).Data.RecordedValues(st, et, , FilterString, fvRemoveFiltered) This way you can handle with any timewindow you want.  Thanks again, Flavio.
|
|
|
Rank: Member Groups: Member
Joined: 5/5/2011 Posts: 22 Location: Moscow
|
Hi, All! Markowic, good idea! I am glad that my help was useful to you.
Ejyoungone, you can create new topics on the forum that interests you and I am sure that the forum will be people who can help you. The main thing that you are properly formulated question. If I can, I'll help you ;)
|
|
|
|
Guest
|