3 Replies Latest reply on Feb 27, 2012 4:30 PM by kandimallav

    Enable PI SDK Buffering using C# with PIData.UpdateValue()

    kandimallav

      Hi,

       

      Anyone tried PI SDK Buffering programtically with PIData.UpdateValue. We can set this with PI SDK Utility manually with PI SDK 1.4. But want to try this with IPISDKOptions by setting Environment options for NOPISDKBUFFERING value.

       

      I am stuck at below. Appreciate any help.

       
      PISDK.PISDK _sdk = new PISDK.PISDK(); 
      PIPoint _piPoint;
      Server _collective=_sdk.Servers["MYCollective"];
      IPICollective _ipcollective = (IPICollective) _collective;
      IPISDKOptions _pisdkoptions = (IPISDKOptions)_sdk;
      
      PISDKCommon.NamedValues _namedvals= _pisdkoptions.GetAvailableEnvironmentOptions();
      object objvalue=0;
       if(_namedvals.Count != 0)
         {
             objvalue=1;
         }
      MessageBox.Show(_namedvals.get_Item(ref objvalue).Name.ToString()); 
      
      /// I am stuck at the above line. This gives me "NOPISDKBUFFERING" at position 1 as the name of setting but not sure how to set the values with SetEnvironmentOptions Method, by passing Named values collection.
      
      //_pisdkoptions.SetEnvironmentOptions(_namedvals, true);   ///? :(
      

       

       

      Regards,

       

      Parthu

        • Re: Enable PI SDK Buffering using C# with PIData.UpdateValue()
          andreas

          Venkata,

           

           

           
                  [STAThread]
                  static void Main(string[] args)
                  {
                      PISDK.PISDK _sdk = new PISDK.PISDK(); 
                      PISDK.Server _myserver = _sdk.Servers.DefaultServer; 
                      PISDK.IPISDKOptions _pisdkoptions = (PISDK.IPISDKOptions)_sdk; 
                      PISDKCommon.NamedValues _namedvals = _pisdkoptions.GetAvailableEnvironmentOptions(); 
                      object objvalue = 0; 
                      if (_namedvals.Count != 0) 
                      { 
                          objvalue = 1; 
                      }
                      global::System.Windows.Forms.MessageBox.Show(_namedvals.get_Item(ref objvalue).Name.ToString());
                      Console.ReadKey();
                  }
          

           

           

          the above code works - strangely the [STAThtread] is necessary in this case.

            • Re: Enable PI SDK Buffering using C# with PIData.UpdateValue()
              mhamel

              Hi Parthu,

               

              One of the easiest way to modify this property is the following:

               
              //Objects.
              NamedValues NVSEnvironmentOptions = new NamedValuesClass();
              PIErrors EnvironmentOptionChangeErrors = new PIErrorsClass();
              string TemplateErrorOptions = "Error {0}: {1}";
              
              this._MyPISDK = new PISDKClass();
              IPISDKOptions ExtPISDK = (IPISDKOptions)this._MyPISDK;
              
              NVSEnvironmentOptions.Sorted = false;
              object MyVal = 1;
              NVSEnvironmentOptions.Add("NOPISDKBUFFERING", ref MyVal);
              EnvironmentOptionChangeErrors = ExtPISDK.SetEnvironmentOptions(NVSEnvironmentOptions, true);
              if (EnvironmentOptionChangeErrors.Count > 0)
              {
                   foreach (PIError EnvOptionChangeError in EnvironmentOptionChangeErrors)
                        Console.WriteLine(String.Format(TemplateErrorOptions,
                                                                     EnvOptionChangeError.Number,
                                                                     EnvOptionChangeError.Description));
              }
              

               

               

              Let me know if it works for you.

               

               

                • Re: Enable PI SDK Buffering using C# with PIData.UpdateValue()
                  kandimallav

                  Hi Mathieu,

                   

                  Thanks for the code. I tried it over the weekend on the same but with out PIErrors errorhandling. It works fine, but i am updating NOPISDKBUFFERING to 0 to enable SDK Buffering and update it back to the default settings(which is 1) at the end. It works perfect first time but when i change it back to default setting and rerun the application it returns the exception as it is still not recognising 0 option although it is updated  "Server returned write error: : [-11414] Buffered point does not accept new events : UpdateValue"

                   

                  I know that this option is a registry setting under the following path "SOFTWARE\PISystem\PI-SDK\1.0". I even tried directly updating the registry using c# and able to succeed for the first time as well.  The registry updates to "ffffffff" under registry when i update it to 1(default setting). When i re run the application it gives the above exception although i update it back to 0.

                   

                  I know this is direct option and may not work as expected if you are not sysadmin or if the registry updating rule is blocked.

                   

                  But for now it works gr8, if i do not update my setting back to default and keep it to 0(Enabling SDK Buffering). Thanks once again. Below is the option i used to modify registry and you already have published for IPISDKOPTIONS.

                   

                  private void UpdatePICollective_Load(object sender, EventArgs e)
                          {

                   

                              Object _ServerName = "MYCOLLECTIVE";
                              String _ConnectionString = "";
                              PISDK.PISDK _sdk = new PISDK.PISDK();
                              PIPoint _piPoint;
                              Server _collective=_sdk.Servers["MYCOLLECTIVE"];
                              _collective.Open((String)_ServerName);

                   

                              RegistryKey myKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\PISystem\PI-SDK\1.0",true);
                              int myValue = (Int32)myKey.GetValue("NOPISDKBUFFERING");
                              if(myValue == 1)
                              {
                                 myKey.SetValue("NOPISDKBUFFERING", 0, RegistryValueKind.DWord);
                              }

                   

                                _piPoint = _collective.PIPoints["Sinusoid"];
                               DateTime dt = DateTime.Now;
                              _piPoint.Data.UpdateValue("51.1278", dt, PISDK.DataMergeConstants.dmInsertDuplicates, null);  
                          }

                   

                  I will update you folks if i will succeed for updating it back to default setting.

                   

                  Regards,

                   

                  Parthu