Does anyone have a code sample they can share for for retrieving an array of data using SDK and C#.net (e.g. [timestamp, tag value])? I need to do some custom calculations on the data.
Any help is greatly appreciated!
I've added a compressed file containing a WinForms application using PI SDK to collect a snapshot value. That gives you a starting point, and then you can modify it to get data from the archive - and also to get more than one value at the time. There is a PI SDK Programming reference help file - search for it here on vCampus (if you don't find it, I can upload it).
Asle Frantzen @ AmitecThere is a PI SDK Programming reference help file
The file is called pisdk.chm and should be located in C:\Program Files\PIPC\HELP\
You said that you needed an array, what kind of array? archived values for the past hour for example?
That should be relatively easy once you see the example that Asle provided and the help file, if you still have questions please let us know. :)
unofrtunately, I have still not figured it out. Does anyone have an explicit code sample ot share? I am, yes trying to colelct data over a specified previous period of time like an hour. I did this in VBA a long time ago but unfortunately am having more dificulty with C# version!
thanks for all the responses!
If you just want to get the archive value for a time range, for example for the last 2 hours You can do something like:
PISDK.PISDK mysdk = new PISDK.PISDK(); PISDK.Server myserv = mysdk.Servers.DefaultServer; //or PISDK.Server myserv = mysdk.Servers["<PI server>"]; myserv.open(""); // connect to server, you might want to add in codes to catch exception for cases where connection fails PISDK.PIPoint mypoint = myserv.PIPoints["<tagname>"]; PISDK.PIValues = mypoint.Data.RecordedValues("*-2h", "*", BoundaryTypeConstants.btInside); ....
You probably want to handle cases where the return value is a digital state instead of a value, as mentioned in this post here.
As mentioned by Asle and Cristobal, you can always look up PISDK.chm for references on the SDK functions. There is a few variants of RecordedValues() function, as well as some optional parameters that I have not included here. You can look at the list of functions under PIData or IPIData to see RecordedValues and other data retrieval functions.
Thanks! I understand how to getto teh last line fo your code. Question is how do I extract timestamps and associated real values to use in calculations? I woudl like to put them in other arrays of teh appropriate type (long, single, etc.)
thanks for your help
First I would like to correct a quick little something in Han Yong's code: he misses a variable name for the PISDK.PIValues object he declared on the last line (it should be something like "PISDK.PIValues myvalues = mypoint.Data.RecordedValues(...".
Then you simply need to navigate or loop through the PIValues collection you obtained from the RecordedValues call - it's an IEnumerable collection of PISDK.PIValue object, which means you can make use of a "foreach" loop. Then every PIValue object has a few main attributes:
As far as getting a "ready-to-use" code sample, I suggest you look into the PI Programming 101 webinar - its recording and sample code is available under the vCampus Auditorium.
Let us know if you need anything else!
My bad... Nice catch there Steve
I'm trying to retrieve historical values from PI point in C++. My code looks like:
spPIPoint = spServer->PIPoints->GetItem((_bstr_t) tag.c_str());
spPIValue = spPIPoint->Data->Snapshot;
MyPIValue* mPv = new MyPIValue(spPIValue);
result = new MyPITag(mPv, tag, this);
// from date
_bstr_t startDt = (_bstr_t) from.c_str();
V_VT (&startDate) = VT_DISPATCH;
V_DISPATCH(&startDate) = startPITime;
// to date
_bstr_t endDt = (_bstr_t) to.c_str();
V_VT (&endDate) = VT_DISPATCH;
V_DISPATCH(&endDate) = endPITime;
spValues = spPIPoint->Data->RecordedValues(startDate, endDate, btInside, "*", fvShowFilteredState, NULL);
But something is wrong. I'm getting this error:
Error in: Failed to retrieve events from server. [-10010] PI System Timed Out : -2147220186.
I received the same error also from PI System Management Tools.
How much data are you retriving? You might increase the timeout our reduce the amount of data.
Isn't -10010 more of a "server licensing" timeout, rather than a command timeout? In the licensing section of PI-SMT, under the General node, what does the "ExpTime" value show?
Thanks for replies.
Dennis - you have right. ExpTime has value from the past. In the Licensing section I see: vCampus Temporary License. Did I miss something when I created vCampus account? I did it long time ago. :-) Maybe I forgot to activate my developer license for PI Server..
There is license for PI Server in In My support -> My License Activation. When I click on the details link, I see: License Timeout Date: 30-Oct-2012 12:00:00.
Ok. It looks like I forgot to activate my PI Server license. Now I did it and ExpTime is set correctly according to my vCampus account. Thank you for your hint and I'm sorry, it was my bad.
Dennis KilgoreIsn't -10010 more of a "server licensing" timeout, rather than a command timeout? In the licensing section of PI-SMT, under the General node, what does the "ExpTime" value show?
uhm. I should read the error message before posting.
Usually you do it like this:
Retrieving data ...