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

AddTags in c# Options · View
zedlik
#1 Posted : Thursday, September 10, 2009 3:14:08 PM
Rank: Newbie
Groups: Member

Joined: 8/11/2009
Posts: 5
Location: canada
Hello,

I need to use the AddTags method of the IPIPoints2 interface. Does any one have an example in c#?

Thank you.
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.
mcasperson
#2 Posted : Wednesday, April 21, 2010 4:42:49 PM
Rank: Newbie
Groups: Member

Joined: 4/5/2010
Posts: 8
I've been working on this myself, I think I've made some progress, but there is still something wrong with the code I have.

Code:
PISDK.Server myServer;     // server object from the name in server pick list
PISDK.IPIPoints2 IPIP2;
PISDKCommon.NamedValues nvsAddRemove = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEdit = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsTagAttr = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEditAttr1 = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEditAttr2 = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEditAttr3 = new PISDKCommon.NamedValues();
PISDKCommon.PIErrors myAddErrors = new PISDKCommon.PIErrors();
PISDK.PointList myPtList = new PISDK.PointList();
PISDKCommon.PIErrors myEditErrors = new PISDKCommon.PIErrors();
PISDKCommon.PIErrors myRemoveErrors = new PISDKCommon.PIErrors();

myServer = g_SDK2.Servers[servPickList2.SelectedServerName.ToString()];
IPIP2 = (PISDK.IPIPoints2)myServer.PIPoints;
object className = "classic";
object pointType = "pttypFloat32";
nvsTagAttr.Add("ptclassName", ref className);
nvsTagAttr.Add("pointtype", ref pointType);
object nvsTagAttr2 = nvsTagAttr;
nvsAddRemove.Add("TagName1", ref nvsTagAttr2);
nvsAddRemove.Add("TagName2", ref nvsTagAttr2);
nvsAddRemove.Add("TagName3", ref nvsTagAttr2);
IPIP2.AddTags(nvsAddRemove, out myAddErrors, out myPtList, null);


The problem I'm running into is there seems to be something wrong with my nvsAddRemove NamedValues Collection. Everytime I try to perform any operation on it I get an error of "Type mismatch" which really doesn't tell me anything. I think its a problem with the second argument in my NamedValues.Add method, in the VB example in the PISDK they had this:

Code:
Dim myServer As Server
Dim IPIP2 As IPIPoints2 ' IPIPoints2 interface
Dim nvsAddRemove As New NamedValues ' NamedValues collection for adding and removing tags
Dim nvsEdit As New NamedValues ' NamedValues collection for editing tags
Dim nvsTagAttr As New NamedValues ' Add attributes for all tags
Dim nvsEditAttr1 As New NamedValues ' Edit attributes for tag 1
Dim nvsEditAttr2 As New NamedValues ' Edit attributes for tag 2
Dim nvsEditAttr3 As New NamedValues ' Edit attributes for tag 3
Dim myAddErrors As PIErrors ' errors collection for adding
Dim myPtList As PointList ' Point list returned from adding tags
Dim myEditErrors As PIErrors ' errors collection for editing
Dim myRemoveErrors As PIErrors ' errors collection for removing
'
' Get the server and the IPIPoints2 interface
'
Set myServer = PISDK.Servers.DefaultServer
Set IPIP2 = myServer.PIPoints
'
' Populate the tag attributes collection
'
nvsTagAttr.Add "ptclassName", "classic"
nvsTagAttr.Add "pointtype", pttypFloat32
'
' Add three tags with these attributes
'
nvsAddRemove.Add "AER1", nvsTagAttr
nvsAddRemove.Add "AER2", nvsTagAttr
nvsAddRemove.Add "AER3", nvsTagAttr
IPIP2.AddTags nvsAddRemove, myAddErrors, myPtList



Here they clearly just reference the NamedValues collection itself, whereas I have to assign it to an object and reference that object or else the compiler won't shut up. So I figure its either something wrong with that portion of the code or its something wrong with the way I assign the IPIPoints2 object, in VB they assign it as such:

Code:
Set IPIP2 = myServer.PIPoints


whereas I have to cast it as well otherwise the compiler won't compile.

Code:
IPIP2 = (PISDK.IPIPoints2)myServer.PIPoints;


Hoping someone can catch my mistake, any help is much appreciated.

Thank you,
Michael
Michael
#3 Posted : Thursday, April 22, 2010 2:44:08 PM
Rank: Advanced Member
Groups: Member

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

Unfortunately, I know nothing about c#. However, I read your code and found this line

object pointType = "pttypFloat32";

The pointtype isn't a string, it's a constant from PISDK.PointTypeConstants enumeratiom.

Michael
mcasperson
#4 Posted : Thursday, April 22, 2010 3:31:57 PM
Rank: Newbie
Groups: Member

Joined: 4/5/2010
Posts: 8
Quote:
Hi Michael,

Unfortunately, I know nothing about c#. However, I read your code and found this line

object pointType = "pttypFloat32";

The pointtype isn't a string, it's a constant from PISDK.PointTypeConstants enumeratiom.

Wow, I never would have found that, and surprise surprise that is exactly what the problem was. It works perfectly now, Thank you very much Michael BigGrin

And for other peoples reference, here is an example of using the IPIPoints2 Interface in c# to add/edit/remove points to/from a PI server. Its exactly whats in the PISDK example but its in c# instead of VB.

Code:
PISDK.Server myServer;     // server object from the name in server pick list
PISDK.IPIPoints2 IPIP2;
PISDKCommon.NamedValues nvsAddRemove = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEdit = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsTagAttr = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEditAttr1 = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEditAttr2 = new PISDKCommon.NamedValues();
PISDKCommon.NamedValues nvsEditAttr3 = new PISDKCommon.NamedValues();
PISDKCommon.PIErrors myAddErrors = new PISDKCommon.PIErrors();
PISDK.PointList myPtList = new PISDK.PointList();
PISDKCommon.PIErrors myEditErrors = new PISDKCommon.PIErrors();
PISDKCommon.PIErrors myRemoveErrors = new PISDKCommon.PIErrors();

myServer = g_SDK2.Servers[servPickList2.SelectedServerName.ToString()];
IPIP2 = (PISDK.IPIPoints2)myServer.PIPoints;
object className = "classic";
object pointType = PISDK.PointTypeConstants.pttypFloat32; //can be replaced with whatever point type you need
nvsTagAttr.Add("ptclassName", ref className);
nvsTagAttr.Add("pointtype", ref pointType);
object nvsTagAttr2 = nvsTagAttr;
nvsAddRemove.Add("AER1", ref nvsTagAttr2);
nvsAddRemove.Add("AER2", ref nvsTagAttr2);
nvsAddRemove.Add("AER3", ref nvsTagAttr2);
IPIP2.AddTags(nvsAddRemove, out myAddErrors, out myPtList, null);
object description1 = "description for tag 1";
object description2 = "description for tag 2";
object description3 = "description for tag 3";
nvsEditAttr1.Add("Descriptor", ref description1);
nvsEditAttr2.Add("Descriptor", ref description2);
nvsEditAttr3.Add("Descriptor", ref description3);
object descriptionAttr1 = nvsEditAttr1;
object descriptionAttr2 = nvsEditAttr2;
object descriptionAttr3 = nvsEditAttr3;
nvsEdit.Add("AER1", ref descriptionAttr1);
nvsEdit.Add("AER2", ref descriptionAttr2);
nvsEdit.Add("AER3", ref descriptionAttr3);
IPIP2.EditTags(nvsEdit, out myEditErrors, null);
IPIP2.RemoveTags(nvsAddRemove, out myRemoveErrors, null);


Thanks,

-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.