AnsweredAssumed Answered

Write values to PI using PISDK and C# without buffer

Question asked by ebelaski on Jan 28, 2015
Latest reply on Jan 28, 2015 by dng

   My question is in regard to writing values to PI using PISDK and Visual Studio 201O in C#.

   I am not able to use the AFSDK until we upgrade to Visual Studio 2013 which will be in a few months.

  

   I have tried three different methods (below) to write a value to PI without success. These values are going to the

   LAB point source and are updated maybe once a week. Currently we use VBA in Excel (PutVal) or Process Book

   to write Pi Values to these tags. I have seen a few similar postings but the resolution there did not work.

  

   Each time I try to write a value to a PI Tag I get an error message, 

   "PiBuff Serv is not running. Unable to buffer. PI buffer subsystem should be running but isn't"

  

   When I turn the buffer Server subsystem on then I get this message, "Write failed. Unbuffered write would desynchronize archive data".

  

   I need to be able to write to PI tags without a buffer server as this application will be deployed to users that do not have buffer service installed.

  

   Would be greatly appreciated if someone was able to provide suggestions as to how to simply write a value to a Pi tag in C#.

 

Thanks

Eric

 

//Write to PI using PIValues
   this.ConnectToPIServer();
   double curTime = ah.ConvertDateToUtcSec(DateTime.Now);
   PISDK.PIPoint piPoint;
   piPoint = this.piServer.PIPoints[myTag];

   PISDK.PIValues pvPIValues;
   pvPIValues = new PISDK.PIValues();
   pvPIValues.ReadOnly = false;
   pvPIValues.Add(curTime, myValue, null);
   piPoint.Data.UpdateValues(pvPIValues, PISDK.DataMergeConstants.dmInsertDuplicates, null);

+++++++++++++++++++++++++++++++++++++
   // Write to PI using PIPoint
   
   this.ConnectToPIServer();
   double curTime = ah.ConvertDateToUtcSec(DateTime.Now);
   PISDK.PIPoint piPoint;
   piPoint = this.piServer.PIPoints[myTag];
   piPoint.Data.UpdateValue(myValue, curTime, DataMergeConstants.dmInsertDuplicates, null);
   
++++++++++++++++++++++++++++++++++++++
   // Write to PI using Collective
   
   List<PiTag> piPointList;
            double utcDatetime = ah.ConvertDateToUtcSec(DateTime.Now);
   this.numPointsUpdated = 0;
   string strLimitVal = "";
   PISDK.PIPoint piPoint;
   Object _ServerName = "MYPISERVER";

   foreach (var alarmLimit in piPointList)
   {
    tagName = alarmLimit.piTagName;
    limitValue = alarmLimit.limitValue;
    strLimitVal = alarmLimit.strLimitValue;

    try
    {      
       PISDK.PISDK piSDK1 = new PISDK.PISDK();
       PISDK.Server Srv = piSDK1.Servers[(String)_ServerName];
       PISDK.IPICollective Collective = (PISDK.IPICollective)Srv;

       if (Collective.IsCollectiveMember)
       {   
        PISDK.CollectiveList ColList = Collective.ListMembers();   
        PISDK.CollectiveMember ColMember = ColList.get_Item(ref _ServerName);  
        piServer = Collective.MemberOpen(ColMember, "");

        piPoint = piServer.PIPoints[tagName];

        piPoint.Data.UpdateValue(strLimitVal, utcDatetime, DataMergeConstants.dmInsertDuplicates, null);
        this.numPointsUpdated++;
       }
    }
   }
  
   ++++++++++++++++++++++++++++++++++++++
  
   //VB code that works but not able to translate to C#
    oCollective = CType(m_oServer, PISDK.IPICollective)
    oPoint = Nothing
    oPoint = oCollective.PIPoints.Item(strPiTag)

    If Not oPoint Is Nothing Then
     oPoint.Data.UpdateValue(strVal, dblUTCSecs, DataMergeConstants.dmInsertDuplicates, Nothing)
    End If

Outcomes