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

Trying to retrieve a timestamp in UTC Options · View
mcasperson
#1 Posted : Tuesday, April 20, 2010 2:45:38 PM
Rank: Newbie
Groups: Member

Joined: 4/5/2010
Posts: 8
I'm currently creating a program that can write values into a PI server via the UpdateValue function, no problems there. The problem I am having is reading the value I have written for timestamps(for the purpose of checking that my writing is done correctly). Right now since the code is in alpha stage I'm just writing dummy data to the PI server, when it comes across a Timestamp point it writes the current time to the value attribute. I have already figured out how to pull the actual Timestamp for the Timestamp tag (what I mean is the timestamp attribute for a timestamp tag) out of the PI server, but that isn't what I want, I want the value I wrote into it and the problem I'm facing is that when I write it into PI it gets converted into scientific notation e.g. "1.2718E9" I believe I've figured out how to convert something like that into a float using C#, however my problem occurs when I try to pull that value out of the PI server, it gives me a System.__ComObject, normally I handle these via DigitalSates but that doesn't seem to apply in this case. Also it seems like an awful lot of precision would be lost when it converts it into scientific notation, is there a better way to write the current time into a PI server? Any help would be greatly appreciated.

Here is the code that writes the time into PI:

PIServer.PIPoints[cs1[NAME]].Data.UpdateValue(DateTime.Now, "*", PISDK.DataMergeConstants.dmReplaceDuplicates, null);

I had tried to write DateTime.Now.ToFileTimeUtc() into the PI point because that is easy to convert back into a date string when I pull it out of PI, but it throws an exception.

Thanks,
Michael
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.
Michael
#2 Posted : Tuesday, April 20, 2010 3:21:38 PM
Rank: Advanced Member
Groups: Member

Joined: 12/3/2009
Posts: 71
Location: Germany/Pennsylvania
Michael,

What pointtype you're using?

Michael
mcasperson
#3 Posted : Tuesday, April 20, 2010 3:34:00 PM
Rank: Newbie
Groups: Member

Joined: 4/5/2010
Posts: 8
I'm trying to write the current Time to a PI point with pointtype Timestamp and then I am trying to pull that Time value that I just wrote back out of that point and convert it into a date string like "mm/dd/yyyy hh:mm:ss" When I write the time to the Timestamp point it writes in the time and PI converts that number (since it is quite long) to scientific notation. I think it writes in a UTC format, although its possible it writes in "mm/dd/yyyy hh:mm:ss" format and PI converts it in the background to scientific notation. But when I try to retrieve that value from the PI server it gives me a System.__ComObject, and I can't seem to convert it into anything useful.

Note: I am not trying to get the timestamp attribute from a point, I am trying to get a value from a point with pointtype Timestamp.

Thanks,
Michael
Michael
#4 Posted : Tuesday, April 20, 2010 4:10:38 PM
Rank: Advanced Member
Groups: Member

Joined: 12/3/2009
Posts: 71
Location: Germany/Pennsylvania
The returned value is a PITime object (PITimeserver lib). Assign the Value to a PITime object and see whats in.

Michael
mcasperson
#5 Posted : Tuesday, April 20, 2010 4:34:50 PM
Rank: Newbie
Groups: Member

Joined: 4/5/2010
Posts: 8
Awesome I got it now, I just had to cast the value to a PITimeServer.PITime like you said and then I retrieved the LocalDate. e.g.

PITimeServer.PITime time = (PITimeServer.PITime)myValue.Value;
string dateTime = time.LocalDate.ToString();

Thank you very much other Michael ThumbsUp ,
Michael

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.