|
|
Rank: Member Groups: Member
Joined: 6/9/2011 Posts: 12 Location: Brisbane
|
Hi all,
I was trying to manually enter data into a couple of Pi tags, data was from the 4-jul-2011 to 24-oct-2011 with a 1 minute interval. I am using the following code which I got from here.
Private PIServer As PISDK.Server
Private Const PIServerName As String = "stupisp01"
Public Sub UpdatePIPoints() Set PIServer = PISDK.Servers(PIServerName)
' Cycle through Cells starting at row 2 Dim i As Long For i = 2 To 1000000 ' If blank cell encountered then do not continue If Range("A" & i).Value = "" Then Exit For ' Check PI tag exists On Error Resume Next Err.Clear If PIServer.PIPoints(Range("A" & i).Value).Name = Range("A" & i).Value Then If Err.Number = 0 Then ' Get the PIPoint Dim PITag As PISDK.PIPoint Set PITag = PIServer.PIPoints(Range("A" & i).Value) Err.Clear Call PITag.Data.UpdateValue(Range("B" & i).Value, Range("C" & i).Value) If Err.Number = 0 Then Range("D" & i).Value = "Value written to PI." MsgBox "A successful update was made to " & PITag Else Range("D" & i).Value = Err.Description MsgBox "The update to " & PITag & "was unsucessful due to " & Err.Description End If Set PITag = Nothing Else Range("D" & i).Value = Err.Description MsgBox "The update was unsucessful because the " & Err.Description End If Else Range("D" & i).Value = "Tag does not exist." MsgBox "The update to " & PITag & "was unsucessful due to the tag not existing" End If On Error GoTo 0 Next i
End Sub
I got no errors when I ran the program but the issue is that when I retrieve the data, only data from 10-sep-2011 appears. The tag wasn't created on that date it was created on the 24th-oct. I manually changed the point created value so I could write before the creation date. I am at a loss as to why the data doesn't appear. I am not sure if it is not being written into PI or it can't retrieve it for some reason.
On a similar note there was a tag which I was updating manually earlier this month. It is a collection of tags which I update every month with daily averages from a weather station. It was working fine before I updated the values this month but after I updated them only the last 6 days of data was available and everything before that couldn't be retrieved.
Also how can the above be tweaked to be able to delete data point in PI. All help is appreciated.
Regards, Jitesh
|
|
|
|
|
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: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 617 Location: Cheshire, United Kingdom.
|
Your problem is likely your archive files. When you create a PI tag, the PI tag record number is added to the current archive file only. It is likely your archive file starts on 10-Sep-11 to the current time. If you want data before that archive file then you need to reprocess each archive file that covers the time period you need. Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Member Groups: Member
Joined: 6/9/2011 Posts: 12 Location: Brisbane
|
Thanks for that RJK. Found a compromise solution. Could anyone help with adapting the code for deleting PI data points in the archive?
|
|
|
Rank: Member Groups: Member
Joined: 6/9/2011 Posts: 12 Location: Brisbane
|
Bump, any help on deleting dta points in the archive
|
|
|
Rank: Member Groups: Member
Joined: 7/5/2010 Posts: 27 Location: Texas
|
Probably not what you are looking for, but if there aren't a whole lot of point values to delete they can be deleted manually via PI-SMT.
I do have some old PI-API code in a VB6 application that deleted PI point values, but Win 7 pretty well broke the app. If you want a snip of some of the PI-API code, let me know.
We only used the VB6 app to manually delete point values one at a time, so PI-SMT is an adequate replacement and I've not felt any overwhelming urge to re-code it in PI-SDK.
jhcoxx
|
|
|
Rank: Member Groups: Member
Joined: 6/9/2011 Posts: 12 Location: Brisbane
|
PI-SMT is not an option unfortunately. Pedantic IT people have severely restricted access to SMT features. I am trying to get some code from piconfig working: I have been trying to use this sample code: @table piarc @mode edit @istru tag, time, mode TAGNAME,23-Apr-04 09:22:10, remove @ends @bye
but it doesn't ever recognise the tagname. I have tried a few diffrent tags so far with no luck. I keep getting this error: Error reading record from table -15003 Generic requested item not found
Any help is appreciated
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
I would suggest you create a csv file with all the values you want to delete. Make sure that ColA=tag,ColB=time,ColC=value,ColD=mode
Also check if your data was not entered with subseconds
dd-MMM-yy hh:mm:ss.00
Excel should look like this, please forgive my feeble attempt to duplicate Excel row & cols. Save the CSV file somewhere in the PI SERVER
MyTagname1,MyTime1,MyValue1,remove MyTagname1,MyTime2,MyValue2,remove MyTagname1,MyTime3,MyValue3,remove MyTagname2,MyTime1,MyValue1,remove MyTagname2,MyTime2,MyValue2,remove MyTagname2,MyTime3,MyValue3,remove
@table piarch @mode edit,t @istructure tag,time,value,mode @input C:\MyFile.csv
If this doesn't work walk up to your IT department and smack the first person you see. IT should never be in charge of what is happening in the engineering floor, as you can see I'm pro-Engineering
|
|
|
Rank: Member Groups: Member
Joined: 6/9/2011 Posts: 12 Location: Brisbane
|
I tried that, i received the same error message as before, it cant find the tag in the archive table. The data was not in subseconds, I am testing it on manually entered data first so there definetely isn't any subseconds involved. Wonder if there is some sort of restriction on the archive for me that is causing this problem, but I do have read/write access to tags.
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
OK, this doesn't make sense, you can't find the tag in the archive table, can you find the tag if you do a normal tagsearch in Datalink. Also check if there isn't any spaces before and after the tagname. I presume you are logged into the piserver when you perform the piconfig commands.
|
|
|
Rank: Administration
 Groups: Administration
Joined: 6/20/2008 Posts: 617 Location: Cheshire, United Kingdom.
|
Do you know there is a RemoveValues method in the PIData object of PI SDK? Principal Consultant Real-Time Data Management @ Wipro Technologies
|
|
|
Rank: Member Groups: Member
Joined: 6/9/2011 Posts: 12 Location: Brisbane
|
RJK Solutions wrote:Do you know there is a RemoveValues method in the PIData object of PI SDK? No I didn't but thanks for that I have it working now.
|
|
|
Rank: Advanced Member
 Groups: Member
Joined: 4/7/2011 Posts: 137 Location: KZN, South Africa
|
Can you share with us what the problem/solution was. We are all here to learn and share
|
|
|
Rank: Member Groups: Member
Joined: 11/30/2010 Posts: 15 Location: New York, USA
|
i agree i like to read these forums for code snippets especially since i am just starting out learning pi/osisoft/vba
|
|
|
Rank: Member Groups: Member
Joined: 6/9/2011 Posts: 12 Location: Brisbane
|
Here it is, it is a modified version of the manual entry code above:
Private PIServer As PISDK.Server
Private Const PIServerName As String = "xyz"
Public Sub UpdatePIPoints() Set PIServer = PISDK.Servers(PIServerName)
' Cycle through Cells starting at row 2 Dim i As Long Dim pv As PIValue Dim response As String For i = 2 To 1000000 ' If blank cell encountered then do not continue If Range("A" & i).Value = "" Then Exit For ' Check PI tag exists On Error Resume Next Err.Clear If PIServer.PIPoints(Range("A" & i).Value).Name = Range("A" & i).Value Then If Err.Number = 0 Then ' Get the PIPoint Dim PITag As PISDK.PIPoint Set PITag = PIServer.PIPoints(Range("A" & i).Value) Err.Clear Set pv = PITag.Data.ArcValue(Range("B" & i).Value, rtCompressed) If pv = "" Then Range("D" & i).Value = "No Value exists at timestamp" MsgBox "No Value exists at timestamp" Exit For End If response = MsgBox("Do you want to remove the value " & pv & " from " & PITag, [vbYesNo], "Warning") Set pv = Nothing If response = vbYes Then Call PITag.Data.RemoveValues(Range("B" & i).Value, Range("B" & i).Value, drRemoveFirstOnly) If Err.Number = 0 Then Range("D" & i).Value = "Value Removed from PI." MsgBox "A successful archive removal was made to " & PITag Else Range("D" & i).Value = Err.Description MsgBox "The archive value removal for " & PITag & "was unsucessful due to " & Err.Description End If Else Exit For End If Set PITag = Nothing Else Range("D" & i).Value = Err.Description MsgBox "The archive value removal was unsucessful because the " & Err.Description End If Else Range("D" & i).Value = "Tag does not exist." MsgBox "The update to " & PITag & "was unsucessful due to the tag not existing" End If On Error GoTo 0 Next i
End Sub
|
|
|
|
Guest
|