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

How to create new PI Point with given digital set with PI SDK Options · View
vkrejcirik
#1 Posted : Monday, January 23, 2012 1:45:55 PM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Hi, can someone help me to create new PI point with given digital set? I'm using PI SDK in C# and I would like to create new PI point with type digital and I would like to set some digital set. I'm able to create PI point, but only with digital set SYSTEM.

Here is my code:

Server s = gSDK.Servers[serverName];

// get point type from input
PointTypeConstants typeConstants = getPointType();

// get point class from input
string pointClass = getPointClass(s);

// create new PI point
NamedValues nv = new NamedValuesClass();
s.PIPoints.Add(tagName, pointClass, typeConstants, nv);

// Now, I would like to insert value

DateTime dateTime = DateTime.Now;
PIAsynchStatus pias = new PIAsynchStatus();

StateSet digitalSet = s.StateSets[stateSet];

s.PIPoints[tagName].Data.UpdateValue(digitalSet[stateName], dateTime, DataMergeConstants.dmReplaceDuplicates, pias);

I have only trouble with this case, setting new digital value...

Any suggestions?

Thanks!
Vlad



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.
zfima
#2 Posted : Monday, January 23, 2012 2:08:59 PM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
I wrote some code, and it works:
Code:

PIPoint pt = _piServer.PIPoints["BA:ACTIVE.1"];
PointAttribute at = pt.PointAttributes["digitalset"];
StateSet st = _piServer.StateSets[at.Value];
pt.Data.UpdateValue(st["Inactive"], DateTime.Now, DataMergeConstants.dmReplaceDuplicates);


Here, i have digital point BA:ACTIVE.1
This point can have one of states: Active and Inactive
The code change value

Tell, what happens
vkrejcirik
#3 Posted : Monday, January 23, 2012 2:26:05 PM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Yes, it works. I'm able to change value for given point. But is it possible to create new point and set digital set to it? Fox example, I would like to create new PI point with digital value from digital set "Modes".

Another case of this issue is:

I have PI point with type digital and it has digital set "Phases". Is it possible to change this digital set for this point to for example "Modes"?
Does it make sense?

Thanks!
zfima
#4 Posted : Monday, January 23, 2012 3:45:30 PM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
aaaa, ok
Now i understand the question, vkrejcirik

Code:

NamedValues vals = new NamedValues();
vals.Add("digitalset", "Phases");
_piServer.PIPoints.Add("MyNewDigitalPoint", "classic", PointTypeConstants.pttypDigital, vals);


Here you have:
name of point to be created: MyNewDigitalPoint
point class = classic
point type = pttypDigital
also, you have attribute that set digital set of point to Phases (one of my sets)

Tell me, what happens
vkrejcirik
#5 Posted : Tuesday, January 24, 2012 6:49:22 AM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Thank you for you reply. Yes it works. Now I am able to create new digital point with given digital set. I'm still not able to set value from this set. If I try to set value with command below, it doesn't work.

// get value from selected digital set
string stateName = getValueFromDigitalSet(s, stateSet);

object digitalSetName = s.StateSets[stateSet].Name;
StateSet digitalSet = s.StateSets[stateSet];

nv.Add("digitalset", ref digitalSetName);

// add new point
s.PIPoints.Add(tagName, pointClass, typeConstants, nv);

// set value
s.PIPoints[tagName].Data.UpdateValue(digitalSet[stateName], dateTime, DataMergeConstants.dmReplaceDuplicates, pias);



I see value "pt created". Any solution?


The second question is, if it is possible to change digital set by exisiting point. For example from "Phases" to "Modes".

Thank you!

Vlad
zfima
#6 Posted : Tuesday, January 24, 2012 7:48:16 AM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
My code :
Code:

PIPoint pt = _piServer.PIPoints["BA:ACTIVE.1"];
PointAttribute at = pt.PointAttributes["digitalset"];
StateSet st = _piServer.StateSets[at.Value];
pt.Data.UpdateValue(st["Inactive"], DateTime.Now, DataMergeConstants.dmReplaceDuplicates);

changes the value without problems... And my point value is not "pt created", the point get the value "Inactive" that i set

Second question:
Code:

PIPoint pt = _piServer.PIPoints["BA:ACTIVE.1"];
PointAttribute at = pt.PointAttributes["digitalset"];
pt.PointAttributes.ReadOnly = false;
pt.PointAttributes["digitalset"].Value = "Modes";
pt.PointAttributes.ReadOnly = true;


Vlad, i hope it will help you
Tell what is going on
vkrejcirik
#7 Posted : Tuesday, January 24, 2012 8:39:35 AM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Thank you !! It works great !

I have one more question. Could you explain me, what does it mean "point source"? Can I set this value when I create new PI point?

Thanks for help!
zfima
#8 Posted : Tuesday, January 24, 2012 12:59:32 PM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
vkrejcirik wrote:
Thank you !! It works great !

I have one more question. Could you explain me, what does it mean "point source"? Can I set this value when I create new PI point?

Thanks for help!


Hi Vlad

Point Source it is some "group" that point belongs to.

From "PI SMT user guide.chm":
"Point sources are unique single or multi-character strings used to identify the source of data for a PI point. Each PI Point contains a PointSource attribute to enable PI Interfaces or other scanning software to provide data to that point. For example, when a PI Random Interface starts up, it searches the PI Point Database for every PI point that is configured with a PointSource R. The interface then typically examines other PI Point attributes before it loads the points, to ensure the points are valid for its use..."

You are welcome! Always it is desire to me to help to someone
vkrejcirik
#9 Posted : Tuesday, January 24, 2012 1:16:30 PM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Thanks for you help ! Ok, now I understand what does it mean. So, is it possible to set this point source property when I create new PI point?

Thanks!
zfima
#10 Posted : Tuesday, January 24, 2012 2:42:30 PM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
vkrejcirik wrote:
Thanks for you help ! Ok, now I understand what does it mean. So, is it possible to set this point source property when I create new PI point?

Thanks!


Yes, of course

For example, you have point source B and you create classic point with type Int16 and name NewPoint_B_1

Code:

NamedValues vals = new NamedValues();
vals.Add("pointsource", "B");
_piServer.PIPoints.Add("NewPoint_B_1", "classic", PointTypeConstants.pttypInt16, vals);


Or you can create point and after this change attribute pointsource, as i show above

Good luck, Vlad.
vkrejcirik
#11 Posted : Tuesday, January 24, 2012 6:50:26 PM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Sounds great! Thanks! It works for me. I see there is property for PI Server : piserver.pointSources. I hope it is possible to print out all point sources on the PI server.

Something like this:

foreach (string pointsource in server.pointsources)
{
....
}

Right?

I got similar code for point types yet...

Thanks for all your help!
zfima
#12 Posted : Wednesday, January 25, 2012 8:15:41 AM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
vkrejcirik wrote:


Something like this:

foreach (string pointsource in server.pointsources)
{
....
}

Right?



Hi Vlad!

First, you can not work with PointSources properties, because of it not implemented.

Second,you can do:
Code:

SortedSet<string> pointSources = new SortedSet<string>();
PointList pointList = _piServer.GetPoints("tag='*'");

foreach (PIPoint point in pointList)
{
   string pointSource = point.PointAttributes["pointsource"].Value;
   if (!pointSources.Contains(pointSource))
   {
      pointSources.Add(pointSource);
   }
}

but it works very slow. Extremely slow, Vlad. You can use parallelism instead of foreach, but maybe it will not work faster.

If some one will find other way, i will glad to get it.
vkrejcirik
#13 Posted : Wednesday, January 25, 2012 8:22:54 AM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Sounds great ! Thanks a lot !
zfima
#14 Posted : Wednesday, January 25, 2012 11:21:09 AM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
vkrejcirik wrote:
Sounds great ! Thanks a lot !

U r welcome, Vlad, but remember - it is a huge time-penalty operation!
vkrejcirik
#15 Posted : Wednesday, January 25, 2012 12:23:38 PM
Rank: Member
Groups: Member

Joined: 1/23/2012
Posts: 10
Ok. I will keep it in mind ! thanks !
zfima
#16 Posted : Wednesday, January 25, 2012 1:01:09 PM
Rank: Advanced Member

Groups: Member

Joined: 11/13/2011
Posts: 77
Location: Middle East
vkrejcirik wrote:
Ok. I will keep it in mind ! thanks !


I posted some useful information about. here
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.