4 Replies Latest reply on Nov 19, 2010 3:29 AM by mhalhead

    Generation of Random values

    mvunsharma

      Hello all,

       

      Greetings.

       

      We are using PI system as a data historian for testing. In one of the test cases, I am supposed to simulate a scenario where:

       

      1. The data historian sends values that are sinusoidal.

       

      2. The data historian sends values between 520 to 780.

       

      3. The data historian sends values limited to three digits i.e., something like 550.678 and not 550.6783465.

       

       

       

      How do I setup this scenario in PI Server?

       

      Thank You and Regards,

       

      Nageshwara Sharma Manda

       

       

       

       

       

       

        • Re: Generation of Random values
          MichaelvdV@Atos

          First of all, what do you mean by 'send' ?

           

          Normally, you retrieve values from PI, rather than that PI 'sends' data.

           

          I'm assuming you mean that you need to generate timeseries based on those 3 requirements.

           

          There are some (standard) random tags, like 'sinusoid', 'sinusoidu' and 'cdt158'. These come from the random interface. You can configure the random interface, and most likely it will solve your requirements.

           

          Other than that, if you want to program, you can use PISDK to generate timeseries based on your requirements (or other requirements). This is an example based on your question (.NET 4, C# -> code is not checked)

          
          

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;
          using PISDK;

          namespace RandomPi
          {
              class Program
              {
                  static void Main(string[] args)
                  {
                      //Set up server
                      var sdk = new PISDK.PISDK();
                      var server = sdk.Servers.DefaultServer;

                      //Settings
                      var startTime = DateTime.Today.AddDays(-10);
                      var endTime = DateTime.Today;
                      var span = TimeSpan.FromHours(1);

                      var sinusoidtag = "vcampus_sinusoid";
                      var rndtag = "vcampus_random";
                      var roundedtag = "vcampus_rounded";

                      //Create sinusoid
                      var sindata = server.PIPoints[sinusoidtag].Data;
                      var sinvalues = new PIValues
                      {
                          ReadOnly = false,
                      };
                      for (var current = startTime; current < endTime; current = current.Add(span))
                          sinvalues.Add(current, Math.Sin((double)current.Ticks), null);

                      sindata.UpdateValues(sinvalues);

                      //Create random values between 520 - 780
                      var rnddata = server.PIPoints[rndtag].Data;
                      var rnd = new Random();
                      var rndvalues = new PIValues
                      {
                          ReadOnly = false,
                      };
                      for (var current = startTime; current < endTime; current = current.Add(span))
                          rndvalues.Add(current, rnd.Next(520, 780), null);

                      rnddata.UpdateValues(rndvalues);

                      //Create random values between 520 - 780
                      var roundeddata = server.PIPoints[roundedtag].Data;
                      var rounded = new Random();
                      var roundedvalues = new PIValues
                      {
                          ReadOnly = false,
                      };
                      for (var current = startTime; current < endTime; current = current.Add(span))
                          roundedvalues.Add(current, Math.Round(rounded.Next(0, 1000) / 0.999, 3, MidpointRounding.ToEven), null);

                      roundeddata.UpdateValues(roundedvalues);

                  }
              }
          }

           

            • Re: Generation of Random values

              Just like Michael, I would think you want to generate data and store it into PI, rather than have PI send data to a separate system - correct?

               

              If that's the case, then I would like to emphasize Michael's point about using the PI Random and PI RampSoak Simulator Interfaces... these are indeed the ones that populate tags like 'cdt158' and 'sinusoid', and can be used to create your own simulated or random points. They offer a great deal of flexibility (often understimated) in terms of how they generate values and store them in PI Points; I would like to recommend you consult the Random and RampSoak user manuals, which provide all the details.

               

              You can also take a look at this discussion thread, where I made a couple other suggestions. Since this is more of a system administration (rather than programming) question, I would like to kindly invite you to contact our regular technical support team, if you need further assistance with this.

                • Re: Generation of Random values

                  As for your requirements about the number of decimal figures, you can always use the DisplayDigit attribute at the PI Point level, or handle this in whatever client you use to read the values back. One would normally store values in PI with maximum precision, and then handle display/manipulation of values the way they want.

                   

                  Hope this helps!

              • Re: Generation of Random values
                mhalhead

                Nageshwara,

                 

                You've had enough answers on points 1 & 2 so I'm not going to both. On point 3; the point configuration has a displaydigits parameter which controls the number of decimals to display. This works seamless in the OSI client; I believe that this includes the PI OLEDB interface. However, if you are programmatically (i.e. via the PI-SDK) accessing the data then you will have to apply the formating yourself; simply read the configuration attribute and apply that to the formatting.